Re: kevents, waitpid() with WNOHANG race
Re: kevents, waitpid() with WNOHANG race
- Subject: Re: kevents, waitpid() with WNOHANG race
- From: Damien Sorresso <email@hidden>
- Date: Wed, 21 Oct 2009 16:17:03 -0700
On Oct 21, 2009, at 3:29 PM, Dave Keck wrote:
Hey list,
I'm using kevents to wait for a child process to exit (EVFILT_PROC,
NOTE_EXIT). Once kevent() reports that the process exited, I use
waitpid() to get its exit status. (I'm using kevents to actually do
the waiting so I can enforce a timeout.)
When I call waitpid(), I specify the WNOHANG option. Intuitively, I
would assume that this option would be safe because by the time I call
waitpid(), kevent() already reported that the child exited. But I'm
wondering if this is always the case: will waitpid() ever return 0
when using WNOHANG, because of some ordering in the kernel where the
kevent machinery notices a process exited before waitpid() would be
able to?
The kernel doesn't issue NOTE_EXIT until the process is in the zombie
state and ready to be reaped by its parent, so WNOHANG should be safe.
I don't know for sure if this is a guarantee, but I'm pretty sure it is.
The only stumbling block you could run into is if someone has attached
to your child process with gdb, thus causing it to be reparented. In
this case, waitpid(2) will return an error.
--
Damien Sorresso
BSD Engineering
Apple Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden