struct sigaction

Structure that specifies how to handle a signal

Synopsis:

The definition of struct sigaction is complicated; see <signal.h> for details.

Description:

The sigaction structure specifies how to handle a signal. You'll use this structure when you call sigaction() or SignalAction(). The members include the following:

void (*sa_handler) (int signo );
The address of a signal handler or action for nonqueued signals.
void (*sa_sigaction) (int signo, siginfo_t *info, void *other);
The address of a signal handler or action for queued signals.
sigset_t sa_mask
An additional set of signals to be masked (blocked) during execution of the signal-catching function.
int sa_flags
Flags that affect the behavior of the signal:
  • SA_NOCLDSTOP — don't generate a SIGCHLD on the parent for children who stop via SIGSTOP. This flag is used only when the signal is SIGCHLD.
  • SA_NOCLDWAIT — don't create zombie processes or status information on child termination.
  • SA_NODEFER — don't automatically block the signal on entry to the handler.
  • SA_RESETHAND — reset the handler to SIG_DFL and clear SA_SIGINFO on entering the signal handler. In QNX Neutrino, if you set SA_RESETHAND, sigaction() and SignalAction() behave as if you also set SA_NODEFER.

    These functions ignore SA_RESETHAND if you set it for SIGILL or SIGTRAP.

  • SA_SIGINFO — queue this signal. The default is not to queue a signal delivered to a process. If a signal isn't queued, and the same signal is set multiple times on a process or thread before it runs, only the last signal is delivered. If you set the SA_SIGINFO flag, the signals are queued, and they're all delivered.

The sa_handler and sa_sigaction members of act are implemented as a union and share common storage. They differ only in their prototypes, with sa_handler being used for POSIX 1003.1a signals, and sa_sigaction being used for POSIX 1003.1b queued realtime signals. The values stored using either name can be one of:

function
The address of a signal-catching function. See below for details.
SIG_DFL
Use the default action for the signal:
  • SIGIO, SIGURG, and SIGWINCH: ignore the signal.
  • SIGCHLD: ignore the signal, but still let the process's children become zombies.
  • SIGSTOP, SIGTSTP, SIGTTIN, and SIGTTOU: stop the process.
  • SIGCONT: make the program continue.
  • SIGABRT, SIGBUS, SIGEMT (or SIGDEADLK), SIGFPE, SIGILL, SIGQUIT, SIGSEGV, SIGSYS, SIGTRAP, and SIGXCPU: kill the process and write a dump file.
  • all other signals: kill the process.
SIG_IGN
Ignore the signal. Setting SIG_IGN for a signal that's pending discards all pending signals, whether it's blocked or not. New signals are discarded. If you set the action for SIGCHLD to SIG_IGN, your process's children won't enter the zombie state, and the process won't be able to use wait() or waitpid() to wait on their deaths.

The function member of sa_handler or sa_sigaction is always invoked with the following arguments:

void handler(int signo, siginfo_t *info, void *other)

If you have an old-style signal handler of the form:

void handler(int signo)

the microkernel passes the extra arguments, but the function simply ignores them. The info argument is a pointer to a siginfo_t structure that contains details about the signal.

While in the handler, signo is masked, preventing nested signals of the same type. In addition, any signals set in the sa_mask member of act are also ORed into the mask. When the handler returns through a normal return, the previous mask is restored, and any pending and now unmasked signals are acted on. You return to the point in the program where it was interrupted. If the thread was blocked in the kernel when the interruption occurred, the kernel call returns with an EINTR (see ChannelCreate() and SyncMutexLock() for exceptions to this).

Note: It isn't safe to use floating-point operations in signal handlers.

Examples:

See sigaction().

Classification:

POSIX 1003.1