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.