How to kill tasks after a user abort?

"Gary S. Moss", VLD/VMB moss at BRL.MIL
Tue Mar 6 01:13:29 AEST 1990


Rob Lansdale writes:
<	So how do I assure that the parent process gets woken and becomes
< the first process to enter the signal handler? I've (carefully) read through
< the signal man page several times and tried a number of variations of the 
< SIGCLD signal catcher, but I still find that the parent process is getting
< stuck occansionally in the printf() routine when it is about to print that 
< the display code is shutdown (printf() -> Psema() -> blockproc() ...). This
< printf() is part of the signal handling code.

Never ever call printf() or any of the <stdio.h> functions from a signal
handler; unless perhaps that's the only usage of stdio in the program.  It
will lead to potentially weird and fatal behavior if the signal interrupts
a stdio function, causing the signal handler to re-enter printf() while the
buffering mechanism is not stable.  Signal handlers should do as little as
possible as far as calling library routines which maintain internal states
which could be interrupted by the signal, malloc() is another good example.

If possible, set a global variable from your handler which can be detected
and acted on from the main runstream.  This can be difficult, depending on
the structure of your program, and therefore is best built into the design
from the start.



More information about the Comp.sys.sgi mailing list