[lug] Zombies

rm at mamma.varadinet.de rm at mamma.varadinet.de
Mon Feb 5 11:57:18 MST 2001


On Mon, Feb 05, 2001 at 12:36:08PM -0600, G. Mallen wrote:
> 
> I have a client-server application that forks a child to answer each
> query and leaves behind a "defunct" process when the child process ends.
> 
> How can this be avoided?

Short answer: wait for it. After you fork the parent process
needs to 'wait' (by means of 'wait (2)' or 'waitpid (2)'.
A common way to do this is to install a signal handler for
SIGCHLD and have the handler wait for child processes.
Be aware that there's quite a bit of possible black magic
involved in this (at least if the thing is supposed
to work reliably). For example, don't use the old signal
call to install the handler, use POSIX sigaction and friends.

A (slightly) longer answer: get a good book on Unix and
read the chapters on IPC/Signaling and process handling.
My all-time favorites are: Stevens, Advanced Programming in
the Unix Environment (has a _lot_ to say about your problem and
the code examples are crystal clear),'and 'Moris J. Bach, The
Design of the Unix Operating System, Pr. Hall, ISBN-0-13-201799-7.

If you can't get your hands on those, drop me a mail, i can mail
some sample code to you (there are people on this list that might
be better suited for this).

 Ralf

> Thanx
> 
> Guillermo
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug



More information about the LUG mailing list