I used os.waitpid,but I still can't Zombie process?

Chris Gonnerman chris.gonnerman at newcenturycomputers.net
Wed Dec 19 08:59:19 EST 2001

> From: 张少驰
> I still want to kill Zombie process which cause by child process,so I use
> os.waitpid,But I found Zombie is still exist,why? my program is follows:
> ...
> while 1:
>   ...
>   ret=os.fork()
>   if ret==0:
>      HOST=udpaddr
>      PORT=21567
>      udpSerSock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
>      udpSerSock.sendto(data,ADDR)
>      udpSerSock.close()
>      break
>   os.waitpid(ret,os.WNOHANG);

First, as Donn already noted, the os.WNOHANG parameter means "don't
wait if the child hasn't exited."  This will not result in correct
operation; you MUST NOT include this parameter with the pid given if
you want the zombie reaped.

If you are intending to spawn multiple children who will run
detached, and you don't care about them after you start them, change
the os.waitpid() call to os.waitpid(-1, os.WNOHANG) (to reap any
child) and ensure that it is called in a loop (which it appears to

> Where is my program's error? How to correct my program? Any idea will be
> appreciated.
>       Edward

It appears to me, from the many questions you have asked, that you
may need to spend some time with a good book on Unix/Linux system
programming.  Your questions are not stupid, but they are fundamental,
which tells me you need to get a better grip on how this kind of program
works in general.

Are you a C/C++ programmer?

More information about the Python-list mailing list