sigaction(3P) sigaction(3P)NAME sigaction - examine or change signal action SYNOPSIS #include <signal.h> int sigaction(sig,act,oact) int sig; struct sigaction *act, *oact; DESCRIPTION The system defines a set of signals that may be delivered to a process. Signal delivery resembles the occurrence of a hardware interrupt: the signal is blocked from further occurrence, the current process context is saved, and a new one is built. A process may specify a handler to which a signal is delivered, or specify that a signal is to be blocked or ignored. A process may also specify that a default action is to be taken by the system when a signal occurs. Normally, signal handlers execute on the current stack of the process. This may be changed, on a per-handler basis, so that signals are taken on a special ``signal stack.'' All signals have the same priority. Signal routines execute with the signal that caused their invocation but other signals may yet occur. A global ``signal mask'' defines the set of signals currently blocked from delivery to a process. The signal mask for a process is initialized from that of its parent (normally 0). It may be changed with a sigprocmask(3P) call, or when a signal is delivered to the process. When a signal condition arises for a process, the signal is added to a set of signals pending for the process. If the signal is not currently blocked by the process, then it is delivered to the process. When a signal is delivered, the current state of the process is saved, a new signal mask is calculated (as described below), and the signal handler is invoked. The call to the handler is arranged so that if the signal handling routine returns normally, the process resumes execution in the context from before the signal's delivery. If the process wishes to resume in a different context, then it must arrange to restore the previous context itself (see sigsetjmp(3P). sigaction allows the calling process to examine or specify the action to be taken on delivery of a signal. sig January 1992 1
sigaction(3P) sigaction(3P)specifies the signal number. The sigaction structure is defined in <signal.h>: struct sigaction { void (*sa_handler)(); sigset_t sa_mask; int sa_flags; }; If act is not NULL, it points to a structure specifying the action to be taken when the signal is delivered. If oact is not NULL, the action previously associated with the signal is stored in the location pointed to by oact. If act is NULL, signal handling is unchanged. When act is NULL, sigaction can be used to inquire about the current handling of a given signal. The sa_flags field of act can be used to modify the delivery of a specific signal. If sig is SIGCHLD and the SA_NOCLDSTOP flag is not set in sa_flags, a SIGCHLD signal is generated for the calling process if any of its child processes stop. If sig is SIGCHLD and the SA_NOCLDSTOP flag is set in sa_flags, a SIGCHLD signal is not generated for stopped child processes. If the SA_ONSTACK bit is set in sa_flags, the system delivers the signal to the process on a signal stack specified by sigstack(2). If the SA_INTERRUPT bit is set in sa_flags, system calls interrupted by a signal are not restarted. When a signal is caught by a signal-catching function, a new signal mask is calculated and installed for the duration of the signal-catching function or until sigprocmask() or sigsuspend() is called. This mask is formed by taking the union of the current signal mask and the set associated with the action for the signal being delivered, such as sa_mask, and then including the signal being delivered. If and when the user's signal handler returns normally, the original signal mask is restored. Once an action is installed for a specific signal, it remains installed until another action is explicitly requested by another call to sigaction or until one of the exec functions is called. SIGKILL and SIGSTOP cannot be caught or ignored. The set of signals specified by sa_mask is not allowed to block these signals. This is silently enforced. If sigaction fails, no new signal handler is installed. A/UX POSIX defines the following signals: 2 January 1992
sigaction(3P) sigaction(3P)SIGHUP 1 hangup SIGINT 2 interrupt SIGQUIT 3* quit SIGILL 4* illegal instruction SIGABRT 6* aborted SIGFPE 8* floating-point exception SIGKILL 9 kill (cannot be caught, blocked, or ignored) SIGSEGV 11* segmentation violation SIGPIPE 13 write on a pipe with no one to read it SIGALRM 14 alarm clock SIGTERM 15 software termination signal SIGUSR1 16 user defined signal 1 SIGUSR2 17 user defined signal 2 SIGCLD 18⊕ child status has changed SIGTSTP 20† stop signal generated from keyboard SIGTTIN 21† background read attempted from control terminal SIGTTOU 22† background write attempted to control terminal SIGSTOP 23† stop (cannot be caught, blocked, or ignored) SIGXCPU 24 cpu time limit exceeded SIGXFSZ 25 file size limit exceeded SIGCONT 29⊕ continue after stop (cannot be blocked) The following signals are also defined: SIGTRAP 5* trace trap SIGIOT 6* abort SIGEMT 7* EMT instruction SIGBUS 10* bus error SIGSYS 12* bad argument to system call SIGPWR 19 power-fail restart SIGVTALRM 26 virtual time alarm (see setitimer(2)) SIGPROF 27 profiling timer alarm (see setitimer(2)) SIGWINCH 28⊕ window size change SIGURG 30⊕ urgent condition present on socket SIGIO 31⊕ I/O possible on a descriptor (see fcntl(2)) The starred signals (*) in the list above cause a core image if not caught or ignored. The default action for a signal may be reinstated by setting sv_handler to SIG_DFL; this default is termination (with a core image for starred signals) except for signals marked with ⊕ or †. Signals marked with ⊕ are discarded if the action is SIG_DFL; signals marked with † cause the process to stop. If sv_handler is SIG_IGN, the signal is subsequently ignored, and pending instances of the signal are discarded. If a caught signal occurs during certain system calls, the call is normally restarted. The affected system calls are read(2) or write(2) on a slow device such as a terminal, but not a file. This behavior may be inhibited by setting the January 1992 3
sigaction(3P) sigaction(3P)SA_INTERRUPT bit in sa_flags. After a fork(2), the child inherits all signals, the signal mask, and the signal stack. execve(2) resets all caught signals to default action and resets all signals to be caught on the user stack. Ignored signals remain ignored; the signal mask remains the same. STATUS MESSAGES AND VALUES On successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. If any of the following conditions occur, sigaction returns -1 and sets errno to the corresponding value: EINVAL The value of sig is not a valid signal number, or an attempt was made to supply an action for a signal that cannot be caught or ignored. EFAULT act or oact is an invalid address. Or both are invalid addresses. SEE ALSO exec(2), kill(2), sigprocmask(2P), sigvec(2), sigsetops(3P), sigsuspend(3P) 4 January 1992