<div dir="ltr"><br><br><div class="gmail_quote">2012/3/19 Diego Iastrubni <span dir="ltr"><<a href="mailto:elcuco@kde.org">elcuco@kde.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On יום שני 19 מרץ 2012 12:22:15 Erez D wrote:<br>
> On Mon, Mar 19, 2012 at 12:20 PM, Nadav Har'El<br>
<<a href="mailto:nyh@math.technion.ac.il">nyh@math.technion.ac.il</a>>wrote:<br>
> > On Mon, Mar 19, 2012, Erez D wrote about "Re: what happens if":<br>
> > > my reason for fork is only for exec() - to protect the first program<br>
> > > from the other.<br>
> ><br>
> > Then you should be all fine.<br>
<br>
</div>Another reason is for interacting with libraries which are "singleton". I had<br>
to work with a library to talk to some special HW. The library was designed to<br>
work with one device per process, and I needed to support "many".<br>
<br>
I found myself "forking" and using pipe() to use the API from my main app. The<br>
problem is that that "fork()" was called from a thread. Read ahead.<br>
<div class="im"><br>
> > If you're talking about the C language, you won't have any of these<br>
> > problems. System calls like close() or dup() do not use any pthread<br>
> > capabilities like mutexes.<br>
> ><br>
> > If you're talking about a different programming language, I frankly<br>
> > have no idea what its fork() does. Maybe you need to write some C<br>
> > code that does fork()/exec() in one function call, and avoid this risk.<br>
><br>
> i will be using C++. are you sure this is safe ?<br>
<br>
</div>All theory I read before implementing this said this was a bad idea. The<br>
theory says that libc may maintain some mutex inside malloc() which is called<br>
from printf() for example. This means that even trivial things may kill your<br>
app. The theory says that in multithreaded applications as soon as you clone()<br>
(the system called used by pthread_create()) you should execvp.<br>
<br>
In my application (a lot of C++, running on linux 2.6.32, glibc 2.9 and glibc<br>
2.11.1 on ARM) erverything worked perfectly against the theory, your mileage<br>
may vary.<br></blockquote><div>what do you mean by " erverything worked perfectly against the theory" - did it work or did you have problems although you just execvp after clone ?<br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Linux-il mailing list<br>
<a href="mailto:Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a><br>
<a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il" target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br>
</div></div></blockquote></div><br></div>