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
33 .\" $FreeBSD: src/lib/libc/sys/sigaction.2,v 1.22.2.10 2002/12/29 16:35:34 schweikh Exp $
34 .\" $DragonFly: src/lib/libc/sys/sigaction.2,v 1.10 2008/05/10 20:39:51 swildner Exp $
41 .Nd software signal facilities
49 * Signal handler function if flag SA_SIGINFO is not used and for
50 * SIG_DFL and SIG_IGN.
52 void (*sa_handler)(int);
54 /* Signal handler function if flag SA_SIGINFO is used */
55 void (*sa_sigaction)(int, siginfo_t *, void *);
57 sigset_t sa_mask; /* signal mask to apply */
58 int sa_flags; /* see signal options below */
62 .Fn sigaction "int sig" "const struct sigaction *act" "struct sigaction *oact"
64 The system defines a set of signals that may be delivered to a process.
65 Signal delivery resembles the occurrence of a hardware interrupt:
66 the signal is normally blocked from further occurrence, the current process
67 context is saved, and a new one is built.
68 A process may specify a
70 to which a signal is delivered, or specify that a signal is to be
72 A process may also specify that a default action is to be taken
73 by the system when a signal occurs.
76 in which case its delivery is postponed until it is
78 The action to be taken on delivery is determined at the time
80 Normally, signal handlers execute on the current stack
82 This may be changed, on a per-handler basis,
83 so that signals are taken on a special
86 Signal routines normally execute with the signal that caused their
89 but other signals may yet occur.
92 defines the set of signals currently blocked from delivery
94 The signal mask for a process is initialized
95 from that of its parent (normally empty).
96 It may be changed with a
98 call, or when a signal is delivered to the process.
101 condition arises for a process, the signal is added to a set of
102 signals pending for the process.
103 If the signal is not currently
105 by the process then it is delivered to the process.
106 Signals may be delivered any time a process enters the operating system
107 (e.g., during a system call, page fault or trap, or clock interrupt).
108 If multiple signals are ready to be delivered at the same time,
109 any signals that could be caused by traps are delivered first.
110 Additional signals may be processed at the same time, with each
111 appearing to interrupt the handlers for the previous signals
112 before their first instructions.
113 The set of pending signals is returned by the
117 is delivered, the current state of the process is saved,
118 a new signal mask is calculated (as described below),
119 and the signal handler is invoked.
120 The call to the handler
121 is arranged so that if the signal handling routine returns
122 normally the process will resume execution in the context
123 from before the signal's delivery.
124 If the process wishes to resume in a different context, then it
125 must arrange to restore the previous context itself.
127 When a signal is delivered to a process a new signal mask is
128 installed for the duration of the process' signal handler
132 This mask is formed by taking the union of the current signal mask set,
133 the signal to be delivered, and
134 the signal mask associated with the handler to be invoked.
137 assigns an action for a signal specified by
145 or a handler routine) and mask
146 to be used when delivering the specified signal.
149 is non-zero, the previous handling information for the signal
150 is returned to the user.
152 Once a signal handler is installed, it normally remains installed
158 A signal-specific default action may be reset by
163 The defaults are process termination, possibly with core dump;
164 no action; stopping the process; or continuing the process.
165 See the signal list below for each signal's default action.
170 the default action for the signal is to discard the signal,
171 and if a signal is pending,
172 the pending signal is discarded even if the signal is masked.
177 current and pending instances
178 of the signal are ignored and discarded.
180 Options may be specified by setting
182 The meaning of the various bits is as follows:
183 .Bl -tag -offset indent -width SA_RESETHANDXX
185 If this bit is set when installing a catching function
191 signal will be generated only when a child process exits,
192 not when a child process stops.
194 If this bit is set when calling
198 signal, the system will not create zombie processes when children of
199 the calling process exit.
200 If the calling process subsequently issues a
202 (or equivalent), it blocks until all of the calling process's child
203 processes terminate, and then returns a value of -1 with
208 If this bit is set, the system will deliver the signal to the process
214 If this bit is set, further occurrences of the delivered signal are
215 not masked during the execution of the handler.
217 If this bit is set, the handler is reset back to
219 at the moment the signal is delivered.
221 If this bit is set, the handler function is assumed to be pointed to by the
223 member of struct sigaction and should match the prototype shown above or as
226 This bit should not be set when assigning
232 If a signal is caught during the system calls listed below,
233 the call may be forced to terminate
236 the call may return with a data transfer shorter than requested,
237 or the call may be restarted.
238 Restart of pending calls is requested
243 The affected system calls include
252 on a communications channel or a slow device (such as a terminal,
253 but not a regular file)
258 However, calls that have already committed are not restarted,
259 but instead return a partial success (for example, a short read count).
265 all signals, the signal mask, the signal stack,
266 and the restart/interrupt flags are inherited by the child.
269 reinstates the default
270 action for all signals which were caught and
271 resets all signals to be caught on the user stack.
272 Ignored signals remain ignored;
273 the signal mask remains the same;
274 signals that restart pending system calls continue to do so.
276 The following is a list of all signals
277 with names as in the include file
279 .Bl -column SIGVTALARMXX "create core imagexxx"
280 .It Sy "NAME Default Action Description"
281 .It Dv SIGHUP No " terminate process" " terminal line hangup"
282 .It Dv SIGINT No " terminate process" " interrupt program"
283 .It Dv SIGQUIT No " create core image" " quit program"
284 .It Dv SIGILL No " create core image" " illegal instruction"
285 .It Dv SIGTRAP No " create core image" " trace trap"
286 .It Dv SIGABRT No " create core image" Ta Xr abort 3
289 .It Dv SIGEMT No " create core image" " emulate instruction executed"
290 .It Dv SIGFPE No " create core image" " floating-point exception"
291 .It Dv SIGKILL No " terminate process" " kill program"
292 .It Dv SIGBUS No " create core image" " bus error"
293 .It Dv SIGSEGV No " create core image" " segmentation violation"
294 .It Dv SIGSYS No " create core image" " non-existent system call invoked"
295 .It Dv SIGPIPE No " terminate process" " write on a pipe with no reader"
296 .It Dv SIGALRM No " terminate process" " real-time timer expired"
297 .It Dv SIGTERM No " terminate process" " software termination signal"
298 .It Dv SIGURG No " discard signal" " urgent condition present on socket"
299 .It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)"
300 .It Dv SIGTSTP No " stop process" " stop signal generated from keyboard"
301 .It Dv SIGCONT No " discard signal" " continue after stop"
302 .It Dv SIGCHLD No " discard signal" " child status has changed"
303 .It Dv SIGTTIN No " stop process" " background read attempted from control terminal"
304 .It Dv SIGTTOU No " stop process" " background write attempted to control terminal"
305 .It Dv SIGIO No " discard signal" Tn " I/O"
306 is possible on a descriptor (see
308 .It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see"
310 .It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see"
312 .It Dv SIGVTALRM No " terminate process" " virtual time alarm (see"
314 .It Dv SIGPROF No " terminate process" " profiling timer alarm (see"
316 .It Dv SIGWINCH No " discard signal" " Window size change"
317 .It Dv SIGINFO No " discard signal" " status request from keyboard"
318 .It Dv SIGUSR1 No " terminate process" " User defined signal 1"
319 .It Dv SIGUSR2 No " terminate process" " User defined signal 2"
326 is not allowed to block
330 Any attempt to do so will be silently ignored.
332 The following functions are either reentrant or not interruptible
333 by signals and are async-signal safe.
334 Therefore applications may
335 invoke them, without restriction, from signal-catching functions:
421 .\".Fn timer_getoverrun ,
425 .\".Fn timer_gettime ,
429 .\".Fn timer_settime .
431 All functions not in the above lists are considered to be unsafe
432 with respect to signals.
433 That is to say, the behaviour of such
434 functions when called from a signal handler is undefined.
438 There are three possible prototypes the handler may match:
439 .Bl -tag -offset indent -width short
443 .It Traditional BSD style:
445 .Fn handler int "int code" "struct sigcontext *scp" ;
446 .It POSIX SA_SIGINFO:
448 .Fn handler int "siginfo_t *info" "ucontext_t *uap" ;
451 The handler function should match the
456 It then should be pointed to by the
459 .Dv struct sigaction .
460 Note that you should not assign
468 flag is not set, the handler function should match
469 either the ANSI C or traditional
471 prototype and be pointed to by
475 .Dv struct sigaction .
478 always sends the three arguments of the latter and since the ANSI C
479 prototype is a subset, both will work.
482 member declaration in
484 include files is that of ANSI C (as required by POSIX),
485 so a function pointer of a
487 function needs to be casted to
488 compile without warning.
491 style is not portable and since its capabilities are a full subset of a
493 handler, its use is deprecated.
497 argument is the signal number, one of the
511 handler contain a numeric code explaining the
512 cause of the signal, usually one of the
516 or codes specific to a signal, i.e.\& one of the
525 handler points to an instance of struct
532 handler points to an instance of ucontext_t.
535 will fail and no new signal handler will be installed if one
536 of the following occurs:
543 points to memory that is not a valid part of the process
547 is not a valid signal number.
549 An attempt is made to ignore or supply a handler for
576 function call is expected to conform to
582 flags are Berkeley extensions,
597 Those signals are available on most
604 flags are intended for backwards compatibility with other operating
612 flags are featuring options commonly found in other operating systems.