what happens if

what happens if

Nadav Har'El nyh at math.technion.ac.il
Mon Mar 19 12:20:13 IST 2012


On Mon, Mar 19, 2012, Erez D wrote about "Re: what happens if":
> my reason for fork is only for exec() - to protect the first program from
> the other.

Then you should be all fine.

> the problem that may arise in forking a multithreaded is that one thread
> may lock a mutex and then another call for fork, which means that the child
> inherits the locked mutex.
> i do not know internaly what library function use this mutex, e.g. will
> close() need this mutex ? will dup() will ? in this case, trying to close a
> side of a pipe, duping it or even closing open fds (for security issues)
> may hang the child while the library waits for the mutex , and no other
> thread exists in the child to release it

If you're talking about the C language, you won't have any of these
problems. System calls like close() or dup() do not use any pthread
capabilities like mutexes.

If you're talking about a different programming language, I frankly
have no idea what its fork() does. Maybe you need to write some C
code that does fork()/exec() in one function call, and avoid this risk.

Did actually notice any problem with your code, or is this question
just theoretical?

-- 
Nadav Har'El                        |                    Monday, Mar 19 2012, 
nyh at math.technion.ac.il             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |If God had intended us to be vegetarians,
http://nadav.harel.org.il           |He wouldn't have made animals out of meat



More information about the Linux-il mailing list