what happens if

what happens if

Nadav Har'El nyh at math.technion.ac.il
Mon Mar 19 11:40:10 IST 2012


On Mon, Mar 19, 2012, Erez D wrote about "what happens if":
> what happens if i am running a multithreaded app ( 3 threads ) and one
> thread calls fork() ?

On Linux, the new process will run ONLY a copy of the thread doing the
fork(). The other threads are *not* copied to the child process.

There is no way in Linux to ask to duplicate all of the process's
threads, as in Solaris's forkall(2) system call. Even if such a
system call existed, its usefulness would be dubious as explained 
in Posix's fork(2) manual:
	http://pubs.opengroup.org/onlinepubs/009695399/functions/fork.html
(look for the section starting in "The addition of the forkall()
function to the standard was considered and rejected.")

All this makes fork() more or less useless for multithreaded
applications except for one idiom: fork() followed by exec().


-- 
Nadav Har'El                        |                    Monday, Mar 19 2012, 
nyh at math.technion.ac.il             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |This space is for sale - inquire inside.
http://nadav.harel.org.il           |



More information about the Linux-il mailing list