Avoiding <exiting> processes on Ultrix

Chris Torek chris at mimsy.UUCP
Wed Apr 12 15:07:08 AEST 1989


In article <7693 at phoenix.Princeton.EDU> bernsten at 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 at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.questions mailing list