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. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" From: @(#)sigaction.2 8.2 (Berkeley) 4/3/94
29 .\" $FreeBSD: src/lib/libc/sys/sigaction.2,v 1.22.2.10 2002/12/29 16:35:34 schweikh Exp $
36 .Nd software signal facilities
44 * Signal handler function if flag SA_SIGINFO is not used and for
45 * SIG_DFL and SIG_IGN.
47 void (*sa_handler)(int);
49 /* Signal handler function if flag SA_SIGINFO is used */
50 void (*sa_sigaction)(int, siginfo_t *, void *);
52 sigset_t sa_mask; /* signal mask to apply */
53 int sa_flags; /* see signal options below */
57 .Fn sigaction "int sig" "const struct sigaction *act" "struct sigaction *oact"
59 The system defines a set of signals that may be delivered to a process.
60 Signal delivery resembles the occurrence of a hardware interrupt:
61 the signal is normally blocked from further occurrence, the current process
62 context is saved, and a new one is built.
63 A process may specify a
65 to which a signal is delivered, or specify that a signal is to be
67 A process may also specify that a default action is to be taken
68 by the system when a signal occurs.
71 in which case its delivery is postponed until it is
73 The action to be taken on delivery is determined at the time
75 Normally, signal handlers execute on the current stack
77 This may be changed, on a per-handler basis,
78 so that signals are taken on a special
81 Signal routines normally execute with the signal that caused their
84 but other signals may yet occur.
87 defines the set of signals currently blocked from delivery
89 The signal mask for a process is initialized
90 from that of its parent (normally empty).
91 It may be changed with a
93 call, or when a signal is delivered to the process.
96 condition arises for a process, the signal is added to a set of
97 signals pending for the process.
98 If the signal is not currently
100 by the process then it is delivered to the process.
101 Signals may be delivered any time a process enters the operating system
102 (e.g., during a system call, page fault or trap, or clock interrupt).
103 If multiple signals are ready to be delivered at the same time,
104 any signals that could be caused by traps are delivered first.
105 Additional signals may be processed at the same time, with each
106 appearing to interrupt the handlers for the previous signals
107 before their first instructions.
108 The set of pending signals is returned by the
112 is delivered, the current state of the process is saved,
113 a new signal mask is calculated (as described below),
114 and the signal handler is invoked.
115 The call to the handler
116 is arranged so that if the signal handling routine returns
117 normally the process will resume execution in the context
118 from before the signal's delivery.
119 If the process wishes to resume in a different context, then it
120 must arrange to restore the previous context itself.
122 When a signal is delivered to a process a new signal mask is
123 installed for the duration of the process' signal handler
127 This mask is formed by taking the union of the current signal mask set,
128 the signal to be delivered, and
129 the signal mask associated with the handler to be invoked.
132 assigns an action for a signal specified by
140 or a handler routine) and mask
141 to be used when delivering the specified signal.
144 is non-zero, the previous handling information for the signal
145 is returned to the user.
147 Once a signal handler is installed, it normally remains installed
153 A signal-specific default action may be reset by
158 The defaults are process termination, possibly with core dump;
159 no action; stopping the process; or continuing the process.
160 See the signal list below for each signal's default action.
165 the default action for the signal is to discard the signal,
166 and if a signal is pending,
167 the pending signal is discarded even if the signal is masked.
172 current and pending instances
173 of the signal are ignored and discarded.
175 Options may be specified by setting
177 The meaning of the various bits is as follows:
178 .Bl -tag -offset indent -width SA_RESETHANDXX
180 If this bit is set when installing a catching function
186 signal will be generated only when a child process exits,
187 not when a child process stops.
189 If this bit is set when calling
193 signal, the system will not create zombie processes when children of
194 the calling process exit.
195 If the calling process subsequently issues a
197 (or equivalent), it blocks until all of the calling process's child
198 processes terminate, and then returns a value of -1 with
203 If this bit is set, the system will deliver the signal to the process
209 If this bit is set, further occurrences of the delivered signal are
210 not masked during the execution of the handler.
212 If this bit is set, the handler is reset back to
214 at the moment the signal is delivered.
216 If this bit is set, the handler function is assumed to be pointed to by the
218 member of struct sigaction and should match the prototype shown above or as
221 This bit should not be set when assigning
227 If a signal is caught during the system calls listed below,
228 the call may be forced to terminate
231 the call may return with a data transfer shorter than requested,
232 or the call may be restarted.
233 Restart of pending calls is requested
238 The affected system calls include
247 on a communications channel or a slow device (such as a terminal,
248 but not a regular file)
253 However, calls that have already committed are not restarted,
254 but instead return a partial success (for example, a short read count).
260 all signals, the signal mask, the signal stack,
261 and the restart/interrupt flags are inherited by the child.
264 reinstates the default
265 action for all signals which were caught and
266 resets all signals to be caught on the user stack.
267 Ignored signals remain ignored;
268 the signal mask remains the same;
269 signals that restart pending system calls continue to do so.
271 The following is a list of all signals
272 with names as in the include file
274 .Bl -column SIGVTALARMXX "create core imagexxx"
275 .It Sy "NAME Default Action Description"
276 .It Dv SIGHUP No " terminate process" " terminal line hangup"
277 .It Dv SIGINT No " terminate process" " interrupt program"
278 .It Dv SIGQUIT No " create core image" " quit program"
279 .It Dv SIGILL No " create core image" " illegal instruction"
280 .It Dv SIGTRAP No " create core image" " trace trap"
281 .It Dv SIGABRT No " create core image" Ta Xr abort 3
284 .It Dv SIGEMT No " create core image" " emulate instruction executed"
285 .It Dv SIGFPE No " create core image" " floating-point exception"
286 .It Dv SIGKILL No " terminate process" " kill program"
287 .It Dv SIGBUS No " create core image" " bus error"
288 .It Dv SIGSEGV No " create core image" " segmentation violation"
289 .It Dv SIGSYS No " create core image" " non-existent system call invoked"
290 .It Dv SIGPIPE No " terminate process" " write on a pipe with no reader"
291 .It Dv SIGALRM No " terminate process" " real-time timer expired"
292 .It Dv SIGTERM No " terminate process" " software termination signal"
293 .It Dv SIGURG No " discard signal" " urgent condition present on socket"
294 .It Dv SIGSTOP No " stop process" " stop (cannot be caught or ignored)"
295 .It Dv SIGTSTP No " stop process" " stop signal generated from keyboard"
296 .It Dv SIGCONT No " discard signal" " continue after stop"
297 .It Dv SIGCHLD No " discard signal" " child status has changed"
298 .It Dv SIGTTIN No " stop process" " background read attempted from control terminal"
299 .It Dv SIGTTOU No " stop process" " background write attempted to control terminal"
300 .It Dv SIGIO No " discard signal" Tn " I/O"
301 is possible on a descriptor (see
303 .It Dv SIGXCPU No " terminate process" " cpu time limit exceeded (see"
305 .It Dv SIGXFSZ No " terminate process" " file size limit exceeded (see"
307 .It Dv SIGVTALRM No " terminate process" " virtual time alarm (see"
309 .It Dv SIGPROF No " terminate process" " profiling timer alarm (see"
311 .It Dv SIGWINCH No " discard signal" " Window size change"
312 .It Dv SIGINFO No " discard signal" " status request from keyboard"
313 .It Dv SIGUSR1 No " terminate process" " User defined signal 1"
314 .It Dv SIGUSR2 No " terminate process" " User defined signal 2"
321 is not allowed to block
325 Any attempt to do so will be silently ignored.
327 The following functions are either reentrant or not interruptible
328 by signals and are async-signal safe.
329 Therefore applications may
330 invoke them, without restriction, from signal-catching functions:
416 .\".Fn timer_getoverrun ,
420 .\".Fn timer_gettime ,
424 .\".Fn timer_settime .
426 All functions not in the above lists are considered to be unsafe
427 with respect to signals.
428 That is to say, the behaviour of such
429 functions when called from a signal handler is undefined.
433 There are three possible prototypes the handler may match:
434 .Bl -tag -offset indent -width short
438 .It Traditional BSD style:
440 .Fn handler int "int code" "struct sigcontext *scp" ;
441 .It POSIX SA_SIGINFO:
443 .Fn handler int "siginfo_t *info" "ucontext_t *uap" ;
446 The handler function should match the
451 It then should be pointed to by the
454 .Dv struct sigaction .
455 Note that you should not assign
463 flag is not set, the handler function should match
464 either the ANSI C or traditional
466 prototype and be pointed to by
470 .Dv struct sigaction .
473 always sends the three arguments of the latter and since the ANSI C
474 prototype is a subset, both will work.
477 member declaration in
479 include files is that of ANSI C (as required by POSIX),
480 so a function pointer of a
482 function needs to be casted to
483 compile without warning.
486 style is not portable and since its capabilities are a full subset of a
488 handler, its use is deprecated.
492 argument is the signal number, one of the
506 handler contain a numeric code explaining the
507 cause of the signal, usually one of the
511 or codes specific to a signal, i.e.\& one of the
520 handler points to an instance of struct
527 handler points to an instance of ucontext_t.
530 will fail and no new signal handler will be installed if one
531 of the following occurs:
538 points to memory that is not a valid part of the process
542 is not a valid signal number.
544 An attempt is made to ignore or supply a handler for
567 function call is expected to conform to
573 flags are Berkeley extensions,
588 Those signals are available on most
595 flags are intended for backwards compatibility with other operating
603 flags are featuring options commonly found in other operating systems.