Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!accuvax.nwu.edu!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: Avoiding processes on Ultrix Message-ID: <16875@mimsy.UUCP> Date: 12 Apr 89 05:07:08 GMT References: <520@pan.UUCP> <7693@phoenix.Princeton.EDU> Distribution: usa Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 26 In article <7693@phoenix.Princeton.EDU> bernsten@phoenix.Princeton.EDU (Dan Bernstein) writes: >I'm surprised nobody's mentioned setting up a SIGCLD/SIGCHLD handler >that does a wait(). (I did, in a mailed reply.) > sigchld() { wait(0); } > > signal(SIGCHLD,sigchld); This is not correct. SIGCHLD signals are not queued (in either BSD or [SIGCLD] SysV), nor are they `regenerated' as they are in SysV. The child handler must use wait3 with the WNOHANG option: while ((w = wait3(&status, WNOHANG, (struct rusage *)0)) >= 0) /* void */; Otherwise, if several child processes exit in quick succession, one or more may be missed. (Also, that should be `wait((int *)0)' or `wait((union wait *)0)', although `union wait' probably should not have been invented.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris