sigaction
Sigaction is a POSIX API used to define and control how a process handles signals. It provides a more consistent and portable mechanism than the older signal() interface, allowing precise specification of the handler and the context in which it runs.
The core data type is struct sigaction, which includes:
- sa_handler, a pointer to a function taking an int (the signal number); or sa_sigaction, a pointer
- sa_mask, a signal set that specifies which signals should be blocked during execution of the signal
- sa_flags, a set of options that modify handler behavior (see below).
- sa_restorer, a historical field present on some systems (often unused and considered obsolete).
To install a handler, a program fills a struct sigaction and calls sigaction(signum, &act, oldact). If oldact
- SA_RESTART, to automatically restart certain interrupted system calls.
- SA_NODEFER, to avoid blocking the signal while its handler runs.
- SA_RESETHAND, to reset the handler to default behavior after the signal is handled.
- SA_SIGINFO, to supply additional information to the handler via the siginfo_t structure.
- SA_ONSTACK, to use an alternate signal stack.
Notes: sigaction is the standard, portable interface for signal handling across POSIX systems (Linux, BSD, macOS,