Sigaction
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.[src]
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.[src] struct sigaction { void (*sa_handler)(int); // address of signal handler sigset_t sa_mask; // additional signals to block int sa_flags; // signal options // alternate signal handler void (*sa_sigaction)(int, siginfo_t*, void*); }; Implementations are free to define additional, possibly non-portable fields.[src] The member specifies the address of a function to be called when the process receives the signal.[src] The signal number is passed as an integer argument to this function.[src] The member specifies additional signals to be blocked during the execution of signal handler.[src] must be initialized with .[src] The member specifies some additional flags.[src] is an alternate signal handler with different set of parameters.[src] Only one signal handler must be specified, either or .[src] If it is desired to use instead of sa_handler, flag must be set.[src] include include include include include include define NUM_CHILDREN 10 // Global variable counting number of exited child processes sig_atomic_t exited_children_count = 0; void sigchld_handler(int signo, siginfo_t *sinfo, void *context) { pid_t proc; while ((proc = waitpid(-1, NULL, WNOHANG)) > 0) { // signal main thread ++exited_children_count; // note: printf() is not signal-safe![src] // don't use it in a signal handler.[src] // si_code is the full 32 bit exit code from the child (see also waitid()).[src] printf("sinfo->si_pid = %ld\nproc = %ld\nexit code %d exit reason %d\n", (long)sinfo->si_pid, (long)proc, sinfo->si_status, sinfo->si_code); } } int main() { struct sigaction act = { .sa_sigaction = sigchld_handler, .sa_flags = SA_SIGINFO }; sigemptyset(&act.sa_mask); if (sigaction(SIGCHLD, &act, NULL) == -1) { perror("sigaction()"); return EXIT_FAILURE; } for (int i = 0; i[src]
15 sentences · 15 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Sigaction." encyclopegia.org, 2026, https://encyclopegia.org/wiki/sigaction. Accessed 26 November 2026.
Chicago
"Sigaction." encyclopegia.org. Accessed November 26, 2026. https://encyclopegia.org/wiki/sigaction.
APA
encyclopegia.org. (2026). Sigaction. Retrieved November 26, 2026, from https://encyclopegia.org/wiki/sigaction
Accessed November 26, 2026 · CC BY-SA 4.0 · citation page · JSON