Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!seismo!gatech!akgua!whuxlm!whuxl!houxm!ihnp4!cbosgd!osu-eddie!karl From: karl@osu-eddie.UUCP (Karl Kleinpaste) Newsgroups: net.unix-wizards Subject: Re: System V and SIGCLD Message-ID: <1794@osu-eddie.UUCP> Date: Sat, 10-May-86 08:59:38 EDT Article-I.D.: osu-eddi.1794 Posted: Sat May 10 08:59:38 1986 Date-Received: Wed, 14-May-86 06:35:17 EDT References: <709@cheviot.uucp> Organization: OSU Lines: 33 Summary: No, it's not a bug - it's quite correct 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 */ > } >[followed by main() which forks and then pauses if it's the parent] > >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...... 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. Anyone have any thoughts, information etc. on >this problem?? You're almost right, but not quite. It's not a bug. The problem your code demonstrates is an inappropriate way to deal with SIGCLD. What you need in the above trap() code is a wait(2) call before the reset of SIGCLD in signal(2), in order to clean up the zombie child. SIGCLD signals queue in SysV - you have to clean up your zombie children _a_s _t_h_e_y _o_c_c_u_r when you want to use SIGCLD on them. Be aware that if you get a SIGCLD for one dead child, call trap() to take care of it, and then a second child dies while still in trap(), you will immediately get run through trap() again when signal(2) is called. And so on for any zombie children. This is correctly documented in the manual page. I know it works, because I use it heavily in my job-control SysV csh. -- Karl Kleinpaste