System V / SIGCLD questions...

Chris Torek chris at mimsy.UUCP
Fri May 12 08:52:13 AEST 1989


In article <565 at lehi3b15.csee.Lehigh.EDU> murrey at lehi3b15.csee.Lehigh.EDU
(Erik Murrey) writes:
>If I have spawned a few children, and one just did an exit(), then my
>reapchildren() signal handler gets called.  It does a wait(), gets the
>exit status, and gets out of there (after resetting the SIGCLD
>signal).  If by chance a second child dies while we are within the
>reapchildren() handler, I never get notified of it...

Your analysis is right, but this is not in fact what happens.  In
System V (all releases for all hardware platforms, for once), SIGCLD
works differently from every other signal.  The default action for
SIGCLD is to do nothing; the `ignore' action for SIGCLD is to discard
exiting children; and the `catch' action is as usual.  But when the
signal is set from any previous disposition to `catch', if there are
any pending exited children, a new SIGCLD signal is generated.

Loosely:

/* signal system call */
	if (sig == SIGCLD)
		switch (action) {
		case SIG_DFL:	/* default action is to ignore */
			... nothing special ...
			break;
		case SIG_IGN:	/* ignore action is to flush */
			... flush any children ...
			break;
		default:	/* catch: regenerate */
			... set handler ...
			if (there are children)
				psig(u.u_procp, SIGCLD);
			break;
		}

This means that a catcher routine written as

	catch()
	{
		int w, status;

		signal(SIGCLD, catch);
		w = wait(&status);
	}

recurses infinitely as soon as one child exits.
-- 
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.wizards mailing list