Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: net.unix-wizards Subject: Re: System V and SIGCLD Message-ID: <735@brl-smoke.ARPA> Date: Fri, 9-May-86 18:14:54 EDT Article-I.D.: brl-smok.735 Posted: Fri May 9 18:14:54 1986 Date-Received: Sun, 25-May-86 06:29:09 EDT References: <709@cheviot.uucp> Reply-To: gwyn@brl.ARPA Organization: Ballistic Research Lab (BRL) Lines: 43 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 */ > } > > main() > { > signal(SIGCLD, trap); > switch ( fork() ) > { > case 0 : /* child */ > sleep(5); > exit(0); > case -1 : > printf("error\n"); > exit(1); > default : > pause(); > } > exit(0); > } > >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?? The reason SIGCLD keeps recurring is that you continue to have an unwaited-for terminated child process. A wait() must be done to lay the zombie to rest. As to the window of vulnerability: Yes, all generally-available UNIXes except 4.2BSD have this problem. AT&T has said that they plan to change to Berkeley-like "reliable signals" in some future release of UNIX System V.