2 .\" Copyright (c) 1994,1995 Mike Battersby <mib@deakin.edu.au>
3 .\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" based on work by faith@cs.unc.edu
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified, aeb, 960424
27 .\" Modified Fri Jan 31 17:31:20 1997 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified Thu Nov 26 02:12:45 1998 by aeb - add SIGCHLD stuff.
29 .\" Modified Sat May 8 17:40:19 1999 by Matthew Wilcox
30 .\" add POSIX.1b signals
31 .\" Modified Sat Dec 29 01:44:52 2001 by Evan Jones <ejones@uwaterloo.ca>
33 .\" Modified 2004-11-11 by Michael Kerrisk <mtk.manpages@gmail.com>
34 .\" Added mention of SIGCONT under SA_NOCLDSTOP
35 .\" Added SA_NOCLDWAIT
36 .\" Modified 2004-11-17 by Michael Kerrisk <mtk.manpages@gmail.com>
37 .\" Updated discussion for POSIX.1-2001 and SIGCHLD and sa_flags.
39 .\" 2004-12-09, mtk, added SI_TKILL + other minor changes
40 .\" 2005-09-15, mtk, split sigpending(), sigprocmask(), sigsuspend()
41 .\" out of this page into separate pages.
43 .TH SIGACTION 2 2005-07-08 "Linux" "Linux Programmer's Manual"
45 sigaction \- examine and change a signal action
48 .B #include <signal.h>
50 .BI "int sigaction(int " signum ", const struct sigaction *" act ,
51 .BI " struct sigaction *" oldact );
56 system call is used to change the action taken by a process on
57 receipt of a specific signal.
60 specifies the signal and can be any valid signal except
67 is non\-null, the new action for signal
73 is non\-null, the previous action is saved in
78 structure is defined as something like
83 void (*sa_handler)(int);
84 void (*sa_sigaction)(int, siginfo_t *, void *);
87 void (*sa_restorer)(void);
92 On some architectures a union is involved: do not assign to both
99 element is obsolete and should not be used.
100 POSIX does not specify a
105 specifies the action to be associated with
109 for the default action,
111 to ignore this signal, or a pointer to a signal handling function.
112 This function receives the signal number as its only argument.
122 specifies the signal-handling function for
124 This function receives the signal number as its first argument, a
127 as its second argument and a pointer to a
129 (cast to void *) as its third argument.
132 gives a mask of signals which should be blocked during execution of
134 In addition, the signal which triggered the handler
135 will be blocked, unless the
140 specifies a set of flags which modify the behavior of the signal handling
142 It is formed by the bitwise OR of zero or more of the following:
150 do not receive notification when child processes stop (i.e., when they
152 .BR SIGSTOP ", " SIGTSTP ", " SIGTTIN
155 or resume (i.e., they receive
161 (Linux 2.6 and later)
162 .\" To be precise: Linux 2.5.60 -- MTK
167 do not transform children into zombies when they terminate.
172 Restore the signal action to the default state once the signal handler
175 is an obsolete, non-standard synonym for this flag.
178 Call the signal handler on an alternate signal stack provided by
180 If an alternate stack is not available, the default stack will be used.
183 Provide behavior compatible with BSD signal semantics by making certain
184 system calls restartable across signals.
187 Do not prevent the signal from being received from within its own signal
190 is an obsolete, non-standard synonym for this flag.
193 The signal handler takes 3 arguments, not one.
196 should be set instead of
200 field was added in Linux 2.1.86.)
207 is a struct with the following elements
212 .\" FIXME si_tid and si_overrun are not documented.
213 .\" FIXME si_trapno is not documented; is it actually used?
214 int si_signo; /* Signal number */
215 int si_errno; /* An errno value */
216 int si_code; /* Signal code */
217 pid_t si_pid; /* Sending process ID */
218 uid_t si_uid; /* Real user ID of sending process */
219 int si_status; /* Exit value or signal */
220 clock_t si_utime; /* User time consumed */
221 clock_t si_stime; /* System time consumed */
222 sigval_t si_value; /* Signal value */
223 int si_int; /* POSIX.1b signal */
224 void *si_ptr; /* POSIX.1b signal */
225 void *si_addr; /* Memory location which caused fault */
226 int si_band; /* Band event */
227 int si_fd; /* File descriptor */
232 .IR si_signo ", " si_errno " and " si_code
233 are defined for all signals.
236 The rest of the struct may be a union, so that one should only
237 read the fields that are meaningful for the given signal:
242 .IR si_pid " and " si_uid .
247 .IR si_status ", " si_utime " and " si_stime .
249 .IR si_int " and " si_ptr
250 are specified by the sender of the POSIX.1b signal.
262 with the address of the fault.
265 .IR si_band " and " si_fd .
268 is a value (not a bit mask)
269 indicating why this signal was sent.
270 The following list shows the values can be placed in
272 for any signal, along with reason that the signal was generated.
290 POSIX message queue state changed (since Linux 2.6.6); see
304 .\" SI_DETHREAD is defined in 2.6.9 sources, but isn't implemented
305 .\" It appears to have been an idea that was tried during 2.5.6
306 .\" through to 2.5.24 and then was backed out.
309 The following values can be place in
323 illegal addressing mode
341 The following values can be place in
349 integer divide by zero
355 floating point divide by zero
358 floating point overflow
361 floating point underflow
364 floating point inexact result
367 floating point invalid operation
370 subscript out of range
373 The following values can be place in
381 address not mapped to object
384 invalid permissions for mapped object
387 The following values can be place in
395 invalid address alignment
398 non-existent physical address
401 object specific hardware error
404 The following values can be place in
418 The following values can be place in
432 child terminated abnormally
435 traced child has trapped
441 stopped child has continued (since Linux 2.6.9)
444 The following values can be place in
455 output buffers available
458 input message available
464 high priority input available
471 returns 0 on success and \-1 on error.
475 .IR act " or " oldact
476 points to memory which is not a valid part of the process address space.
479 An invalid signal was specified.
480 This will also be generated if an attempt
481 is made to change the action for
482 .BR SIGKILL " or " SIGSTOP ", "
483 which cannot be caught or ignored.
486 .\" SVr4 does not document the EINTR condition.
489 According to POSIX, the behavior of a process is undefined after it
495 signal that was not generated by
499 Integer division by zero has undefined result.
500 On some architectures it will generate a
503 (Also dividing the most negative integer by \-1 may generate
505 Ignoring this signal might lead to an endless loop.
507 POSIX.1-1990 disallowed setting the action for
511 POSIX.1-2001 allows this possibility, so that ignoring
513 can be used to prevent the creation of zombies (see
515 Nevertheless, the historical BSD and System V behaviors for ignoring
517 differ, so that the only completely portable method of ensuring that
518 terminated children do not become zombies is to catch the
524 POSIX.1-1990 only specified
532 Use of these latter values in
534 may be less portable in applications intended for older
535 Unix implementations.
539 was added in Linux 2.2.
543 flag is compatible with the SVr4 flag of the same name.
547 flag is compatible with the SVr4 flag of the same name under kernels
549 On older kernels the Linux implementation
550 allowed the receipt of any signal, not just the one we are installing
551 (effectively overriding any
556 .\".BR SA_RESETHAND " and " SA_NODEFER
557 .\"names for SVr4 compatibility are present only in library versions 3.0.9
561 can be called with a null second argument to query the current signal
563 It can also be used to check whether a given signal is valid for
564 the current machine by calling it with null second and third arguments.
566 It is not possible to block
567 .BR SIGKILL " or " SIGSTOP
568 (by specifying them in
570 Attempts to do so are silently ignored.
574 for details on manipulating signal sets.
578 for a list of the async-signal-safe functions that can be
579 safely called inside from inside a signal handler.
581 Before the introduction of
583 it was also possible to get some additional information,
586 with second argument of type
587 .IR "struct sigcontext".
588 See the relevant kernel sources for details.
589 This use is obsolete now.
591 In kernels up to and including 2.6.13, specifying
595 prevents not only the delivered signal from being masked during
596 execution of the handler, but also the signals specified in
598 This bug was fixed in kernel 2.6.14.
615 .BR siginterrupt (3),