Sets up one of several ways for a thread to handle an interrupt signal from the OS.
#include <signal.h> void (*signal (int sig, void (*func)(int sig [,int subcode]))) (int sig);
sig
func
subcode
This function is implemented in the shared C library interface library (not in the shared C library), and is private to each application.
The sig
argument must be one of these manifest constants:
Value | Description |
---|---|
SIGABRT | Abnormal termination |
SIGALLOC | Memory allocation failure |
SIGBREAK | <Ctrl-Break> signal |
SIGFREE | Bad free pointer |
SIGINT | Interactive attention |
SIGSEGV | Segment violation |
SIGTERM | Termination request |
SIGUSR1 | User-defined |
SIGUSR2 | User-defined |
SIGUSR3 | User-defined |
The func
must be either a function address or one of these manifest constants:
Value | Description |
---|---|
SIG_DFL | Uses system-default response. The system-default response for all signals except SIGUSR1, SIGUSR2, and SIGUSR3 is to abort the calling program using _exit. The default response for SIGUSR1, SIGUSR2, and SIGUSR3 is to ignore the signal. |
SIG_IGN | Ignores interrupt signal. This value should never be given for SIGFPE, since the floating-point state of the process is left undefined. |
Function address | Installs the specified function as the handler for the given signal. |
For all signals except SIGFPE and SIGUSRx, the function is passed the sig
argument and executed.
For SIGFPE, the function pointed to by func is passed two arguments, SIGFPE and an integer error subcode, FPE_xxx; then the function is executed. The value of func
is not reset upon receiving the signal. To recover from floating-point exceptions, use setjmp in conjunction with longjmp. If the function returns, the calling thread resumes execution with the floating-point state of the process left undefined.
If the function returns, the calling thread resumes execution immediately following the point at which it received the interrupt signal. This is true regardless of the type of signal or operating mode.
Before the specified function is executed, the value of func is set to SIG_DFL. The next interrupt signal is treated as described above for SIG_DFL, unless an intervening call to signal specifies otherwise. This allows the program to reset signals in the called function.
Since signal-handler routines are normally called asynchronously when an interrupt occurs, it is possible that your signal-handler function will assume control when an operation is incomplete and in an unknown state. Certain restrictions therefore apply to the C functions used in your signal-handler routine:
func
. For example, if the previous value of func
was SIG_IGN, the return value will be SIG_IGN.
sig
or func
values, and the function sets errno to EINVAL.
Versions | Defined in | Include | Link to |
---|---|---|---|
INtime 3.0 | intime/rt/include/signal.h | signal.h | clib.lib |
_exit, abort, fread, longjmp, malloc, putenv printf, raise, read, setjmp, strdup, write