waste of resources ?

Timothy R Evans tre17 at cosc.canterbury.ac.nz
Tue Jun 8 01:01:05 EDT 1999


Gary Herron <gherron at aw.sgi.com> writes:

> Arne Mueller wrote: 
> > Im running python 1.5.2b2 on SGI power challange irix64 version 6.5.
> > Everytime a child process is created via fork(), it realy does it's job
> > but never dies, instead the number of zombie processes (as reported by
> > the 'top' program) steadily increases, though I call the sys.exit(0)
> > method for the child. Any idea how exit a process without creating a
> > zombie?
> > 
> >         thanks alot,
> > 
> >         Arne
> 
> Yes.  The parent process must execute a os.wait() or os.waitpid() in
> order for the child process's return code to be sent back to the parent
> program.  Only after that does the child process (now a zombie process)
> actually get eliminated.
> 
> Hope this helps.
> 
> -- 
> Dr. Gary Herron <gherron at aw.sgi.com>
> 206-287-5616
> Alias | Wavefront
> 1218 3rd Ave, Suite 800, Seattle WA 98101

Another thing to note is that when a child process dies the parent
will be sent a SIGCHLD signal (I think this also applies if the child
process was paused with SIGSTOP).  If you just want to ignore the
return code of the child process, use code like this:


import signal
import os

def sigchild_handler(signum, frame):
    os.wait()

signal.signal(signal.SIGCHLD, sigchild_handler)


This will run os.wait for each child process that exits.  You will
need to catch the return value of os.wait and inspect it if you care
what the process returned or whether it was killed by a signal.

--
Tim Evans




More information about the Python-list mailing list