> Call getppid, set up the kevent listener, then before you actually
> block in kevent, call getppid *again*. If the answer matches the first
> call, then you can go ahead and call kevent. If the answer doesn't
> match, you've hit the race condition you outline here, your parent is
> dead, and you can exit immediately. If the parent quits after the
> second getppid but before the call to kevent, you should still get the
> exit notification because you registered it before the parent quit.

Ah - that should do it.

I was skeptical though, so I took a peek at the kernel's
exiting-process code
(http://www.opensource.apple.com/source/xnu/xnu-1504.3.12/bsd/kern/kern_exit.c);
indeed it looks like this technique is free from races, due to
proc_exit() both issuing the NOTE_EXIT event and putting the exiting
process in a reapable state _after_ all children of the exiting
process have been reparented by launchd.

For the archives: http://pastie.org/901581
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to