In computing, is a function API defined by POSIX to give the programmer access to what a program's behavior should be when receiving specific OS signals.
In Unix-like operating systems, one means of inter-process communication is through signals. When an executing unit (process or thread) receives a signal from the OS, it should react in some way defined by the datasheet and the conventional meaning of this signal (i.e. by dumping its data, stopping execution, synchronizing something...).
The <code>sigaction()</code> system call is used to declare the behavior of the program should it receive one particular non-system-reserved signal. This is done by giving along with the system call a structure containing, among others, a function pointer to the signal handling routine. Some predefined signals (such as <code>SIGKILL</code>) have locked behavior that is handled by the system and cannot be overridden by such system calls.
The POSIX standard requires that the sigaction structure be defined as below in the <signal.h> header file and it should contain at least the following fields:
Implementations are free to define additional, possibly non-portable fields. The member specifies the address of a function to be called when the process receives the signal. The signal number is passed as an integer argument to this function. The member specifies additional signals to be blocked during the execution of signal handler. must be initialized with . The member specifies some additional flags. is an alternate signal handler with different set of parameters. Only one signal handler must be specified, either or . If it is desired to use instead of sa_handler, flag must be set.
The <code>sigaction()</code> function provides an interface for reliable signals in replacement of the unreliable <code>signal()</code> function. Signal handlers installed by the <code>signal()</code> interface will be uninstalled immediately prior to execution of the handler. Permanent handlers must therefore be reinstalled by a call to <code>signal()</code> during the handler's execution, causing unreliability in the event a signal of the same type is received during the handler's execution but before the reinstall. Handlers installed by the <code>sigaction()</code> interface can be installed permanently and a custom set of signals can be blocked during the execution of the handler. These signals will be unblocked immediately following the normal termination of the handler (but not in the event of an abnormal termination such as a C++ exception throw.)
In C++, the / programming structure may be (depending on host platforms) based on signalling. To <code>catch</code> signals translated into C++ exceptions, special compiler switches may be necessary on some platforms such as <code>-fnon-call-exceptions</code> for GCC and the Intel C Compiler.