Re: fork problems (zombie children)

Bas V. de Bakker (bas@astro.uva.nl)
Wed, 8 May 1996 14:51:49 +0200


Thomas Zerucha <tz@execpc.com> writes:

> What am I doing wrong? The following program:
> #include <signal.h>
> #include <sys/wait.h>
> main(){
> for(;;) {
> if( !fork() ) {
> exit(0); /* child, exit immediately */
> }
> sleep(1);
> }
> }

> when run with PID=8704 creates children that stay undead until the parent
> process terminates, e.g. from "ps -x":

Exited children stay around in the process table to allow their parent
to get their status using wait(). You should either wait() for your
children or ignore the SIGCHLD signal (using signal(SIGCHLD, SIG_IGN))
to avoid this.

Note that this is a generic UN*X thing, not Linux specific.

Bas.