On Mon, Apr 09, 2007 at 03:42:50PM -0600, Philip Guenther wrote: > However, OpenBSD 4.0 doesn't actually comply with that: after > waitpid() there will be no SIGCHLD pending, even if there are > additional children to reap. > > So, if you're going to have multiple children, you need to call > waitpid(-1, &ret, WNOHANG) until it returns zero or -1/ECHILD before > you loop back to sigsuspend() again. That way you can be sure that > you haven't lost any SIGCHLDs before you reenter the sigsuspend(). > I've actually confirmed that that loop does work as expected, unlike > the original example which only works with one child.
Hmm. OK, thanks for that. I think for now my preferred solution is to keep a linear list of child processes. Forking adds a child to the end of the list; reaping finds the first child in the list with a matching pid and removes that entry. This eliminates the need for dealing with signals. The extra overhead of a linear search is small, given that children don't die that often. Cheers, Brian.