Next: Timefns, Previous: Wchar strings, Up: Top [Contents][Index]

## 7 Signal Handling (`signal.h`)

A signal is an event that interrupts the normal flow of control in your program. Your operating environment normally defines the full set of signals available (see `sys/signal.h`), as well as the default means of dealing with them—typically, either printing an error message and aborting your program, or ignoring the signal.

All systems support at least the following signals:

`SIGABRT`

  Abnormal termination of a program; raised by the `abort` function.

`SIGFPE`

  A domain error in arithmetic, such as overflow, or division by zero.

`SIGILL`

  Attempt to execute as a function data that is not executable.

`SIGINT`

  Interrupt; an interactive attention signal.

`SIGSEGV`

  An attempt to access a memory location that is not available.

`SIGTERM`

  A request that your program end execution.

Two functions are available for dealing with asynchronous signals—one to allow your program to send signals to itself (this is called raising a signal), and one to specify subroutines (called handlers to handle particular signals that you anticipate may occur—whether raised by your own program or the operating environment.

To support these functions, `signal.h` defines three macros:

`SIG_DFL`

  Used with the `signal` function in place of a pointer to a handler subroutine, to select the operating environment’s default handling of a signal.

`SIG_IGN`

  Used with the `signal` function in place of a pointer to a handler, to ignore a particular signal.

`SIG_ERR`

  Returned by the `signal` function in place of a pointer to a handler, to indicate that your request to set up a handler could not be honored for some reason.

`signal.h` also defines an integral type, `sig_atomic_t`. This type is not used in any function declarations; it exists only to allow your signal handlers to declare a static storage location where they may store a signal value. (Static storage is not otherwise reliable from signal handlers.)

Next: Timefns, Previous: Wchar strings, Up: Top [Contents][Index]