SIGNAL - dictate what to do if signal received.

(ANSI Standard)


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


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>).


"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 multi-segment GCOS-8 C compiler are identified by manifests defined in <signal.h>. The names of these manifests start with either "SIG" or "_SIG".

integer overflow.
exponent overflow.
exponent underflow.
a communications event once unmasked.

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

user interrupt.
illegal instruction.
memory fault.
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 SIGIOFL, SIGEOFL, or SIGEUFL (and vice versa).
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.
terminates the current program. This signal is not generated by system software; it only occurs when you use "raise" to raise the signal.


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 nsc lib raise

expl nsc lib abort

Copyright © 1996, Thinkage Ltd.