Parameter | Details |
——— | —–– |
sig | The signal to set the signal handler to, one of SIGABRT
, SIGFPE
, SIGILL
, SIGTERM
, SIGINT
, SIGSEGV
or some implementation defined value |
func | The signal handler, which is either of the following: SIG_DFL
, for the default handler, SIG_IGN
to ignore the signal, or a function pointer with the signature void foo(int sig);
.
The usage of signal handlers with only the guarantees from the C standard imposes various limitations what can, or can’t be done in the user defined signal handler.
SIGSEGV
, SIGFPE
, SIGILL
or any other implementation-defined hardware interrupt, the behavior is undefined by the C standard. This is because C’s interface doesn’t give means to change the faulty state (e.g after a division by 0
) and thus when returning the program is in exactly the same erroneous state than before the hardware interrupt occurred.abort
, or raise
, the signal handler is not allowed to call raise
, again.sig_atomic_t
(all versions) or a lock-free atomic type (since C11, optional)volatile
qualified.abort
, _Exit
(since C99), quick_exit
(since C11), signal
(for the same signal number), and some atomic operations (since C11).Behavior is undefined by the C standard if any of the rules above are violated. Platforms may have specific extensions, but these are generally not portable beyond that platform.
printf
is among these function.