9.8 Signal Handling (<signal.h>)

The <signal.h> header file declares a type and two functions and defines several macros for handling exception conditions that might be reported during program execution.

Type

sig_atomic_t


The integral type of an object that can be accessed as an atomic entity, even in the presence of asynchronous interrupts.

Macros

SIG_DFL SIG_ERR SIG_IGN


Expand to constant expressions with distinct values that have a type compatible with the second argument to, and the return value of, the signal function, and whose value compares unequal to the address of any declarable function.

Functions

void (*signal(int sig, void (*handler) (int))) (int);


Determines how subsequent signals are handled. Signals are handled in the following way:

  1. If the value of handler is SIG_ DFL , default handling of that signal occurs.

  2. If the value of handler is SIG_ IGN , the signal is ignored.

  3. Otherwise, when that signal occurs, a function pointed to by handler is called with the argument of the type of signal. Such a function is called a signal handler. Valid signals include:

    • SIGABRT-abnormal termination, such as from the abort function

    • SIGFPE-arithmetic error, such as zero divide or overflow

    • SIGILL-invalid function image, such as an invalid instruction

    • SIGINT-interactive attention, such as an interrupt

    • SIGSEGV-invalid access to storage, such as outside of memory limit

    • SIGTERM-termination request sent to the program

Any other signals are operating-system dependent.

If the request can be honored, the signal function returns the value of handler for the most recent call to signal for the specified signal sig . Otherwise, a value of SIG_ERR is returned and an implementation-defined positive value is stored in errno .

int raise(int sig);


Sends the signal sig to the executing program. The raise function returns 0 if successful and nonzero if unsuccessful.


Previous Page | Next Page | Table of Contents | Index