Names specified here
Name Description Notes Source Availability
SIG_ATOMIC_MAX Maximum value of sig_atomic_t H M <stdint.h> C99 C11
SIG_ATOMIC_MIN Minimum value of sig_atomic_t H M <stdint.h> C99 C11
Names specified for <signal.h>, “Signal handling”
Name Description Notes Source Availability
raise() Generate signal (·) <signal.h> C89 C90 C95 C99 C11
SIG_DFL Default signal handler M <signal.h> C89 C90 C95 C99 C11
SIG_ERR Signal-handler change error M <signal.h> C89 C90 C95 C99 C11
SIG_IGN Signal should be ignored M <signal.h> C89 C90 C95 C99 C11
SIGABRT Execution aborted M <signal.h> C89 C90 C95 C99 C11
SIGFPE Floating-point exception M <signal.h> C89 C90 C95 C99 C11
SIGILL Illegal instruction M <signal.h> C89 C90 C95 C99 C11
SIGINT User interruption M <signal.h> C89 C90 C95 C99 C11
SIGSEGV Illegal memory access M <signal.h> C89 C90 C95 C99 C11
SIGTERM Environment requests termination M <signal.h> C89 C90 C95 C99 C11
sig_atomic_t Type for use by signal handlers H T <signal.h> C89 C90 C95 C99 C11
signal() Set signal handler (·) <signal.h> C89 C90 C95 C99 C11

This header is available in C89, C90, C95, C99 and C11.

Signals are indicators of exceptional circumstances during a program's execution. Each signal has a type indicating its cause. Signal types are identified by names beginning with SIG and an upper-case letter. Six are specified in the standard, but most implementations will define many more:

Macros with names matching ^SIG[A-Z] might be added to <signal.h>.

SIGINT indicates that the user attempted to stop a program, usually through its terminal. SIGTERM indicates that some part of the system in which the program is running has asked the program to terminate.

SIGABRT is raised by the abort function, and by assert.

SIGILL indicates that an illegal machine-code instruction was encountered. This typically happens when an invalid function pointer is invoked.

SIGFPE indicates that a floating-point exception occurred, for example, a division by zero.

SIGSEGV indicates some fault relating to memory access. It commonly happens when mistakenly dereferencing a null pointer.

#include <signal.h>
int raise(int s);

You can cause a signal to occur artificially by calling the raise function with the signal type. If it returns at all, it returns zero on success and non-zero otherwise.

Many signals will cause a program to terminate by default. A C program can change the behaviour by specifying a signal handler, a function to be called when the signal occurs.

#include <signal.h>
void (*signal(int s, void (*handler)(int)))(int);

The function signal sets a new signal handler for signal type s. The second argument of signal is a pointer to the new signal handler. The return value is a pointer to the previous handler, or SIG_ERR if signal could not change the current handler for the specified signal type.

Two special values can be given instead of a function pointer. SIG_DFL means that the default behaviour for the signal type is to be followed. SIG_IGN means that the signal should be ignored.

Macros with names matching SIG_[A-Z] might be added to <signal.h>.

A signal handler should have the following form:

void handler(int s);

When a signal of type s occurs, handler(s) is invoked.

Very little is specified about the behaviour that a signal handler can do. To be completely portable, it should limit itself to:

sig_atomic_t is an integer type with the range SIG_ATOMIC_MIN to SIG_ATOMIC_MAX, which is at least [−127, +127]


CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2023-10-04T20:24:03.201+0000