NAME
signal — signal
management
SYNOPSIS
#include
<signal.h>
void (*signal(int sig, void (*func)(int)))(int);
DESCRIPTION
[CX] The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1-2017 defers to the ISO C standard.
The signal () function chooses one of
three ways in which receipt of the signal number sig is to
be subsequently handled. If the value of func is SIG_DFL,
default handling for that signal shall occur. If the value of
func is SIG_IGN, the signal shall be ignored. Otherwise,
the application shall ensure that func points to a
function to be called when that signal occurs. An invocation of such a
function because of a signal, or (recursively) of any further functions
called by that invocation (other than functions in the standard library), is
called a "signal handler".
When a signal occurs, and func points to a function, it is implementation-defined whether the equivalent of a:
signal(sig, SIG_DFL);
is executed or the implementation prevents some implementation-defined set of signals (at least including sig) from occurring until the current signal handling has completed. (If the value of sig is SIGILL, the implementation may alternatively define that no action is taken.) Next the equivalent of:
(*func)(sig);
is executed. If and when the function returns, if the value of sig was SIGFPE, SIGILL, or SIGSEGV or any other implementation-defined value corresponding to a computational exception, the behavior is undefined. Otherwise, the program shall resume execution at the point it was interrupted. The ISO C standard places a restriction on applications relating to the use of raise(3) from signal handlers. [CX] This restriction does not apply to POSIX applications, as POSIX.1-2017 requires raise(3) to be async-signal-safe (see V2_chap02(3)).
[CX] If the process is multi-threaded, or if the process is single-threaded and a signal handler is executed other than as the result of:
- The process calling abort(3), raise(3), [CX] kill(3), pthread_kill(3), or sigqueue(3) to generate a signal that is not blocked
- [CX] A pending signal being unblocked and being delivered before the call that unblocked it returns
the behavior is undefined if the signal handler refers to any object [CX] other than errno with static storage duration other than by assigning a value to an object declared as volatile sig_atomic_t, or if the signal handler calls any function defined in this standard other than [CX] one of the functions listed in V2_chap02(3).
At program start-up, the equivalent of:
signal(sig, SIG_IGN);
is executed for some signals, and the equivalent of:
signal(sig, SIG_DFL);
is executed for all other signals [CX] (see exec).
The signal () function shall not change
the setting of errno if successful.
RETURN VALUE
If the request can be honored, signal ()
shall return the value of func for the most recent call to
signal () for the specified signal
sig. Otherwise, SIG_ERR shall be returned and a positive
value shall be stored in errno.
ERRORS
The signal () function shall fail if:
- [EINVAL]
- [CX] The sig argument is not a valid signal number or an attempt is made to catch a signal that cannot be caught or ignore a signal that cannot be ignored.
The signal () function may fail if:
- [EINVAL]
- [CX] An attempt was made to set the action to SIG_DFL for a signal that cannot be caught or ignored (or both).
EXAMPLES
None.
APPLICATION USAGE
The sigaction(3) function provides a more
comprehensive and reliable mechanism for controlling signals; new
applications should use sigaction(3) rather than
signal ().
RATIONALE
None.
FUTURE DIRECTIONS
None.
SEE ALSO
V2_chap02(3), exec(3), pause(3), raise(3), sigaction(3), sigsuspend(3), waitid(3)
XBD <signal.h>
CHANGE HISTORY
First released in Issue 1. Derived from Issue 1 of the SVID.
Issue 5
Moved from X/OPEN UNIX extension to BASE.
The DESCRIPTION is updated to indicate that the sigpause(3) function restores the signal mask of the process to its original state before returning.
The RETURN VALUE section is updated to indicate that the sigpause(3) function suspends execution of the process until a signal is received, whereupon it returns -1 and sets errno to [EINTR].
Issue 6
Extensions beyond the ISO C standard are marked.
The normative text is updated to avoid use of the term "must" for application requirements.
The DESCRIPTION is updated for alignment with the ISO/IEC 9899:1999 (“ISO C99”) standard.
References to the wait3 () function are removed.
The sighold(3), sigignore(3), sigrelse(3), and sigset(3) functions are split out onto their own reference page.
Issue 7
POSIX.1-2008, Technical Corrigendum 1, XSH/TC1-2008/0580 [275], XSH/TC1-2008/0581 [66], and XSH/TC1-2008/0582 [105] are applied.
POSIX.1-2008, Technical Corrigendum 2, XSH/TC2-2008/0331 [785] is applied.