Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!caip!nike!styx!lll-crg!gymble!umcp-cs!seismo!mcvax!ukc!stc!inset!dave From: dave@inset.UUCP (Dave Lukes) Newsgroups: net.unix-wizards Subject: Re: System V and SIGCLD Message-ID: <979@inset.UUCP> Date: Fri, 9-May-86 11:33:20 EDT Article-I.D.: inset.979 Posted: Fri May 9 11:33:20 1986 Date-Received: Tue, 13-May-86 01:09:09 EDT References: <709@cheviot.uucp> Reply-To: dave@inset.UUCP (Dave Lukes) Organization: The Instruction Set Ltd., London, UK. Lines: 42 In article <709@cheviot.uucp> lindsay@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