Messages in this thread | ![/](/images/icornerl.gif) | | Subject | Re: fork problems (zombie children) | Date | Wed, 08 May 1996 19:04:45 -0500 | From | "Larry 'Daffy' Daffner" <> |
| |
Thomas Zerucha writes: -> What am I doing wrong? The following program: -> -> -> 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
These are all zombies. IE, they're waiting for their parent to pick them up, and the process will stay around until the parent waits for them. So, try:
-> #include <signal.h> #include <sys/types.h> -> #include <sys/wait.h> -> main(){ int status;
-> for(;;) { -> if( !fork() ) { -> exit(0); /* child, exit immediately */ -> } wait(&status); -> sleep(1); -> } -> } The additions should cause the children to exit before the sleep.
Please take any further replies/questions off the linux-kernel list, as this isn't an appropriate topic.
-Larry
| ![\](/images/icornerr.gif) |