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.48 2003/03/24 16:07:19 charnier Exp $
35 .Dd September 18, 2008
40 .Nd software signal facilities
48 union __sigaction_u __sigaction_u; /* signal handler */
49 sigset_t sa_mask; /* signal mask to apply */
50 int sa_flags; /* see signal options below */
54 void (*__sa_handler)(int);
55 void (*__sa_sigaction)(int, struct __siginfo *,
59 #define sa_handler __sigaction_u.__sa_handler
60 #define sa_sigaction __sigaction_u.__sa_sigaction
66 .Fa "const struct sigaction *restrict act"
67 .Fa "struct sigaction *restrict oact"
70 The system defines a set of signals that may be delivered to a process.
71 Signal delivery resembles the occurrence of a hardware interrupt:
72 the signal is normally blocked from further occurrence, the current process
73 context is saved, and a new one is built. A process may specify a
75 to which a signal is delivered, or specify that a signal is to be
77 A process may also specify that a default action is to be taken
78 by the system when a signal occurs.
81 in which case its delivery is postponed until it is
83 The action to be taken on delivery is determined at the time
85 Normally, signal handlers execute on the current stack
86 of the process. This may be changed, on a per-handler basis,
87 so that signals are taken on a special
90 Signal routines normally execute with the signal that caused their
93 but other signals may yet occur.
96 defines the set of signals currently blocked from delivery
97 to a process. The signal mask for a process is initialized
98 from that of its parent (normally empty). It
101 call, or when a signal is delivered to the process.
104 condition arises for a process, the signal is added to a set of
105 signals pending for the process.
106 If the signal is not currently
108 by the process then it is delivered to the process.
109 Signals may be delivered any time a process enters the operating system
110 (e.g., during a system call, page fault or trap, or clock interrupt).
111 If multiple signals are ready to be delivered at the same time,
112 any signals that could be caused by traps are delivered first.
113 Additional signals may be processed at the same time, with each
114 appearing to interrupt the handlers for the previous signals
115 before their first instructions.
116 The set of pending signals is returned by the
120 is delivered, the current state of the process is saved,
121 a new signal mask is calculated (as described below),
122 and the signal handler is invoked. The call to the handler
123 is arranged so that if the signal handling routine returns
124 normally the process will resume execution in the context
125 from before the signal's delivery.
126 If the process wishes to resume in a different context, then it
127 must arrange to restore the previous context itself.
129 When a signal is delivered to a process a new signal mask is
130 installed for the duration of the process' signal handler
133 system call is made).
134 This mask is formed by taking the union of the current signal mask set,
135 the signal to be delivered, and
136 the signal mask associated with the handler to be invoked.
141 assigns an action for a signal specified by
149 or a handler routine) and mask
150 to be used when delivering the specified signal.
153 is non-zero, the previous handling information for the signal
154 is returned to the user.
156 Once a signal handler is installed, it normally remains installed
159 system call is made, or an
162 A signal-specific default action may be reset by
167 The defaults are process termination, possibly with core dump;
168 no action; stopping the process; or continuing the process.
169 See the signal list below for each signal's default action.
174 the default action for the signal is to discard the signal,
175 and if a signal is pending,
176 the pending signal is discarded even if the signal is masked.
181 current and pending instances
182 of the signal are ignored and discarded.
184 Options may be specified by setting
186 The meaning of the various bits is as follows:
187 .Bl -tag -offset indent -width SA_RESETHANDXX
189 If this bit is set when installing a catching function
195 signal will be generated only when a child process exits,
196 not when a child process stops.
198 If this bit is set when calling
202 signal, the system will not create zombie processes when children of
203 the calling process exit. If the calling process subsequently issues
206 (or equivalent), it blocks until all of the calling process's child
207 processes terminate, and then returns a value of -1 with errno set to
210 If this bit is set, the system will deliver the signal to the process
216 If this bit is set, further occurrences of the delivered signal are
217 not masked during the execution of the handler.
219 If this bit is set, the handler is reset back to
221 at the moment the signal is delivered.
225 If this bit is set, the handler function is assumed to be pointed to by the
227 member of struct sigaction and should match the prototype shown above or as
230 This bit should not be set when assigning
236 If a signal is caught during the system calls listed below,
237 the call may be forced to terminate
240 the call may return with a data transfer shorter than requested,
241 or the call may be restarted.
242 Restart of pending calls is requested
247 The affected system calls include
256 on a communications channel or a slow device (such as a terminal,
257 but not a regular file)
262 However, calls that have already committed are not restarted,
263 but instead return a partial success (for example, a short read count).
269 all signals, the signal mask, the signal stack,
270 and the restart/interrupt flags are inherited by the child.
274 system call reinstates the default
275 action for all signals which were caught and
276 resets all signals to be caught on the user stack.
277 Ignored signals remain ignored;
278 the signal mask remains the same;
279 signals that restart pending system calls continue to do so.
281 The following is a list of all signals
282 with names as in the include file
284 .Bl -column SIGVTALARMXX "create core imagexxx"
285 .It Sy "NAME Default Action Description"
286 .It Dv SIGHUP No " terminate process" " terminal line hangup"
287 .It Dv SIGINT No " terminate process" " interrupt program"
288 .It Dv SIGQUIT No " create core image" " quit program"
289 .It Dv SIGILL No " create core image" " illegal instruction"
290 .It Dv SIGTRAP No " create core image" " trace trap"
291 .It Dv SIGABRT No " create core image" Ta Xr abort 3
294 .It Dv SIGEMT No " create core image" " emulate instruction executed"
295 .It Dv SIGFPE No " create core image" " floating-point exception"
296 .It Dv SIGKILL No " terminate process" " kill program"
297 .It Dv SIGBUS No " create core image" " bus error"
298 .It Dv SIGSEGV No " create core image" " segmentation violation"
299 .It Dv SIGSYS No " create core image" " non-existent system call invoked"
300 .It Dv SIGPIPE No " terminate process" " write on a pipe with no reader"
301 .It Dv SIGALRM No " terminate process" " real-time timer expired"
302 .It Dv SIGTERM No " terminate process" " software termination signal"
303 .It Dv SIGURG No " discard signal" " urgent condition present on socket"
304 .It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)"
305 .It Dv SIGTSTP No " stop process" " stop signal generated from keyboard"
306 .It Dv SIGCONT No " discard signal" " continue after stop"
307 .It Dv SIGCHLD No " discard signal" " child status has changed"
308 .It Dv SIGTTIN No " stop process" " background read attempted from control terminal"
309 .It Dv SIGTTOU No " stop process" " background write attempted to control terminal"
310 .It Dv SIGIO No " discard signal" Tn " I/O"
311 is possible on a descriptor (see
313 .It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see"
315 .It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see"
317 .It Dv SIGVTALRM No " terminate process" " virtual time alarm (see"
319 .It Dv SIGPROF No " terminate process" " profiling timer alarm (see"
321 .It Dv SIGWINCH No " discard signal" " Window size change"
322 .It Dv SIGINFO No " discard signal" " status request from keyboard"
323 .It Dv SIGUSR1 No " terminate process" " User defined signal 1"
324 .It Dv SIGUSR2 No " terminate process" " User defined signal 2"
331 is not allowed to block
335 Any attempt to do so will be silently ignored.
337 The following functions are either reentrant or not interruptible
338 by signals and are async-signal safe.
339 Therefore applications may
340 invoke them, without restriction, from signal-catching functions:
436 and perhaps some others.
438 Extension Interfaces:
443 All functions not in the above lists are considered to be unsafe
444 with respect to signals. That is to say, the behaviour of such
445 functions when called from a signal handler is undefined.
446 In general though, signal handlers should do little more than set a
447 flag; most other actions are not safe.
449 Also, it is good practice to make a copy of the global variable
451 and restore it before returning from the signal handler.
452 This protects against the side effect of
454 being set by functions called from inside the signal handler.
458 There are three possible prototypes the handler may match:
459 .Bl -tag -offset indent -width short
463 .It POSIX SA_SIGINFO:
465 .Fn handler int "siginfo_t *info" "ucontext_t *uap" ;
468 The handler function should match the SA_SIGINFO prototype if the
469 SA_SIGINFO bit is set in flags.
470 It then should be pointed to by the
473 .Dv struct sigaction .
474 Note that you should not assign SIG_DFL or SIG_IGN this way.
476 If the SA_SIGINFO flag is not set, the handler function should match
477 either the ANSI C or traditional
479 prototype and be pointed to by
483 .Dv struct sigaction .
486 always sends the three arguments of the latter and since the ANSI C
487 prototype is a subset, both will work.
490 member declaration in
492 include files is that of ANSI C (as required by POSIX),
493 so a function pointer of a
495 function needs to be casted to
496 compile without warning.
499 style is not portable and since its capabilities
500 are a full subset of a SA_SIGINFO handler,
501 its use is deprecated.
505 argument is the signal number, one of the
507 values from <signal.h>.
517 argument to a SA_SIGINFO handler contain a numeric code explaining the
518 cause of the signal, usually one of the
521 <sys/signal.h> or codes specific to a signal, i.e. one of the
527 argument to a POSIX SA_SIGINFO handler points to an instance of
533 will fail and no new signal handler will be installed if one
534 of the following occurs:
542 points to memory that is not a valid part of the process
549 is not a valid signal number.
552 An attempt is made to ignore or supply a handler for
558 An attempt was made to set the action to SIG_DFL
559 for a signal that cannot be caught or ignored (or both).
564 system call is expected to conform to
570 flags are Berkeley extensions,
585 Those signals are available on most
592 flags are intended for backwards compatibility with other operating
599 flags are featuring options commonly found in other operating systems.