> Do we even need a signal handler at all for ECHILD? I suppose the
> select might not get interrupted (at least on some platforms) if there
> isn't one.
>
> Actually I guess there still is a race condition: there is a window
> between the last wait() of the reap loop and the select() wherein an
> ECHILD won't be serviced right away, because we hit the select() before
> noticing it. We could maybe use a timeout on the select to fix that.
> Don't really like it though, since the timeout couldn't be very long,
> but we don't want the postmaster wasting cycles when there's nothing
> to do. Is there another way around this?
Here is code I use for reaping dead child processes. Under SysV, if you
say you want to ignore child processes, they just disappear, but on BSD,
the children stay as zombies. This fixes that.
Seems you need to define a singnal handler, and just put select() in a
loop:
while (1) if (select(...) != -1 || errno != EINTR) break;
I see you are are loosing your error inside the singnal handler. Seems
you may have to save/restore errno.
---------------------------------------------------------------------------
/** From: rstevens@noao.edu (W. Richard Stevens) * Newsgroups: comp.unix.bsd.misc,comp.unix.bsd.bsdi.misc*
Subject:Re: BSD 4.4: Preventing zombies SIGCHLD* Date: 19 Dec 1995 13:24:39 GMT*/
void
reapchild(int signo)
{ pid_t pid; int stat; while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) { /* handle "pid" and "stat"
*/ } if (pid < 0) ;/* error */
/* we are done playing the current sound */cur_sound_id = -1; /* return value is 0 if no more children */ return;
}
-- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610)
853-3000+ If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill,
Pennsylvania19026