# <signal.h>
<signal.h>
# ``
* * *
Include the standard header **``**
to specify how the program handles
**signals** while it executes. A signal can
report some exceptional behavior within the program, such as division
by zero. Or a signal can report some asynchronous event outside the
program, such as someone striking an interactive attention key on
a keyboard.
You can report any signal by calling
[`raise`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#raise). Each implementation
defines what signals it generates (if any) and under what circumstances
it generates them. An implementation can define signals other than
the ones listed here. The standard header
`` can define
additional macros with names beginning with `SIG` to specify
the values of additional signals.
All such values are integer constant expressions >= 0.
You can specify a
**signal handler** for each signal.
A signal handler is a function that the target environment
calls when the corresponding signal occurs.
The target environment suspends execution of the program
until the signal handler returns or calls
[`longjmp`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_setjmp.html#longjmp). For maximum
portability, an asynchronous signal handler should only:
- make calls (that succeed) to the function
[`signal`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#signal)
- assign values to objects of type *volatile*
[`sig_atomic_t`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#sig_atomic_t)
- return control to its caller
Furthermore, in C++, a signal handler should:
- have `extern "C"` linkage
- use only language features common to C and C++
If the signal reports an error within the program (and the signal
is not asynchronous), the signal handler can terminate by calling
[`abort`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_stdlib.html#abort),
[`exit`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_stdlib.html#exit), or
[`longjmp`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_setjmp.html#longjmp).
/* MACROS */
#define SIGABRT = 0>
#define SIGFPE = 0>
#define SIGILL = 0>
#define SIGINT = 0>
#define SIGSEGV = 0>
#define SIGTERM = 0>
#define SIG_DFL
#define SIG_ERR
#define SIG_IGN
/* TYPES */
typedef i-type sig_atomic_t;
/* FUNCTIONS */
int raise(int sig);
void (*signal(int sig, void (*func)(int)))(int);Copy to clipboard
## `raise`
int raise(int sig);Copy to clipboard
The function sends the signal `sig` and returns
zero if the signal is successfully reported.
## `sig_atomic_t`
typedef i-type sig_atomic_t;Copy to clipboard
The type is the integer type `i-type` for objects whose
stored value is altered by an assigning operator as an
**atomic operation**
(an operation that never has its execution suspended
while partially completed).
You declare such objects to communicate between
[signal handlers](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#signal%20handler)
and the rest of the program.
## `SIGABRT`
#define SIGABRT = 0>Copy to clipboard
The macro yields the `sig` argument value
for the abort signal.
## `SIGFPE`
#define SIGFPE = 0>Copy to clipboard
The macro yields the `sig` argument value for the arithmetic
error signal, such as for division by zero or result out of range.
## `SIGILL`
#define SIGILL = 0>Copy to clipboard
The macro yields the `sig` argument value for the invalid
execution signal, such as for a corrupted function image.
## `SIGINT`
#define SIGINT = 0>Copy to clipboard
The macro yields the `sig` argument value for the asynchronous
interactive attention signal.
## `signal`
void (*signal(int sig, void (*func)(int)))(int);Copy to clipboard
The function specifies the new handling for signal `sig`
and returns the previous handling, if successful; otherwise, it returns
[`SIG_ERR`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#SIG_ERR).
- If `func` is
[`SIG_DFL`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#SIG_DFL),
the target environment commences
default handling (as defined by the implementation).
- If `func` is
[`SIG_IGN`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#SIG_IGN),
the target environment ignores subsequent reporting of the signal.
- Otherwise, `func` must be the address of a function returning
*void* that the target environment calls with a single *int*
argument. The target environment calls this function to handle the
signal when it is next reported,
with the value of the signal as its argument.
When the target environment calls a signal handler:
- The target environment can block further occurrences of the
corresponding signal until the handler returns, calls
[`longjmp`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_setjmp.html#longjmp),
or calls `signal` for that signal.
- The target environment can perform default handling of further
occurrences of the corresponding signal.
- For signal
[`SIGILL`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#SIGILL),
the target environment can leave handling unchanged for that signal.
## `SIGSEGV`
#define SIGSEGV = 0>Copy to clipboard
The macro yields the `sig` argument value for the invalid
storage access signal, such as for an erroneous
[lvalue expression](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_express.html#lvalue%20expression).
## `SIGTERM`
#define SIGTERM = 0>Copy to clipboard
The macro yields the `sig` argument value for the asynchronous
termination request signal.
## `SIG_DFL`
#define SIG_DFL Copy to clipboard
The macro yields the `func` argument value to
[`signal`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#signal)
to specify default signal handling.
## `SIG_ERR`
#define SIG_ERR Copy to clipboard
The macro yields the
[`signal`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#signal)
return value to specify an erroneous call.
## `SIG_IGN`
#define SIG_IGN Copy to clipboard
The macro yields the `func` argument value to
[`signal`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_signal.html#signal)
to specify that the target environment is to henceforth ignore the
signal.
* * *
See also the
**[Table of Contents](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#Table%20of%20Contents)** and the
**[Index](https://docs.qualcomm.com/doc/80-N3040-23/topic/_cpp_index.html)**.
*[Copyright](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_crit_pjp.html) © 1992-2006by P.J. Plauger and Jim Brodie. All rights reserved.*
Last Published: Oct 06, 2026
Previous Topic
Next Topic