lkml.org 
[lkml]   [1996]   [May]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: fork problems (zombie children)
Date
From

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


\
 
 \ /
  Last update: 2005-03-22 13:37    [W:0.210 / U:0.296 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site