Messages in this thread | | | Date | Thu, 9 Apr 2009 22:36:44 +1000 | From | Nick Andrew <> | Subject | Re: the different effect of system call fork() |
| |
On Wed, Apr 08, 2009 at 03:08:48PM +0200, Bernd Petrovitsch wrote: > > if (pid_t pid = fork() < 0) > > I don't think that this line does what you want it to do. > Hint: Using a "pid_t" for the boolean result for a comparison seems > strange at best.
The "problem" is due to a misunderstanding of C/C++ operator precedence.
"(pid = fork() < 0)" binds like "pid = (fork() < 0)" and so pid always has a value of zero and so both parent and child process run the "first level child process" code ... soon there are 4 processes all confused about who they are.
Nick.
| |