From: Nick Andrew <nick@nick-andrew.net>
To: Bernd Petrovitsch <bernd@firmix.at>
Cc: Sino <szj087@gmail.com>, linux-kernel@vger.kernel.org
Subject: Re: the different effect of system call fork()
Date: Thu, 9 Apr 2009 22:36:44 +1000 [thread overview]
Message-ID: <20090409123644.GA10495@mail.local.tull.net> (raw)
In-Reply-To: <1239196128.5031.3.camel@spike.firmix.at>
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.
prev parent reply other threads:[~2009-04-09 12:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-08 12:53 Sino
2009-04-08 13:08 ` Bernd Petrovitsch
2009-04-09 12:36 ` Nick Andrew [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090409123644.GA10495@mail.local.tull.net \
--to=nick@nick-andrew.net \
--cc=bernd@firmix.at \
--cc=linux-kernel@vger.kernel.org \
--cc=szj087@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®