Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* How to ignore SIGCLD and not produce zombies?
@ 1996-09-13  4:00 Bryan Miller
  1996-09-16  4:00 ` Daniel Lewis
  0 siblings, 1 reply; 4+ messages in thread
From: Bryan Miller @ 1996-09-13  4:00 UTC (permalink / raw)



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 Miller            |
Powertrain Electronics  |
Control Systems Software|        "Nil Sine Numine"
bmiller6@ford.com       |



^ permalink raw reply	[flat|nested] 4+ messages in thread

* How to ignore SIGCLD and not produce zombies?
@ 1996-09-13  4:00 Bryan Miller
  1996-09-16  4:00 ` Andy St Martin
  0 siblings, 1 reply; 4+ messages in thread
From: Bryan Miller @ 1996-09-13  4:00 UTC (permalink / raw)



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 ;-)  The current method that I use does not 
seem to work on Digital Unix but does work well on Sun
and HP.

regards,
Bryan

----------------------------------------------------------
Bryan Miller            |
Powertrain Electronics  |
Control Systems Software|        "Nil Sine Numine"
bmiller6@ford.com       |



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to ignore SIGCLD and not produce zombies?
  1996-09-13  4:00 How to ignore SIGCLD and not produce zombies? Bryan Miller
@ 1996-09-16  4:00 ` Daniel Lewis
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Lewis @ 1996-09-16  4:00 UTC (permalink / raw)



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. 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to ignore SIGCLD and not produce zombies?
  1996-09-13  4:00 Bryan Miller
@ 1996-09-16  4:00 ` Andy St Martin
  0 siblings, 0 replies; 4+ messages in thread
From: Andy St Martin @ 1996-09-16  4:00 UTC (permalink / raw)



In article <51c1mr$58s@pt9201.ped.pto.ford.com>,
Bryan Miller <millerb@ACM.org> 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?

If you really don't want to be notified with SIGCLD, you can periodically
call waitpid() to "reap" the exited children.

Something like:

	while ((pid = waitpid(-1, &status, WNOHANG)) != -1) {
	    /* do stuff for cleaning up dead children */
	}

This should clean up all the Zombies and not hang if one or more child
processes are still active.  This should work for Digital UNIX, Sun
and HP-UX.

Andy St.Martin
stmartin@stmart.cxo.dec.com



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1996-09-16  4:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-09-13  4:00 How to ignore SIGCLD and not produce zombies? Bryan Miller
1996-09-16  4:00 ` Daniel Lewis
  -- strict thread matches above, loose matches on Subject: below --
1996-09-13  4:00 Bryan Miller
1996-09-16  4:00 ` Andy St Martin

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