Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
From: dlewis@voicenet.com (Daniel Lewis)
Subject: Re: How to ignore SIGCLD and not produce zombies?
Date: 1996/09/16	[thread overview]
Message-ID: <51kcqj$pjf@gnews2.voicenet.com> (raw)
In-Reply-To: 51c1if$58s@pt9201.ped.pto.ford.com


Bryan Miller (millerb@pt9526.ped.pto.ford.com) wrote:
: I have a server that listens to a well know port and forks
: off children upon request.  Since the server cannot wait
: for the children to die before going back to the port to
: listen it produces defunct (zombie) processes.

: Isn't there a way to start the server with SIGCLD set
: to ignore?  I currently stop the server periodically
: to reap the defunct processes and then restart the server.
: All ideas are welcome since this is causing untold pain
: and angst ;-)

: regards,
: Bryan

Bryan,

You might consider installing a signal handler for your server 
whose function is to reap child processes. For your server process,

	(void) signal(SIGCHLD, reaper);

"reaper" is:

	int reaper()
	{
		union wait status;
		while (wait3(&status, WNOHANG, (struct rusage *)0) >= 0)
			;
	}

This code is from Comer's book "Internetworking with TCP/IP", Vol III,
pp 135 and 136. The idea is that the server goes about its business, and
when a child dies, it receives SIGCHLD. The above signal handler is
called, which does a "wait3", thus reaping the child proccess which
has caused the signal. THe WNOHANG prevents the signal handler from
blocking if something goes wrong. So, you have the wait3 being called
on demand. The behavior of SIGCHLD and SIGCLD is subtly different on
BSD, Posix, and System V systems and is also dependent on the call you
use to assign the signal handler, there are at least three different
ways of doing that as I recall, haven't looked into it for awhile.
Stevens "Advanced Unix Programming" has a few pages on this around
page 279.

Dan L. 



  reply	other threads:[~1996-09-16  4:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-13  4:00 How to ignore SIGCLD and not produce zombies? Bryan Miller
1996-09-16  4:00 ` Daniel Lewis [this message]
  -- strict thread matches above, loose matches on Subject: below --
1996-09-13  4:00 Bryan Miller
1996-09-16  4:00 ` Andy St Martin
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox