1 .\" $NetBSD: sigaction.2,v 1.43 2006/06/03 18:23:52 christos Exp $
3 .\" Copyright (c) 1980, 1990, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)sigaction.2 8.2 (Berkeley) 4/3/94
37 .Nd software signal facilities
43 .Fn sigaction "int sig" "const struct sigaction * restrict act" "struct sigaction * restrict oact"
45 The system defines a set of signals that may be delivered to a process.
46 Signal delivery resembles the occurrence of a hardware interrupt:
47 the signal is blocked from further occurrence, the current process
48 context is saved, and a new one is built.
49 A process may specify a
51 to which a signal is delivered, or specify that a signal is to be
53 A process may also specify that a default action is to be taken
54 by the system when a signal occurs.
57 in which case its delivery is postponed until it is
59 The action to be taken on delivery is determined at the time of delivery.
60 Normally, signal handlers execute on the current stack of the process.
61 This may be changed, on a per-handler basis, so that signals are
65 Signal routines execute with the signal that caused their
68 but other signals may yet occur.
71 defines the set of signals currently blocked from delivery
73 The signal mask for a process is initialized from that of its parent
75 It may be changed with a
77 call, or when a signal is delivered to the process.
78 Signal masks are represented using the
82 interface is used to modify such data.
85 condition arises for a process, the signal is added to a set of
86 signals pending for the process.
87 If the signal is not currently
89 by the process then it is delivered to the process.
90 Signals may be delivered any time a process enters the operating system
91 (e.g., during a system call, page fault or trap, or clock interrupt).
92 If multiple signals are ready to be delivered at the same time,
93 any signals that could be caused by traps are delivered first.
94 Additional signals may be processed at the same time, with each
95 appearing to interrupt the handlers for the previous signals
96 before their first instructions.
97 The set of pending signals is returned by the
101 is delivered, the current state of the process is saved,
102 a new signal mask is calculated (as described below),
103 and the signal handler is invoked.
104 The call to the handler is arranged so that if the signal handling
105 routine returns normally the process will resume execution in the
106 context from before the signal's delivery.
107 If the process wishes to resume in a different context, then it
108 must arrange to restore the previous context itself.
110 .Em "struct sigaction"
111 includes the following members:
112 .Bd -literal -offset indent
113 void (*sa_sigaction)(int sig, siginfo_t *info, void *ctx);
114 void (*sa_handler)(int sig);
119 When a signal is delivered to a process a new signal mask is
120 installed for the duration of the process' signal handler
124 This mask is formed by taking the union of the current signal mask,
125 the signal to be delivered, and
126 the signal mask associated with the handler to be invoked,
130 assigns an action for a specific signal.
137 or a handler routine) and mask
138 to be used when delivering the specified signal.
141 is non-zero, the previous handling information for the signal
142 is returned to the user.
144 Once a signal handler is installed, it remains installed
150 A signal-specific default action may be reset by
155 The defaults are process termination, possibly with core dump;
156 no action; stopping the process; or continuing the process.
157 See the signal list below for each signal's default action.
162 the default action for the signal is to discard the signal,
163 and if a signal is pending,
164 the pending signal is discarded even if the signal is masked.
169 current and pending instances
170 of the signal are ignored and discarded.
172 Options may be specified by setting
174 .Bl -tag -width SA_NOKERNINFO
176 If set, then the signal that caused the handler to be executed is not added
177 to the list of block signals.
180 takes precedence over
182 so that if the specified signal is blocked in
188 If set when installing a catching function
194 signal will be generated only when a child process exits,
195 not when a child process stops.
197 If set, the system will not create a zombie when the child exits,
198 but the child process will be automatically waited for.
199 The same effect can be achieved by setting the signal handler for
204 If set, the system will deliver the signal to the process on a
209 If set, the default action will be reinstated when the signal
212 Normally, if a signal is caught during the system calls listed below,
213 the call may be forced to terminate
216 the call may return with a data transfer shorter than requested,
217 or the call may be restarted.
218 Restarting of pending calls is requested
223 The affected system calls include
232 on a communications channel or a slow device (such as a terminal,
233 but not a regular file)
238 However, calls that have already committed are not restarted,
239 but instead return a partial success (for example, a short read count).
245 all signals, the signal mask, the signal stack,
246 and the restart/interrupt flags are inherited by the child.
250 system call reinstates the default
251 action for all signals which were caught and
252 resets all signals to be caught on the user stack.
253 Ignored signals remain ignored;
254 the signal mask remains the same;
255 signals that restart pending system calls continue to do so.
259 for comprehensive list of supported signals.
261 If set, the signal handler function will receive additional information
262 about the caught signal.
263 An alternative handler that gets passed additional arguments will
264 be called which is named
268 argument of this handler contains the signal number that was caught.
271 argument contains additional signal specific information which
279 context where the signal handler will return to.
281 This flag is relevant only to
283 and turns off printing kernel messages on the tty.
290 Only functions that are async-signal-safe can safely be used in signal
295 The mask specified in
297 is not allowed to block
301 This is enforced silently by the system.
303 A 0 value indicates that the call succeeded.
304 A \-1 return value indicates an error occurred and
306 is set to indicate the reason.
309 will fail and no new signal handler will be installed if one
310 of the following occurs:
317 points to memory that is not a valid part of the process
321 is not a valid signal number.
323 An attempt is made to ignore or supply a handler for
330 word contains bits other than
361 flags are Berkeley extensions, available on most