fork problems (zombie children)

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


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

8704 v14 8 0:00 ./forktest
8705 v14 8 0:00 (forktest) Z 8704
8707 v14 8 0:00 (forktest) Z 8704
8708 v14 8 0:00 (forktest) Z 8704
8710 v14 8 0:00 (forktest) Z 8704
8712 v14 8 0:00 (forktest) Z 8704
8714 v14 8 0:00 (forktest) Z 8704
8716 v14 8 0:00 (forktest) Z 8704
8717 v14 8 0:00 (forktest) Z 8704

I ran out of virtual memory on my 32Mb machine on a different app (lynx)
after lots of these were created.