1 .\" Copyright (c) 1980, 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" From: @(#)sigaction.2 8.2 (Berkeley) 4/3/94
40 .Nd software signal facilities
42 .Fd #include <signal.h>
45 void (*sa_handler)(); /* signal handler */
46 sigset_t sa_mask; /* signal mask to apply */
47 int sa_flags; /* see signal options below */
51 .Fn sigaction "int sig" "const struct sigaction *act" "struct sigaction *oact"
53 The system defines a set of signals that may be delivered to a process.
54 Signal delivery resembles the occurrence of a hardware interrupt:
55 the signal is normally blocked from further occurrence, the current process
56 context is saved, and a new one is built. A process may specify a
58 to which a signal is delivered, or specify that a signal is to be
60 A process may also specify that a default action is to be taken
61 by the system when a signal occurs.
64 in which case its delivery is postponed until it is
66 The action to be taken on delivery is determined at the time
68 Normally, signal handlers execute on the current stack
69 of the process. This may be changed, on a per-handler basis,
70 so that signals are taken on a special
73 Signal routines normally execute with the signal that caused their
76 but other signals may yet occur.
79 defines the set of signals currently blocked from delivery
80 to a process. The signal mask for a process is initialized
81 from that of its parent (normally empty). It
84 call, or when a signal is delivered to the process.
87 condition arises for a process, the signal is added to a set of
88 signals pending for the process.
89 If the signal is not currently
91 by the process then it is delivered to the process.
92 Signals may be delivered any time a process enters the operating system
93 (e.g., during a system call, page fault or trap, or clock interrupt).
94 If multiple signals are ready to be delivered at the same time,
95 any signals that could be caused by traps are delivered first.
96 Additional signals may be processed at the same time, with each
97 appearing to interrupt the handlers for the previous signals
98 before their first instructions.
99 The set of pending signals is returned by the
103 is delivered, the current state of the process is saved,
104 a new signal mask is calculated (as described below),
105 and the signal handler is invoked. The call to the handler
106 is arranged so that if the signal handling routine returns
107 normally the process will resume execution in the context
108 from before the signal's delivery.
109 If the process wishes to resume in a different context, then it
110 must arrange to restore the previous context itself.
112 When a signal is delivered to a process a new signal mask is
113 installed for the duration of the process' signal handler
117 This mask is formed by taking the union of the current signal mask set,
118 the signal to be delivered, and
119 the signal mask associated with the handler to be invoked.
122 assigns an action for a signal specified by
130 or a handler routine) and mask
131 to be used when delivering the specified signal.
134 is non-zero, the previous handling information for the signal
135 is returned to the user.
137 Once a signal handler is installed, it normally remains installed
143 A signal-specific default action may be reset by
148 The defaults are process termination, possibly with core dump;
149 no action; stopping the process; or continuing the process.
150 See the signal list below for each signal's default action.
155 the default action for the signal is to discard the signal,
156 and if a signal is pending,
157 the pending signal is discarded even if the signal is masked.
162 current and pending instances
163 of the signal are ignored and discarded.
165 Options may be specified by setting
167 The meaning of the various bits is as follows:
168 .Bl -tag -offset indent -width SA_RESETHANDXX
170 If this bit is set when installing a catching function
176 signal will be generated only when a child process exits,
177 not when a child process stops.
179 If this bit is set when calling
183 signal, the system will not create zombie processes when children of
184 the calling process exit. If the calling process subsequently issues
187 (or equivalent), it blocks until all of the calling process's child
188 processes terminate, and then returns a value of -1 with errno set to
191 If this bit is set, the system will deliver the signal to the process
197 If this bit is set, further occurrences of the delivered signal are
198 not masked during the execution of the handler.
200 If this bit is set, the handler is reset back to
202 at the moment the signal is delivered.
204 .\" .It Dv SA_SIGINFO
207 If a signal is caught during the system calls listed below,
208 the call may be forced to terminate
211 the call may return with a data transfer shorter than requested,
212 or the call may be restarted.
213 Restart of pending calls is requested
218 The affected system calls include
227 on a communications channel or a slow device (such as a terminal,
228 but not a regular file)
233 However, calls that have already committed are not restarted,
234 but instead return a partial success (for example, a short read count).
240 all signals, the signal mask, the signal stack,
241 and the restart/interrupt flags are inherited by the child.
244 reinstates the default
245 action for all signals which were caught and
246 resets all signals to be caught on the user stack.
247 Ignored signals remain ignored;
248 the signal mask remains the same;
249 signals that restart pending system calls continue to do so.
251 The following is a list of all signals
252 with names as in the include file
254 .Bl -column SIGVTALARMXX "create core imagexxx"
255 .It Sy " NAME " " Default Action " " Description"
256 .It Dv SIGHUP No " terminate process" " terminal line hangup"
257 .It Dv SIGINT No " terminate process" " interrupt program"
258 .It Dv SIGQUIT No " create core image" " quit program"
259 .It Dv SIGILL No " create core image" " illegal instruction"
260 .It Dv SIGTRAP No " create core image" " trace trap"
261 .It Dv SIGABRT No " create core image" Xr abort 3
264 .It Dv SIGEMT No " create core image" " emulate instruction executed"
265 .It Dv SIGFPE No " create core image" " floating-point exception"
266 .It Dv SIGKILL No " terminate process" " kill program"
267 .It Dv SIGBUS No " create core image" " bus error"
268 .It Dv SIGSEGV No " create core image" " segmentation violation"
269 .It Dv SIGSYS No " create core image" " non-existent system call invoked"
270 .It Dv SIGPIPE No " terminate process" " write on a pipe with no reader"
271 .It Dv SIGALRM No " terminate process" " real-time timer expired"
272 .It Dv SIGTERM No " terminate process" " software termination signal"
273 .It Dv SIGURG No " discard signal" " urgent condition present on socket"
274 .It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)"
275 .It Dv SIGTSTP No " stop process" " stop signal generated from keyboard"
276 .It Dv SIGCONT No " discard signal" " continue after stop"
277 .It Dv SIGCHLD No " discard signal" " child status has changed"
278 .It Dv SIGTTIN No " stop process" " background read attempted from control terminal"
279 .It Dv SIGTTOU No " stop process" " background write attempted to control terminal"
280 .It Dv SIGIO No " discard signal" Tn " I/O"
281 is possible on a descriptor (see
283 .It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see"
285 .It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see"
287 .It Dv SIGVTALRM No " terminate process" " virtual time alarm (see"
289 .It Dv SIGPROF No " terminate process" " profiling timer alarm (see"
291 .It Dv SIGWINCH No " discard signal" " Window size change"
292 .It Dv SIGINFO No " discard signal" " status request from keyboard"
293 .It Dv SIGUSR1 No " terminate process" " User defined signal 1"
294 .It Dv SIGUSR2 No " terminate process" " User defined signal 2"
301 is not allowed to block
305 Any attempt to do so will be silently ignored.
307 The following functions are either reentrant or not interruptible
308 by signals and are async-signal safe. Therefore applications may
309 invoke them, without restriction, from signal-catching functions:
395 .Fn timer_getoverrun ,
405 All functions not in the above lists are considered to be unsafe
406 with respect to signals. That is to say, the behaviour of such
407 functions when called from a signal handler is undefined.
409 A 0 value indicated that the call succeeded. A \-1 return value
410 indicates an error occurred and
412 is set to indicated the reason.
414 The handler routine can be declared:
415 .Bd -literal -offset indent
416 void handler(sig, code, scp)
418 struct sigcontext *scp;
423 is the signal number, into which the hardware faults and traps are
426 is a parameter that is either a constant
427 or the code provided by
432 structure (defined in
434 used to restore the context from before the signal.
437 will fail and no new signal handler will be installed if one
438 of the following occurs:
445 points to memory that is not a valid part of the process
449 is not a valid signal number.
451 An attempt is made to ignore or supply a handler for
459 function call is expected to conform to
465 flags are Berkeley extensions,
480 Those signals are available on most
487 flags are intended for backwards compatibility with other operating
494 flags are featuring options commonly found in other operating systems.