|
Home > Archive > Unix Programming > March 2006 > WNOHANG in SIGCHLD handler
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
WNOHANG in SIGCHLD handler
|
|
| Roman Mashak 2006-03-14, 2:49 am |
| Hello, All!
I can't grasp the point of using WNOHANG in 'waitpid()', when it's called
inside of handler reaping children? According to man page WNOHANG 'means to
return immediately if no child has exited', but if the handler was invoked,
the signal has already been sent, right?
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
| |
| Nils O. Selåsdal 2006-03-14, 2:49 am |
| Roman Mashak wrote:
> Hello, All!
>
> I can't grasp the point of using WNOHANG in 'waitpid()', when it's called
> inside of handler reaping children? According to man page WNOHANG 'means to
> return immediately if no child has exited', but if the handler was invoked,
> the signal has already been sent, right?
This is to ensure you collect all children.
unix signals doesn't queue - if more than one child died at about
the same time that might result in just one SIGCHLD.
Thus you should call waitpid in a loop to be sure you reap all of them.
| |
| Roman Mashak 2006-03-14, 2:49 am |
| Hello, "Nils!
You wrote on Tue, 14 Mar 2006 08:22:53 +0100:
??>> I can't grasp the point of using WNOHANG in 'waitpid()', when it's
??>> called inside of handler reaping children? According to man page
??>> WNOHANG 'means to return immediately if no child has exited', but if
??>> the handler was invoked, the signal has already been sent, right?
NOS> This is to ensure you collect all children.
NOS> unix signals doesn't queue - if more than one child died at about
NOS> the same time that might result in just one SIGCHLD.
If it may result in only one SIGCHLD, what happens with other children
signals from which I didn't receive?
NOS> Thus you should call waitpid in a loop to be sure you reap all of
NOS> them.
With best regards, Roman Mashak. E-mail: mrv@tusur.ru
| |
| Nils O. Selåsdal 2006-03-14, 7:49 am |
| Roman Mashak wrote:
> Hello, "Nils!
> You wrote on Tue, 14 Mar 2006 08:22:53 +0100:
>
> ??>> I can't grasp the point of using WNOHANG in 'waitpid()', when it's
> ??>> called inside of handler reaping children? According to man page
> ??>> WNOHANG 'means to return immediately if no child has exited', but if
> ??>> the handler was invoked, the signal has already been sent, right?
> NOS> This is to ensure you collect all children.
> NOS> unix signals doesn't queue - if more than one child died at about
> NOS> the same time that might result in just one SIGCHLD.
> If it may result in only one SIGCHLD, what happens with other children
> signals from which I didn't receive?
They are merged with the one you did receive.
| |
| David Schwartz 2006-03-14, 7:49 am |
|
"Roman Mashak" <mrv@tusur.ru> wrote in message
news:dv5ndg$2g8b$1@relay.tomsk.ru...
> Hello, All!
>
> I can't grasp the point of using WNOHANG in 'waitpid()', when it's called
> inside of handler reaping children? According to man page WNOHANG 'means
> to return immediately if no child has exited', but if the handler was
> invoked, the signal has already been sent, right?
Sure, but how many times? Perhaps the first time you don't need WNOHANG,
but then you need to check if another child has exited, and you don't know
for sure whether one has or not.
DS
|
|
|
|
|