Skip to content
BSD syscall#46

svc · unix #46

sigaction

Installs or queries the disposition of a signal, including handler and flags.

Prototype

int sigaction(int signum, struct __sigaction *nsa, struct sigaction *osa);

Returns: int

Arguments

NameTypeDirDescription
signumint-
nsastruct __sigaction-
osastruct sigaction-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard46
xnu-1486.2.1146
xnu-1504.15.346
xnu-1504.3.1246
xnu-1504.7.446
xnu-1504.9.1746
xnu-1504.9.2646
xnu-1504.9.3746

Examples

Install SIGINT handler

#include <signal.h>

void on_int(int s) { (void)s; }

struct sigaction sa = {0};
sa.sa_handler = on_int;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sigaction(SIGINT, &sa, NULL);

Notes

The struct sigaction lets you pick SA_SIGINFO (three-argument handler with siginfo_t and ucontext_t), SA_RESTART to auto-restart interrupted syscalls, SA_ONSTACK to run on the alt stack, and SA_RESETHAND for one-shot semantics. On Darwin, the libc wrapper routes through __sigaction with the trampoline at _sigtramp, which is what unwinders rely on.

Detection

DTrace syscall::sigaction:entry shows arg0 as signal number; combine with copyinstr of handler address for symbolication. Frequently sanity-checked by sandbox profiles.

Related APIs

killsigprocmasksigaltstacksigsuspend__sigwait