Guardian Programmer's Guide

Table Of Contents
Debugging, Trap Handling, and Signal Handling
Guardian Programmer’s Guide 421922-014
25 - 32
Examples
the main() function, and jumps to the location of
sigsetjmp() with a return value of 1. */
siglongjmp (env, 1);
}
main ()
{
int i = 0;
if (SIGACTION_INIT_ (myHandler)) /* install the signal */
/* handler */
; /* Code to handle errors returned by */
/* SIGACTION_INIT_() */
/* sigsetjmp() returns 0 (zero) if called directly and
returns a nonzero value if returning from a call to
siglongjmp(). */
if (! sigsetjmp (env, 1)) {
/* Code that could generate a signal that is caught
by myHandler(). */
i = 3/i; /* SIGFPE generated here is caught by */
/* myHandler() */
} else {
/* This is the return location for siglongjmp(),
which is called from myHandler() after dealing with
the signal. */
}
}
Using All the HP Signals Extensions
/* This program shows how to use the HP signal extension
functions, jump functions, and HIST_* functions.
This program does the following:
1. Installs a general-purpose signal handler called
globalHandler() using the SIGACTION_INIT_() function.
2. Saves the process execution context (including the process
signal mask) and establishes the location to return (jump)
to from globalHandler() using the sigsetjmp() function.
3. Restores the process execution context and performs the
nonlocal goto (jump) using the siglongjmp() function.
4. Installs a local signal handler called localHandler(),
which takes over signal handling from globalHandler() for
system-generated nondeferrable signals (such as SIGFPE) using
the SIGACTION_SUPPLANT_() function. The signal-handling
state established by globalHandler() is saved.
5. Saves the process execution context and establishes the
location to return (jump) to from localHandler() using the
setjmp() function.
6. Formats and displays the process execution context when
the signal occurred using the HIST_* functions and the