SIGNAL - dictate what to do if signal received.

(ANSI Standard)

Usage:

#include <signal.h>
oldfunc = signal( sig, newfunc );

Where:

int sig;
is the signal that you wish to handle. The signals that are recognized are listed later on.
void (*newfunc)(int);
points to the function that should be invoked if the signal occurs. See "Signal Functions" below for more information.
void (*oldfunc)(int);
points to the function that previously handled this particular kind of signal. If the process of setting up the signal-catching function fails, "signal" returns the special value SIG_ERR (defined in <signal.h>).

Description:

"signal" instructs the operating system that a certain function should be called if a particular condition is encountered during program execution. For example, "signal" lets you set up a function that will perform break-handling.

Signal Functions:

The "newfunc" argument points to a function that should be invoked if the signal occurs. This may be a user-defined function. If so, the function is passed a single integer argument when the signal occurs; this argument is the number of the signal. When the user-defined function returns, the program resumes execution at the point that the signal was received. However, the signal-catching function for this particular signal is automatically reset to SIG_DFL when the user's function returns, unless the encountered signal happened to be SIGILL. Thus your program must call "signal" again if you want to catch the same signal with the same function.

SIG_DFL is another possible choice for "newfunc". This stands for the "default" action. The default action varies for different types of signals. Typically, it closes all open file descriptors and terminates the program, but other actions may be taken instead or in addition.

The final choice for "newfunc" is SIG_IGN. This function simply ignores the signal.

Signal Values:

Signals for the single segment GCOS-8 C compiler are identified by manifests defined in <signal.h>. The names of these manifests start with either "SIG" or "_SIG".

_SIGZOP
GCOS ZOP fault (illegal machine instruction).
_SIGMEM
memory fault.
_SIGFTAG
FTAG fault.
_SIGDVCHK
divide check.
_SIGOFLOW
overflow fault. This covers integer overflow, and floating point overflow and underflow.
_SIGBRK
user interrupt (break).
_SIGDRL
indicates that a DRL instruction was encountered. This only causes an exception when the program is executing in batch.
_SIGOFL
integer overflow. If you set a signal handler for _SIGOFL, you cannot set one for _SIGOFLOW, and vice versa.
_SIGFEO
floating point overflow. If you set a signal handler for _SIGFEO, you cannot set one for _SIGOFLOW, and vice versa.
_SIGFEU
floating point underflow. If you set a signal handler for _SIGFEU, you cannot set one for _SIGOFLOW, and vice versa.

The signal manifests given above should be considered non-portable. Portable signals (defined by the ANSI standard) are:

SIGINT
same as _SIGBRK.
SIGILL
same as _SIGZOP.
SIGSEGV
same as _SIGMEM.
SIGFPE
arithmetic exception. This covers both divide check and overflow/underflow situations for either floating point or integer arithmetic. If you set a signal handler for SIGFPE, you should not set a handler for _SIGDVCHK, _SIGOFLOW, _SIGFEO, or _SIGFEU (and vice versa).
SIGABRT
aborts the current program. This signal is not generated by system software; it only occurs when you call the "abort" function or use "raise" to raise the signal.
SIGTERM
terminates the current program. This signal is not generated by system software; it only occurs when you use "raise" to raise the signal.

Notes:

We do not recommend using the SIG_IGN signal handler for _SIGBRK (i.e. ignoring breaks). There are dangerous critical sections in such a process. See "expl b lib nobrks" of the UW Tools package for a better way of ignoring breaks.

The include file <signal.h> defines an integer type named "sig_atomic_t". It is "safe" to assign values to a data object of this type inside a signal handling function. Assigning values to other data types may be less safe, in the sense that such assignment operations may take several machine instructions. If a new signal is raised when some of the instructions have been performed (but not all), you have the confusing situation of an assignment that is partly done, leaving the object's value in doubt. There is no doubt with "sig_atomic_t" objects; an assignment takes a single machine instruction, so it cannot be "partly performed".

On GCOS8, it is safe to assign values to any basic data type.

See Also:

expl c lib raise

expl c lib abort

Copyright © 1996, Thinkage Ltd.