System V and SIGCLD
Dave Lukes
dave at inset.UUCP
Sat May 10 01:33:20 AEST 1986
In article <709 at cheviot.uucp> lindsay at cheviot.newcastle.ac.uk (Lindsay F. Marshall) writes:
>The following code goes into an infinite loop on System V :-
>
> trap(sig)
> int sig;
> {
> printf("trapped SIGCLD\n");
> signal(SIGCLD, trap); /* reset handler */
> }
>
> ...
>
>The problem is that resetting the SIGCLD trap inside the handler causes the
>signal to be raised again and the handler to be re-entered......
Yes, this is because you still have an unwait()ed for child!!
What you have to do is wait() for the child in the SIGCLD handler,
THEN reset the handler: this works fine.
>This is not documented in the manual page and seems to me to be a bug as if you
>do not reset the handler the system seems to set it to SIG_DFL, meaning that
>you will loose any SIGCLD signals between the handler's exit and your getting
>a chance to call signal again.
WRONG!!! (``It's not a bug: it's a feature'')
If you catch SIGCLD you will get sent SIGCLD whenever you have ANY
zombie children around (whether newly zombified or not):
the same thing happens when you re-catch it.
Yes, the manual is wrong (as well as totally unclear): it should say that
any pending SIGCLD signals are queued until you call signal(SIGCLD, ...) again
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
it should also remind you that you still MUST call wait() to dispose of the
children.
Still, in defence of SIGCLD:
it IS safe (you NEVER lose any children), AND usable (if you know how!).
Hope this helps.
--
Dave Lukes. (...!inset!dave)
``Fox hunting: the unspeakable chasing the inedible'' -- Oscar Wilde
More information about the Comp.unix.wizards
mailing list