Log in

View Full Version : fork is not inheriting all the threads from parent


rijnahts
January 8th, 2009, 12:12
Hi,
I have a process which has main thread and also created a new thread. So totallly this porcess contains 2 threads. When I did fork() from the newly created thread, the child is inheriting only the calling thread and it is not inheriting main thread. I am not understanding why it is like that..
I wanted child to be inherited all the threads from parent proces.. Please anybody help me on this.


Thanks

tdennist
January 21st, 2009, 13:46
The operation of fork() is OS-dependent... On some UNIX systems (and Solaris), there are two versions of fork(), one that duplicates all threads and one that duplicates just the calling thread. If the application is using POSIX threads, a call to fork only duplicates the calling thread.

Here's a link to fork() calls on Solaris which details the different calls:
http://docs.sun.com/app/docs/doc/816-0212/6m6nd4n9e?a=view