Re: fork problems (zombie children)

Robert L Krawitz (rlk@tiac.net)
Wed, 8 May 1996 09:30:00 -0400


Date: Mon, 6 May 1996 18:22:11 -0500 (CDT)
From: Thomas Zerucha <tz@execpc.com>

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":

You need to wait() on the children (from the parent) to reap them.
Otherwise they stay around so that the parent can grab their exit
status.