![]() |
| | #1 |
| Registered User Join Date: Oct 2006
Posts: 298
| pthreads + fork() |
| Elkvis is offline | |
| | #2 |
| Registered User Join Date: Oct 2006
Posts: 298
| I discovered the answer for myself, experimentally. for those interested, the thread only executes in the parent process, unless it is started again in the child. |
| Elkvis is offline | |
| | #3 |
| Registered User Join Date: Mar 2003
Posts: 3,898
| http://www.opengroup.org/onlinepubs/...ions/fork.html Correct - only the thread calling fork() is duplicated in the child. gg |
| Codeplug is offline | |
| | #4 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 2,070
| I'm learning about these now myself. This is how I was going to respond, but I wasn't sure of myself. Is this all correct? It's my understanding that fork() starts processing the newly spawned process (the "child") at the point of the fork(). The child is running in it's own process (aka address space) and while the stack and other info is copied into the new process (address space), you do not have access to the pthread that was started prior to the fork() - it's not in the child address space.
__________________ Mac and Windows cross platform programmer. Ruby lover. |
| Dino is offline | |
| | #5 |
| Registered User Join Date: Mar 2003
Posts: 3,898
| Something like that. As I understand it, the thread that calls fork is the only thread that is copied to the new process. The Rationale section of the pthread_atfork() documentation gives good insight on the kind things to be aware of when calling fork() in a multi-threaded application. gg |
| Codeplug is offline | |
| | #6 | |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,761
| Quote:
| |
| brewbuck is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is fork() a resource hog? | HalNineThousand | Linux Programming | 8 | 04-15-2008 09:07 AM |
| Fork(), pause(), and storing PID's in a linked list | vital101 | C Programming | 10 | 09-28-2007 02:16 AM |
| Fork - unpredictable? | fredkwok | Linux Programming | 4 | 03-26-2006 02:49 PM |
| fork(), exit() - few questions! | s3t3c | C Programming | 10 | 11-30-2004 06:58 AM |
| Daemon programming: allocated memory vs. fork() | twisgabak | Linux Programming | 2 | 09-25-2003 02:53 PM |