Re: PROBLEM: Failure to deliver SIGCHLD

Edgar Toernig
2005-07-23T04:40:43Z

Michael Harris wrote:
>
> [2.] The problem occurs in a forking server similar in function to
> inetd. The server employs a very simple SIGCHLD handler that loops on
> wait(2), until all zombie processes have been collected. For no
> immediately apparent reason, the parent process behaves as if it no
> longer receives SIGCHLD. Manually sending the signal has no effect.

Sounds like a blocked signal.

> [6.] This is the code for the signal handler in the server application.
>
> void reaper_man (int signum)
> {
> int stat;
> while ( waitpid(-1, &stat, WNOHANG) > 0 );
> }
>
> signal (SIGCHLD, reaper_man); /* from main() */
>
> I dare say it contains no bugs (famous last words)

It does - it clobbers errno :-)

My suggestions: use sigaction with defined restart/mask/etc behaviour
instead of signal. Save and restore errno in the signal handler.
Make sure SIGCHLD isn't blocked.

But if your only interest is to get rid of the zombies, the most simple
solution would be to set SIGCHLD to ignore.

Ciao, ET.