[lkml]   [2009]   [Apr]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: 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.


 \ /
  Last update: 2009-04-09 14:41    [W:0.057 / U:3.356 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site