(ANSI Standard)
#include <signal.h> oldfunc = signal( sig, newfunc );
"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.
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.
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".
The signal manifests given above should be considered non-portable. Portable signals (defined by the ANSI standard) are:
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.
Copyright © 1996, Thinkage Ltd.