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

lokie.spods lokie.spods at ntlworld.com
Wed Dec 19 22:53:45 CET 2001

"ÕÅÉÙ³Û" <zhangsc at neusoft.com> wrote in message
news:mailman.1008727643.15703.python-list at python.org...
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:
  if ret==0:

Where is my program's error? How to correct my program? Any idea will be

Depends on what your trying to do.

If your intent is to spawn a child to do the work, and wait till its
completed, then replace os.WNOHANG with 0 in the os.waitpid call. Naturally
the question would become why spawn a process your going to wait for when
you could do the work inline and save the overhead of a fork call.

If as the code imply's your looking to continually spawn processes and
cleanup the zombies as they happen, then replace RET with -1 in the
os.waitpid call. I'd also advise looping on the return tuple to ensure you
remove as many dead processes as possible per loop.

However you can save a lot of overhead from the loop, by creating a handler
for SIGCHLD and calling waitpid(-1, os.WNOHANG) from within the handler. See
Pythons signal module for more details of that option.

Anthony McDonald

More information about the Python-list mailing list