Guardian C Library Calls Reference Manual

Reference to Library Calls
Guardian TNS C Library Calls Reference Manual128833 3-165
signal
Usage Guidelines
An exceptional condition, or signal, is generated by an abnormal event. For example,
a floating point exception occurs when two very large floating point numbers are
multiplied together.
The exceptional conditions that can be handled by the operating system are defined
as symbolic constants in the header signalh. Some examples are:
If an exceptional condition is raised in a process, then the typical default action of
the operating system is to terminate the process. You can use the signal function to
invoke a signal handler that replaces the default system action.
The signal function takes two arguments, an int and a pointer to a function that takes
an int and returns nothing. The signal function returns a pointer to a function that
takes an int and returns nothing.
The function call signal(sig, func) associates the signal sig with the signal handler
func(). This causes the system to pass sig as an argument to func() and invoke func()
when the signal sig is raised.
The standard C signal handlers are SIG_DFL, SIG_IGN, and SIG_ERR.
The signal handler SIG_DFL is initially registered by the C run-time library to all
signals, that is the equivalent of signal(xxx, SIG_DFL) is performed for each signal.
The action of SIG_DFL is equivalent to closing all files and aborting the program
with a stack dump.
A call to signal of the form signal(sig, SIG_IGN) means that the signal sig is to be
ignored. The Tandem C implementation of signal handling does not allow certain
signals to be ignored or returned from. If a signal is described as not allowing
SIG_IGN to be registered for it then if a user supplied handler executes the return
statement the program will be aborted as if SIG_DFL was used for that signal. If the
user attempts to return control to his program from his signal handler by way of the
longjmp function then he is responsible for insuring the program’s environment is
stable.
The standard C signal handlers SIG_DFL, SIG_IGN, and SIG_ERR are defined in
the header signalh to appear like functions. However, they should never be used
explicitly as the results are undefined. They should be used as in the following
example:
signal(SIGTIMEOUT, SIG_IGN); /* ignore the signal
SIGTIMEOUT */
SIGFPE
Arithmetic overflow
SIGILL
Illegal instruction
SIGSEGV
Illegal address reference