Re: kevents, waitpid() with WNOHANG race
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com 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? _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... On Oct 21, 2009, at 3:29 PM, Dave Keck wrote: 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. This email sent to site_archiver@lists.apple.com
participants (1)
-
Damien Sorresso