POSIX wait and SIGCHLD

Donn Cave (donn@u.washington.edu)
Tue, 21 Mar 95 15:08:33 -0800

Quoth Guido,
| There's undocumented special code in signalmodule.c which requires
| your handler to re-instate the signal handler for this signal, because
| otherwise the two-stage way of handling signals in Python would cause
| infinite recursion given the way this signal is generated (if there's
| still a child waiting when you return from the C signal handler, the
| signal is sent again by the OS). I don't know if this code works
| correctly -- in fact I don't know what the guaranteed and actual
| semantics of SIGCHLD are in Posix and other Unix versions.

I can't prove that it works correctly and can't quote POSIX on the subject,
but in a simple test SIGCHLD seems to work as expected, on DEC OSF/1.
The handler I used had only a print statement, didn't reinstate any signals,
and no infinite loops were observed.

Quoth Michael Scharf,
| It was me who brought up the problem with the SIGCHLD :-). In the meantime I
| read in the 'UNIX Network Programming' bible [UNIX Network Programming';
| W. Richard Stevens; Prentice Hall; 1990]. Stevens points out, that SIGCLD unde
| System V has a special semantics: if SIGCLD is set to SIG_IGN, then exited
| children do not become zombies. To emulate the same under 4.3BSD based UNIX he
| suggests the following handler:
...
| Later he uses this in the following way:
...
| #ifdef SIGTSTP
| signal(SIGCLD, sig_child); /* BSD */
| #else
| signal(SIGCLD, SIG_IGN); /* System V */
| #endif

I beg your pardon, Richard Stevens said to use SIGCLD on BSD? Not SIGCHLD?

| Well, using SIGTSTP as indicator for BSD seems to be a funny trick...

By this measure nearly all UNIX computers are BSD today, certainly any
that are likely to run python. And it's sort of true, but unfortunately
not entirely, even on BSD 4.4!

Anyway, I thought I'd pass on some experimental results from modern,
generally POSIX-compliant UNIX implementations. If I SIGCHLD (not
SIGCLD) to SIG_IGN, AIX 3.2.5 doesn't leave a zombie child, but DEC
OSF/1 does. IBM documents this feature for AIX. I can test this
elsewhere later, if anyone's interested, but right off it seems like
something that would be hard to use in a portable way. (The above
tests were done in C, not python.)

Donn Cave, University Computing Services, University of Washington
donn@cac.washington.edu