[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice needed: Controlling the number of child processes



Hmmm, I'm going back a while, but my head has records that a
signal handler, strictly, should exit PDQ, and do almost nothing.

I can't remember the reference, but IIRC sig handlers should not
call anything else and ideally just mark the fact that that signal
occurred somewhere that the main flow of execution can check once
it gets control back.
(presumably because subsequent signals aren't stacked, but are just
 ignored while in the handler)

I dunno why I thought that, but it kinda smacks of a man page for
something from a long time ago.

So I think your sigchild handler should just increment a counter
for the number of wait()s the main flow needs to do...

Dom
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dom De Vitto                                       Tel. 07855 805 271
http://www.devitto.com                         mailto:dom_(_at_)_devitto_(_dot_)_com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 


-----Original Message-----
From: owner-misc_(_at_)_openbsd_(_dot_)_org [mailto:owner-misc_(_at_)_openbsd_(_dot_)_org] On Behalf
Of Fábio Olivé Leite
Sent: Saturday, April 12, 2003 9:20 PM
To: misc_(_at_)_openbsd_(_dot_)_org
Subject: Re: Advice needed: Controlling the number of child processes


Em Sab 12 Abr 2003 12:17, Marc Balmer escreveu:
>
> Unfortunately I get zombies over time, as if some SIGCHLDs get lost. 
> After a short period of time my variable "nchildren" no longer matches

> the number of actual running processes.  How can I

Perhaps you need to either unblock the signal or reinstall the 
sighandler as the first thing in the handler. I don't have an OpenBSD 
machine around now, but man 2 signal in this linux box says:

...
       The  original  Unix  signal()  would  reset the handler to
       SIG_DFL, and System V (and the Linux kernel  and  libc4,5)
       does  the same.  On the other hand, BSD does not reset the
       handler, but blocks new  instances  of  this  signal  from
       occurring  during  a  call  of  the  handler.   The glibc2
       library follows the BSD behaviour.
...

Or, alternatively, you could do:

while (waitpid(0, NULL, WNOHANG)) {
	--nchildren;
}

Which will wait on any number of terminated children whenever it is 
called, without blocking if there is no child to wait on.

Hope this helps,

-- 
          Fábio Olivé Leite (foleite at yahoo.com.br)
OpenBSD: Unix casca grossa -*- KNOW THYSHELL (that is, man ksh)



Visit your host, monkey.org