> A concurrent server must include the following code to avoid
creating
> zombie processes in FreeBSD:
>
#include <signal.h>
extern void sigchld_hdl(); /* SIGCHLD handler */
int
main()
{
...
signal(SIGCHLD, sigchld_hdl); /* capture
SIGCHLD */
...
/* service loop - spawning processes */
}
/*
* SIGCHLD handler
*/
void
sigchld_hdl()
{
int e = errno;
while (waitpid(-1, NULL, WNOHANG) > 0) {}
errno = e;
}
> Note that you don't have to preserve errno (in sigchld_hdl)
if your
> program is not using that variable.
> |