---
name: "rt_sigaction"
section: "2"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/sigaction"
---

# rt\_sigaction(2)

examine and change a signal action

Part of [sigaction(2)](/sigaction/2.md).

## NAME

sigaction, rt\_sigaction - examine and change a signal action

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <signal.h>
```

**int sigaction(int** *signum***,**               **const struct sigaction \*\_Nullable restrict** *act***,**               **struct sigaction \*\_Nullable restrict** *oldact***);**

Feature Test Macro Requirements for glibc (see [**feature\_test\_macros**(7)](/feature_test_macros/7.md)):

**sigaction**():

```
    _POSIX_C_SOURCE
```

*siginfo\_t*:

```
    _POSIX_C_SOURCE >= 199309L
```

## DESCRIPTION

The **sigaction**() system call is used to change the action taken by a process on receipt of a specific signal. (See [**signal**(7)](/signal/7.md) for an overview of signals.)

*signum* specifies the signal and can be any valid signal except **SIGKILL** and **SIGSTOP**.

If *act* is non-NULL, the new action for signal *signum* is installed from *act*. If *oldact* is non-NULL, the previous action is saved in *oldact*.

The *sigaction* structure is defined as something like:

```
struct sigaction {
    void     (*sa_handler)(int);
    void     (*sa_sigaction)(int, siginfo_t *, void *);
    sigset_t   sa_mask;
    int        sa_flags;
    void     (*sa_restorer)(void);
};
```

On some architectures a union is involved: do not assign to both *sa\_handler* and *sa\_sigaction*.

The *sa\_restorer* field is not intended for application use. (POSIX does not specify a *sa\_restorer* field.) Some further details of the purpose of this field can be found in [**sigreturn**(2)](/sigreturn/2.md).

*sa\_handler* specifies the action to be associated with *signum* and can be one of the following:

- •

  **SIG\_DFL** for the default action.

- •

  **SIG\_IGN** to ignore this signal.

- •

  A pointer to a signal handling function. This function receives the signal number as its only argument.

If **SA\_SIGINFO** is specified in *sa\_flags*, then *sa\_sigaction* (instead of *sa\_handler*) specifies the signal-handling function for *signum*. This function receives three arguments, as described below.

*sa\_mask* specifies a mask of signals which should be blocked (i.e., added to the signal mask of the thread in which the signal handler is invoked) during execution of the signal handler. In addition, the signal which triggered the handler will be blocked, unless the **SA\_NODEFER** flag is used.

*sa\_flags* specifies a set of flags which modify the behavior of the signal. It is formed by the bitwise OR of zero or more of the following:

- **SA\_NOCLDSTOP**

  If *signum* is **SIGCHLD**, do not receive notification when child processes stop (i.e., when they receive one of **SIGSTOP**, **SIGTSTP**, **SIGTTIN**, or **SIGTTOU**) or resume (i.e., they receive **SIGCONT**) (see [**wait**(2)](/wait/2.md)). This flag is meaningful only when establishing a handler for **SIGCHLD**.

- **SA\_NOCLDWAIT** (since Linux 2.6)

  If *signum* is **SIGCHLD**, do not transform children into zombies when they terminate. See also [**waitpid**(2)](/waitpid/2.md). This flag is meaningful only when establishing a handler for **SIGCHLD**, or when setting that signal's disposition to **SIG\_DFL**.

-

  If the **SA\_NOCLDWAIT** flag is set when establishing a handler for **SIGCHLD**, POSIX.1 leaves it unspecified whether a **SIGCHLD** signal is generated when a child process terminates. On Linux, a **SIGCHLD** signal is generated in this case; on some other implementations, it is not.

- **SA\_NODEFER**

  Do not add the signal to the thread's signal mask while the handler is executing, unless the signal is specified in *act.sa\_mask*. Consequently, a further instance of the signal may be delivered to the thread while it is executing the handler. This flag is meaningful only when establishing a signal handler.

-

  **SA\_NOMASK** is an obsolete, nonstandard synonym for this flag.

- **SA\_ONSTACK**

  Call the signal handler on an alternate signal stack provided by [**sigaltstack**(2)](/sigaltstack/2.md). If an alternate stack is not available, the default stack will be used. This flag is meaningful only when establishing a signal handler.

- **SA\_RESETHAND**

  Restore the signal action to the default upon entry to the signal handler. This flag is meaningful only when establishing a signal handler.

-

  **SA\_ONESHOT** is an obsolete, nonstandard synonym for this flag.

- **SA\_RESTART**

  Provide behavior compatible with BSD signal semantics by making certain system calls restartable across signals. This flag is meaningful only when establishing a signal handler. See [**signal**(7)](/signal/7.md) for a discussion of system call restarting.

- **SA\_RESTORER**

  *Not intended for application use*. This flag is used by C libraries to indicate that the *sa\_restorer* field contains the address of a "signal trampoline". See [**sigreturn**(2)](/sigreturn/2.md) for more details.

- **SA\_SIGINFO** (since Linux 2.2)

  The signal handler takes three arguments, not one. In this case, *sa\_sigaction* should be set instead of *sa\_handler*. This flag is meaningful only when establishing a signal handler.

- **SA\_UNSUPPORTED** (since Linux 5.11)

  Used to dynamically probe for flag bit support.

-

  If an attempt to register a handler succeeds with this flag set in *act-\>sa\_flags* alongside other flags that are potentially unsupported by the kernel, and an immediately subsequent **sigaction**() call specifying the same signal number and with a non-NULL *oldact* argument yields **SA\_UNSUPPORTED** *clear* in *oldact-\>sa\_flags*, then *oldact-\>sa\_flags* may be used as a bitmask describing which of the potentially unsupported flags are, in fact, supported. See the section "Dynamically probing for flag bit support" below for more details.

- **SA\_EXPOSE\_TAGBITS** (since Linux 5.11)

  Normally, when delivering a signal, an architecture-specific set of tag bits are cleared from the *si\_addr* field of *siginfo\_t*. If this flag is set, an architecture-specific subset of the tag bits will be preserved in *si\_addr*.

-

  Programs that need to be compatible with Linux versions older than 5.11 must use **SA\_UNSUPPORTED** to probe for support.

### The siginfo\_t argument to a SA\_SIGINFO handler

When the **SA\_SIGINFO** flag is specified in *act.sa\_flags*, the signal handler address is passed via the *act.sa\_sigaction* field. This handler takes three arguments, as follows:

```
void
handler(int sig, siginfo_t *info, void *ucontext)
{
    ...
}
```

These three arguments are as follows

- *sig*

  The number of the signal that caused invocation of the handler.

- *info*

  A pointer to a *siginfo\_t*, which is a structure containing further information about the signal, as described below.

- *ucontext*

  This is a pointer to a *ucontext\_t* structure, cast to *void \**. The structure pointed to by this field contains signal context information that was saved on the user-space stack by the kernel; for details, see [**sigreturn**(2)](/sigreturn/2.md). Further information about the *ucontext\_t* structure can be found in [**getcontext**(3)](/getcontext/3.md) and [**signal**(7)](/signal/7.md). Commonly, the handler function doesn't make any use of the third argument.

The *siginfo\_t* data type is a structure with the following fields:

```
siginfo_t {
    int      si_signo;     /* Signal number */
    int      si_errno;     /* An errno value */
    int      si_code;      /* Signal code */
    int      si_trapno;    /* Trap number that caused
                              hardware-generated signal
                              (unused on most architectures) */
    pid_t    si_pid;       /* Sending process ID */
    uid_t    si_uid;       /* Real user ID of sending process */
    int      si_status;    /* Exit value or signal */
    clock_t  si_utime;     /* User time consumed */
    clock_t  si_stime;     /* System time consumed */
    union sigval si_value; /* Signal value */
    int      si_int;       /* POSIX.1b signal */
    void    *si_ptr;       /* POSIX.1b signal */
    int      si_overrun;   /* Timer overrun count;
                              POSIX.1b timers */
    int      si_timerid;   /* Timer ID; POSIX.1b timers */
    void    *si_addr;      /* Memory location which caused fault */
    long     si_band;      /* Band event (was int in
                              glibc 2.3.2 and earlier) */
    int      si_fd;        /* File descriptor */
    short    si_addr_lsb;  /* Least significant bit of address
                              (since Linux 2.6.32) */
    void    *si_lower;     /* Lower bound when address violation
                              occurred (since Linux 3.19) */
    void    *si_upper;     /* Upper bound when address violation
                              occurred (since Linux 3.19) */
    int      si_pkey;      /* Protection key on PTE that caused
                              fault (since Linux 4.6) */
    void    *si_call_addr; /* Address of system call instruction
                              (since Linux 3.5) */
    int      si_syscall;   /* Number of attempted system call
                              (since Linux 3.5) */
    unsigned int si_arch;  /* Architecture of attempted system call
                              (since Linux 3.5) */
}
```

*si\_signo*, *si\_errno* and *si\_code* are defined for all signals. (*si\_errno* is generally unused on Linux.) The rest of the struct may be a union, so that one should read only the fields that are meaningful for the given signal:

- •

  Signals sent with [**kill**(2)](/kill/2.md) and [**sigqueue**(3)](/sigqueue/3.md) fill in *si\_pid* and *si\_uid*. In addition, signals sent with [**sigqueue**(3)](/sigqueue/3.md) fill in *si\_int* and *si\_ptr* with the values specified by the sender of the signal; see [**sigqueue**(3)](/sigqueue/3.md) for more details.

- •

  Signals sent by POSIX.1b timers (since Linux 2.6) fill in *si\_overrun* and *si\_timerid*. The *si\_timerid* field is an internal ID used by the kernel to identify the timer; it is not the same as the timer ID returned by [**timer\_create**(2)](/timer_create/2.md). The *si\_overrun* field is the timer overrun count; this is the same information as is obtained by a call to [**timer\_getoverrun**(2)](/timer_getoverrun/2.md). These fields are nonstandard Linux extensions.

- •

  Signals sent for message queue notification (see the description of **SIGEV\_SIGNAL** in [**mq\_notify**(3)](/mq_notify/3.md)) fill in *si\_int*/*si\_ptr*, with the *sigev\_value* supplied to [**mq\_notify**(3)](/mq_notify/3.md); *si\_pid*, with the process ID of the message sender; and *si\_uid*, with the real user ID of the message sender.

- •

  **SIGCHLD** fills in *si\_pid*, *si\_uid*, *si\_status*, *si\_utime*, and *si\_stime*, providing information about the child. The *si\_pid* field is the process ID of the child; *si\_uid* is the child's real user ID. The *si\_status* field contains the exit status of the child (if *si\_code* is **CLD\_EXITED**), or the signal number that caused the process to change state. The *si\_utime* and *si\_stime* contain the user and system CPU time used by the child process; these fields do not include the times used by waited-for children (unlike [**getrusage**(2)](/getrusage/2.md) and [**times**(2)](/times/2.md)). Up to Linux 2.6, and since Linux 2.6.27, these fields report CPU time in units of *sysconf(\_SC\_CLK\_TCK)*. In Linux 2.6 kernels before Linux 2.6.27, a bug meant that these fields reported time in units of the (configurable) system jiffy (see [**time**(7)](/time/7.md)).

- •

  **SIGILL**, **SIGFPE**, **SIGSEGV**, **SIGBUS**, and **SIGTRAP** fill in *si\_addr* with the address of the fault. On some architectures, these signals also fill in the *si\_trapno* field.

-

  Some suberrors of **SIGBUS**, in particular **BUS\_MCEERR\_AO** and **BUS\_MCEERR\_AR**, also fill in *si\_addr\_lsb*. This field indicates the least significant bit of the reported address and therefore the extent of the corruption. For example, if a full page was corrupted, *si\_addr\_lsb* contains *log2(sysconf(\_SC\_PAGESIZE))*. When **SIGTRAP** is delivered in response to a [**ptrace**(2)](/ptrace/2.md) event (PTRACE\_EVENT\_foo), *si\_addr* is not populated, but *si\_pid* and *si\_uid* are populated with the respective process ID and user ID responsible for delivering the trap. In the case of [**seccomp**(2)](/seccomp/2.md), the tracee will be shown as delivering the event. **BUS\_MCEERR\_\*** and *si\_addr\_lsb* are Linux-specific extensions.

-

  The **SEGV\_BNDERR** suberror of **SIGSEGV** populates *si\_lower* and *si\_upper*.

-

  The **SEGV\_PKUERR** suberror of **SIGSEGV** populates *si\_pkey*.

- •

  **SIGIO**/**SIGPOLL** (the two names are synonyms on Linux) fills in *si\_band* and *si\_fd*. The *si\_band* event is a bit mask containing the same values as are filled in the *revents* field by [**poll**(2)](/poll/2.md). The *si\_fd* field indicates the file descriptor for which the I/O event occurred; for further details, see the description of **F\_SETSIG** in [**fcntl**(2)](/fcntl/2.md).

- •

  **SIGSYS**, generated (since Linux 3.5) when a seccomp filter returns **SECCOMP\_RET\_TRAP**, fills in *si\_call\_addr*, *si\_syscall*, *si\_arch*, *si\_errno*, and other fields as described in [**seccomp**(2)](/seccomp/2.md).

### The si\_code field

The *si\_code* field inside the *siginfo\_t* argument that is passed to a **SA\_SIGINFO** signal handler is a value (not a bit mask) indicating why this signal was sent. For a [**ptrace**(2)](/ptrace/2.md) event, *si\_code* will contain **SIGTRAP** and have the ptrace event in the high byte:

```
(SIGTRAP | PTRACE_EVENT_foo << 8).
```

For a non-[**ptrace**(2)](/ptrace/2.md) event, the values that can appear in *si\_code* are described in the remainder of this section. Since glibc 2.20, the definitions of most of these symbols are obtained from *\<signal.h\>* by defining feature test macros (before including *any* header file) as follows:

- •

  **\_XOPEN\_SOURCE** with the value 500 or greater;

- •

  **\_XOPEN\_SOURCE** and **\_XOPEN\_SOURCE\_EXTENDED**; or

- •

  **\_POSIX\_C\_SOURCE** with the value 200809L or greater.

For the **TRAP\_\*** constants, the symbol definitions are provided only in the first two cases. Before glibc 2.20, no feature test macros were required to obtain these symbols.

For a regular signal, the following list shows the values which can be placed in *si\_code* for any signal, along with the reason that the signal was generated.

- **SI\_USER**

  [**kill**(2)](/kill/2.md).

- **SI\_KERNEL**

  Sent by the kernel.

- **SI\_QUEUE**

  [**sigqueue**(3)](/sigqueue/3.md).

- **SI\_TIMER**

  POSIX, or [**setitimer**(2)](/setitimer/2.md) or [**alarm**(2)](/alarm/2.md) timer expired.

- **SI\_MESGQ** (since Linux 2.6.6)

  POSIX message queue state changed; see [**mq\_notify**(3)](/mq_notify/3.md).

- **SI\_ASYNCIO**

  AIO completed.

- **SI\_SIGIO**

  Queued **SIGIO** (only up to Linux 2.2; from Linux 2.4 onward **SIGIO**/**SIGPOLL** fills in *si\_code* as described below).

- **SI\_TKILL** (since Linux 2.4.19)

  [**tkill**(2)](/tkill/2.md) or [**tgkill**(2)](/tgkill/2.md).

- **SI\_ASYNCNL**

  Async name lookup completion.

The following values can be placed in *si\_code* for a **SIGILL** signal:

- **ILL\_ILLOPC**

  Illegal opcode.

- **ILL\_ILLOPN**

  Illegal operand.

- **ILL\_ILLADR**

  Illegal addressing mode.

- **ILL\_ILLTRP**

  Illegal trap.

- **ILL\_PRVOPC**

  Privileged opcode.

- **ILL\_PRVREG**

  Privileged register.

- **ILL\_COPROC**

  Coprocessor error.

- **ILL\_BADSTK**

  Internal stack error.

The following values can be placed in *si\_code* for a **SIGFPE** signal:

- **FPE\_INTDIV**

  Integer divide by zero.

- **FPE\_INTOVF**

  Integer overflow.

- **FPE\_FLTDIV**

  Floating-point divide by zero.

- **FPE\_FLTOVF**

  Floating-point overflow.

- **FPE\_FLTUND**

  Floating-point underflow.

- **FPE\_FLTRES**

  Floating-point inexact result.

- **FPE\_FLTINV**

  Floating-point invalid operation.

- **FPE\_FLTSUB**

  Subscript out of range.

- **FPE\_FLTUNK** (since Linux 4.17)

  Undiagnosed floating-point exception.

- **FPE\_CONDTRAP** (PARISC only)

  Trap on condition.

The following values can be placed in *si\_code* for a **SIGSEGV** signal:

- **SEGV\_MAPERR**

  Address not mapped to object.

- **SEGV\_ACCERR**

  Invalid permissions for mapped object.

- **SEGV\_BNDERR** (since Linux 3.19)

  Failed address bound checks.

- **SEGV\_PKUERR** (since Linux 4.6)

  Access was denied by memory protection keys. See [**pkeys**(7)](/pkeys/7.md). The protection key which applied to this access is available via *si\_pkey*.

- **SEGV\_ACCADI** (since Linux 4.17; SPARC only)

  Application Data Integrity not enabled for mapped object.

- **SEGV\_ADIDERR** (since Linux 4.17; SPARC only)

  Disrupting Memory Corruption Detection error.

- **SEGV\_ADIPERR** (since Linux 4.17; SPARC only)

  Precise Memory Corruption Detection exception.

- **SEGV\_MTEAERR** (since Linux 5.10; ARM only)

  Asynchronous Memory Tagging Extension error.

- **SEGV\_MTESERR** (since Linux 5.10; ARM only)

  Synchronous Memory Tagging Extension exception.

- **SEGV\_CPERR** (since Linux 6.10)

  Control protection fault.

The following values can be placed in *si\_code* for a **SIGBUS** signal:

- **BUS\_ADRALN**

  Invalid address alignment.

- **BUS\_ADRERR**

  Nonexistent physical address.

- **BUS\_OBJERR**

  Object-specific hardware error.

- **BUS\_MCEERR\_AR** (since Linux 2.6.32)

  Hardware memory error consumed on a machine check; action required.

- **BUS\_MCEERR\_AO** (since Linux 2.6.32)

  Hardware memory error detected in process but not consumed; action optional.

The following values can be placed in *si\_code* for a **SIGTRAP** signal:

- **TRAP\_BRKPT**

  Process breakpoint.

- **TRAP\_TRACE**

  Process trace trap.

- **TRAP\_BRANCH** (since Linux 2.4; IA64 only)

  Process taken branch trap.

- **TRAP\_HWBKPT** (since Linux 2.4; IA64 only)

  Hardware breakpoint/watchpoint.

- **TRAP\_UNK** (since Linux 4.18)

  Undiagnosed trap.

- **TRAP\_PERF** (since Linux 5.13 and glibc 2.43)

  Perf event with sigtrap=1.

The following values can be placed in *si\_code* for a **SIGCHLD** signal:

- **CLD\_EXITED**

  Child has exited.

- **CLD\_KILLED**

  Child was killed.

- **CLD\_DUMPED**

  Child terminated abnormally.

- **CLD\_TRAPPED**

  Traced child has trapped.

- **CLD\_STOPPED**

  Child has stopped.

- **CLD\_CONTINUED** (since Linux 2.6.9)

  Stopped child has continued.

The following values can be placed in *si\_code* for a **SIGIO**/**SIGPOLL** signal:

- **POLL\_IN**

  Data input available.

- **POLL\_OUT**

  Output buffers available.

- **POLL\_MSG**

  Input message available.

- **POLL\_ERR**

  I/O error.

- **POLL\_PRI**

  High priority input available.

- **POLL\_HUP**

  Device disconnected.

The following values can be placed in *si\_code* for a **SIGSYS** signal:

- **SYS\_SECCOMP** (since Linux 3.5 and glibc 2.43)

  Triggered by a [**seccomp**(2)](/seccomp/2.md) filter rule.

- **SYS\_USER\_DISPATCH** (since Linux 5.11 and glibc 2.43)

  Syscall user dispatch triggered.

The following value can be placed in *si\_code* for a **SIGEMT** signal:

- **EMT\_TAGOVF** (SPARC only)

  Tag overflow.

### Dynamically probing for flag bit support

The **sigaction**() call on Linux accepts unknown bits set in *act-\>sa\_flags* without error. The behavior of the kernel starting with Linux 5.11 is that a second **sigaction**() will clear unknown bits from *oldact-\>sa\_flags*. However, historically, a second **sigaction**() call would typically leave those bits set in *oldact-\>sa\_flags*.

This means that support for new flags cannot be detected simply by testing for a flag in *sa\_flags*, and a program must test that **SA\_UNSUPPORTED** has been cleared before relying on the contents of *sa\_flags*.

Since the behavior of the signal handler cannot be guaranteed unless the check passes, it is wise to either block the affected signal while registering the handler and performing the check in this case, or where this is not possible, for example if the signal is synchronous, to issue the second **sigaction**() in the signal handler itself.

In kernels that do not support a specific flag, the kernel's behavior is as if the flag was not set, even if the flag was set in *act-\>sa\_flags*.

The flags **SA\_NOCLDSTOP**, **SA\_NOCLDWAIT**, **SA\_SIGINFO**, **SA\_ONSTACK**, **SA\_RESTART**, **SA\_NODEFER**, **SA\_RESETHAND**, and, if defined by the architecture, **SA\_RESTORER** may not be reliably probed for using this mechanism, because they were introduced before Linux 5.11. However, in general, programs may assume that these flags are supported, since they have all been supported since Linux 2.6, which was released in the year 2003.

See EXAMPLES below for a demonstration of the use of **SA\_UNSUPPORTED**.

## RETURN VALUE

**sigaction**() returns 0 on success; on error, -1 is returned, and *errno* is set to indicate the error.

## ERRORS

- **EFAULT**

  *act* or *oldact* points to memory which is not a valid part of the process address space.

- **EINVAL**

  An invalid signal was specified. This will also be generated if an attempt is made to change the action for **SIGKILL** or **SIGSTOP**, which cannot be caught or ignored.

## VERSIONS

### C library/kernel differences

The glibc wrapper function for **sigaction**() gives an error (**EINVAL**) on attempts to change the disposition of the two real-time signals used internally by the NPTL threading implementation. See [**nptl**(7)](/nptl/7.md) for details.

On architectures where the signal trampoline resides in the C library, the glibc wrapper function for **sigaction**() places the address of the trampoline code in the *act.sa\_restorer* field and sets the **SA\_RESTORER** flag in the *act.sa\_flags* field. See [**sigreturn**(2)](/sigreturn/2.md).

The original Linux system call was named **sigaction**(). However, with the addition of real-time signals in Linux 2.2, the fixed-size, 32-bit *sigset\_t* type supported by that system call was no longer fit for purpose. Consequently, a new system call, **rt\_sigaction**(), was added to support an enlarged *sigset\_t* type. The new system call takes a fourth argument, *size\_t sigsetsize*, which specifies the size in bytes of the signal sets in *act.sa\_mask* and *oldact.sa\_mask*. This argument is currently required to have the value *sizeof(sigset\_t)* (or the error **EINVAL** results). The glibc **sigaction**() wrapper function hides these details from us, transparently calling **rt\_sigaction**() when the kernel provides it.

## STANDARDS

POSIX.1-2024.

## HISTORY

POSIX.1-2001, SVr4.

POSIX.1-1990 disallowed setting the action for **SIGCHLD** to **SIG\_IGN**. POSIX.1-2001 and later allow this possibility, so that ignoring **SIGCHLD** can be used to prevent the creation of zombies (see [**wait**(2)](/wait/2.md)). Nevertheless, the historical BSD and System V behaviors for ignoring **SIGCHLD** differ, so that the only completely portable method of ensuring that terminated children do not become zombies is to catch the **SIGCHLD** signal and perform a [**wait**(2)](/wait/2.md) or similar.

POSIX.1-1990 specified only **SA\_NOCLDSTOP**. POSIX.1-2001 added **SA\_NOCLDWAIT**, **SA\_NODEFER**, **SA\_ONSTACK**, **SA\_RESETHAND**, **SA\_RESTART**, and **SA\_SIGINFO** as XSI extensions. POSIX.1-2008 moved **SA\_NODEFER**, **SA\_RESETHAND**, **SA\_RESTART**, and **SA\_SIGINFO** to the base specifications. Use of these latter values in *sa\_flags* may be less portable in applications intended for older UNIX implementations.

The **SA\_RESETHAND** flag is compatible with the SVr4 flag of the same name.

The **SA\_NODEFER** flag is compatible with the SVr4 flag of the same name under kernels 1.3.9 and later. On older kernels the Linux implementation allowed the receipt of any signal, not just the one we are installing (effectively overriding any *sa\_mask* settings).

## NOTES

A child created via [**fork**(2)](/fork/2.md) inherits a copy of its parent's signal dispositions. During an [**execve**(2)](/execve/2.md), the dispositions of handled signals are reset to the default; the dispositions of ignored signals are left unchanged.

According to POSIX, the behavior of a process is undefined after it ignores a **SIGFPE**, **SIGILL**, or **SIGSEGV** signal that was not generated by [**kill**(2)](/kill/2.md) or [**raise**(3)](/raise/3.md). Integer division by zero has undefined result. On some architectures it will generate a **SIGFPE** signal. (Also dividing the most negative integer by -1 may generate **SIGFPE**.) Ignoring this signal might lead to an endless loop.

**sigaction**() can be called with a NULL second argument to query the current signal handler. It can also be used to check whether a given signal is valid for the current machine by calling it with NULL second and third arguments.

It is not possible to block **SIGKILL** or **SIGSTOP** (by specifying them in *sa\_mask*). Attempts to do so are silently ignored.

See [**sigsetops**(3)](/sigsetops/3.md) for details on manipulating signal sets.

See [**signal-safety**(7)](/signal-safety/7.md) for a list of the async-signal-safe functions that can be safely called inside from inside a signal handler.

POSIX only guarantees **SI\_TIMER** for signals created by [*timer\_create*(2)](/timer_create/2.md). Implementations are free to also provide it for other types of timers. The Linux behavior matches NetBSD.

### Undocumented

Before the introduction of **SA\_SIGINFO**, it was also possible to get some additional information about the signal. This was done by providing an *sa\_handler* signal handler with a second argument of type *struct sigcontext*, which is the same structure as the one that is passed in the *uc\_mcontext* field of the *ucontext* structure that is passed (via a pointer) in the third argument of the *sa\_sigaction* handler. See the relevant Linux kernel sources for details. This use is obsolete now.

## BUGS

When delivering a signal resulting from a hardware exception with a **SA\_SIGINFO** handler, the kernel does not always provide meaningful values for all of the fields of the *siginfo\_t* that are relevant for that signal. For example, when the x86 *int* instruction is called with a forbidden argument (any number other than 3 or 128), a **SIGSEGV** signal is delivered, but the *siginfo\_t* passed to the signal handler has all its fields besides *si\_signo* and *si\_code* set to zero, even if other fields should be set (as an example, *si\_addr* should be non-zero for all **SIGSEGV** signals).

Up to and including Linux 2.6.13, specifying **SA\_NODEFER** in *sa\_flags* prevents not only the delivered signal from being masked during execution of the handler, but also the signals specified in *sa\_mask*. This bug was fixed in Linux 2.6.14.

## EXAMPLES

See [**mprotect**(2)](/mprotect/2.md).

### Probing for flag support

The following example program exits with status **EXIT\_SUCCESS** if **SA\_EXPOSE\_TAGBITS** is determined to be supported, and **EXIT\_FAILURE** otherwise.

```
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static void
handler(int signo, siginfo_t *info, void *context)
{
    struct sigaction oldact;
    if (sigaction(SIGSEGV, NULL, &oldact) == -1
        || (oldact.sa_flags & SA_UNSUPPORTED)
        || !(oldact.sa_flags & SA_EXPOSE_TAGBITS))
    {
        _exit(EXIT_FAILURE);
    }
    _exit(EXIT_SUCCESS);
}
int
main(void)
{
    struct sigaction act = { 0 };
    act.sa_flags = SA_SIGINFO | SA_UNSUPPORTED | SA_EXPOSE_TAGBITS;
    act.sa_sigaction = &handler;
    if (sigaction(SIGSEGV, &act, NULL) == -1) {
        perror("sigaction");
        exit(EXIT_FAILURE);
    }
    raise(SIGSEGV);
}
```

## SEE ALSO

[**kill**(1)](/kill/1.md), [**kill**(2)](/kill/2.md), [**pause**(2)](/pause/2.md), [**pidfd\_send\_signal**(2)](/pidfd_send_signal/2.md), [**restart\_syscall**(2)](/restart_syscall/2.md), [**seccomp**(2)](/seccomp/2.md), [**sigaltstack**(2)](/sigaltstack/2.md), [**signal**(2)](/signal/2.md), [**signalfd**(2)](/signalfd/2.md), [**sigpending**(2)](/sigpending/2.md), [**sigprocmask**(2)](/sigprocmask/2.md), [**sigreturn**(2)](/sigreturn/2.md), [**sigsuspend**(2)](/sigsuspend/2.md), [**wait**(2)](/wait/2.md), [**killpg**(3)](/killpg/3.md), [**raise**(3)](/raise/3.md), [**siginterrupt**(3)](/siginterrupt/3.md), [**sigqueue**(3)](/sigqueue/3.md), [**sigsetops**(3)](/sigsetops/3.md), [**sigvec**(3)](/sigvec/3.md), [**core**(5)](/core/5.md), [**signal**(7)](/signal/7.md)
