Guardian Programmer's Guide

Table Of Contents
Debugging, Trap Handling, and Signal Handling
Guardian Programmer’s Guide 421922-014
25 - 26
Using Standard Signals Functions
Using Standard Signals Functions
There are many ways to use the standard signals functions in your application
programs. For information about writing standard, portable signal handlers, see
commercial texts on UNIX programming. The following discussion provides
considerations for using some of the standard signals functions and the sequence in
which you might use them.
Tailoring the Signal Mask
The signal mask of a process contains the signals to be blocked from delivery to a
process. Remember that a process signal mask cannot include signals that cannot be
ignored. You can construct a signal set with the sigaddset(), sigdelset(),
sigemptyset(), and sigfillset() functions. This signal set is essentially a draft
of a process signal mask, but the signal set does not become an official process signal
mask until the set is passed to the sigprocmask(), sigpending(), or
sigaction() function. These functions validate the content of the process signal
mask before installing it.
Before executing a signal handler, the new process signal mask is installed. This mask
is the union of the current process signal mask and the signal being delivered.
Specifying an Action for a Signal
A process also uses the sigaction() function to specify the action to be taken in
response to a signal. The action can be to ignore the signal, take the default action for
the signal, or catch the signal. If the action is to catch the signal, the sigaction()
function installs a signal-handling function. When the signal handler finishes, if the
process can continue, it resumes executing where it left off before the signal was
delivered.
Resuming a Process in a Different Context
A process can resume in a different context by using a combination of the
sigsetjmp() and siglongjmp() functions. sigsetjmp() and siglongjmp()
also allow the process to save and restore the state of the process signal mask before
the call to the signal handler, whereas setjmp() and longjmp() do not.
To resume in a different context, the process should have established the current
execution context by calling the sigsetjmp() function. Instead of exiting normally
from the signal handler, the signal handler calls the siglongjmp() function. The
process execution context reverts to the state saved by the sigsetjmp() function
call. If the process signal mask was also saved in the call to the sigsetjmp()
function, the mask is also restored.
The jump functions allow a process to change the flow of control and return to a known
process execution context. Changing the flow of control using the jump functions can
allow a process to continue executing when it might otherwise terminate abnormally.