Flags for Sigaction (The GNU C Library)

#### 25.3.5 Flags for `sigaction` ¶

The `sa_flags` member of the `sigaction` structure is a catch-all for special features. Most of the time, `SA_RESTART` is a good value to use for this field.

The value of `sa_flags` is interpreted as a bit mask. Thus, you should choose the flags you want to set, OR those flags together, and store the result in the `sa_flags` member of your `sigaction` structure.

Each signal number has its own set of flags. Each call to `sigaction` affects one particular signal number, and the flags that you specify apply only to that particular signal.

In the GNU C Library, establishing a handler with `signal` sets all the flags to zero except for `SA_RESTART`, whose value depends on the settings you have made with `siginterrupt`. See Primitives Interrupted by Signals, to see what this is about.

These macros are defined in the header file `signal.h`.

Macro: `int` SA_NOCLDSTOP ¶

  This flag is meaningful only for the `SIGCHLD` signal. When the flag is set, the system delivers the signal for a terminated child process but not for one that is stopped. By default, `SIGCHLD` is delivered for both terminated children and stopped children.

  Setting this flag for a signal other than `SIGCHLD` has no effect.

Macro: `int` SA_NOCLDWAIT ¶

  This flag is meaningful only for the `SIGCHLD` signal. When the flag is set, the terminated child will not wait for the parent to reap it, or become a zombie if not reaped. The child will instead be reaped by the kernel immediately on termination, similar to setting SIGCHLD to SIG_IGN.

  Setting this flag for a signal other than `SIGCHLD` has no effect.

Macro: `int` SA_NODEFER ¶

  Normally a signal is added to the signal mask while running its own handler; this negates that, so that the same signal can be received while it’s handler is running. Note that if the signal is included in `sa_mask`, it is masked regardless of this flag. Only useful when assigning a function as a signal handler.

Macro: `int` SA_ONSTACK ¶

  If this flag is set for a particular signal number, the system uses the signal stack when delivering that kind of signal. See Using a Separate Signal Stack. If a signal with this flag arrives and you have not set a signal stack, the normal user stack is used instead, as if the flag had not been set.

Macro: `int` SA_RESETHAND ¶

  Resets the handler for a signal to SIG_DFL, at the moment specified handler function begins. I.e. the handler is called once, then the action resets.

Macro: `int` SA_RESTART ¶

  This flag controls what happens when a signal is delivered during certain primitives (such as `open`, `read` or `write`), and the signal handler returns normally. There are two alternatives: the library function can resume, or it can return failure with error code `EINTR`.

  The choice is controlled by the `SA_RESTART` flag for the particular kind of signal that was delivered. If the flag is set, returning from a handler resumes the library function. If the flag is clear, returning from a handler makes the function fail. See Primitives Interrupted by Signals.

Macro: `int` SA_SIGINFO ¶

  Indicates that the `sa_sigaction` three-argument form of the handler should be used in setting up a handler instead of the one-argument `sa_handler` form.