Printing in signal handlers vs. setting flags.

Radford Neal radford at calgary.UUCP
Wed Mar 27 05:51:32 AEST 1985


> My recommendation is to do little more than set a flag in the signal
> catcher and return.  Test this flag at appropriate places in the
> main program control loop.  This is much safer than trying to do
> anything useful from inside a signal catcher.

If you *must* use signals for something other than fatal error handling, then
just setting a flag is usually best. My advice to print an error message
and terminate the program was meant for cases where you are just trying to
provide a more informative error message than the shell would have given
out.

By the way, if setting a flag is best, why not add a new option to "signal"
that specifies a word in memory to be incremented by the kernel when a
signal arrives, as an addition to the current ignore, trap, terminate options.
This avoids the problems of restarting system calls when the flag methodology
is being used.

     Radford Neal
     The University of Calgary



More information about the Comp.unix.wizards mailing list