Help with select(2) and SIGCHLD together

Rick Auricchio rick at cadtec.UUCP
Thu May 16 06:51:34 AEST 1985


--------
[]
The requirement: to "watch" a file descriptor [technically, a socket for
pending connects] via select(2), AND to catch SIGCHLD signals;
-----------
Current thoughts:

	for (;;) {

	    oldmask = sigblock(1 << (SIGCHLD - 1));	/* block SIGCHLD */
	    ... scan tables for dead children and do whatever...

	    sigsetmask(oldmask);		/* allow SIGCHLD */
	    n = select(fd,&fdmask,0,0,0);	/* wait for activity */
	    switch (n) {

		case -1 : ...oops!...

		case  0 : break;  /* SIGCHLD occurred, recheck tables */

		case  1 : ... do socket accept etc...
	    }
	}
	
	sigchldcatcher()
	{
	    ...simply mark tables appropriately (nothing else!)...
	}

------------
The Problem: An interruptibility window exists between the sigsetmask() and
    the select(), which could cause me to miss a signal till the next time
    an event terminates/interrupts the select.

    One (ugly) solution is to have the select timeout and then re-select if
    nothing's happened. But this wastes CPU time.

    The original design didn't have to select at all, so the sigsetmask
    was actually a sigpause(oldmask) which worked fine...

    Any ideas?
==============================================================================
Opinions expressed have been generated solely by line-noise.
{cbosgd,decwrl,hplabs,ihnp4,seismo}!nsc!cadtec!rick    N1150G   (408) 942-1535
		"It only rains when you have something planned."



More information about the Comp.unix.wizards mailing list