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 .\" %%%LICENSE_START(VERBATIM)
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date. The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein. The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
28 .\" Modified, aeb, 960424
29 .\" Modified Fri Jan 31 17:31:20 1997 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified Thu Nov 26 02:12:45 1998 by aeb - add SIGCHLD stuff.
31 .\" Modified Sat May 8 17:40:19 1999 by Matthew Wilcox
32 .\" add POSIX.1b signals
33 .\" Modified Sat Dec 29 01:44:52 2001 by Evan Jones <ejones@uwaterloo.ca>
35 .\" Modified 2004-11-11 by Michael Kerrisk <mtk.manpages@gmail.com>
36 .\" Added mention of SIGCONT under SA_NOCLDSTOP
37 .\" Added SA_NOCLDWAIT
38 .\" Modified 2004-11-17 by Michael Kerrisk <mtk.manpages@gmail.com>
39 .\" Updated discussion for POSIX.1-2001 and SIGCHLD and sa_flags.
41 .\" 2004-12-09, mtk, added SI_TKILL + other minor changes
42 .\" 2005-09-15, mtk, split sigpending(), sigprocmask(), sigsuspend()
43 .\" out of this page into separate pages.
44 .\" 2010-06-11 Andi Kleen, add hwpoison signal extensions
45 .\" 2010-06-11 mtk, improvements to discussion of various siginfo_t fields.
47 .TH SIGACTION 2 2014-12-31 "Linux" "Linux Programmer's Manual"
49 sigaction \- examine and change a signal action
52 .B #include <signal.h>
54 .BI "int sigaction(int " signum ", const struct sigaction *" act ,
55 .BI " struct sigaction *" oldact );
59 Feature Test Macro Requirements for glibc (see
60 .BR feature_test_macros (7)):
65 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
68 _POSIX_C_SOURCE >= 199309L
73 system call is used to change the action taken by a process on
74 receipt of a specific signal.
77 for an overview of signals.)
80 specifies the signal and can be any valid signal except
87 is non-NULL, the new action for signal
93 is non-NULL, the previous action is saved in
98 structure is defined as something like:
103 void (*sa_handler)(int);
104 void (*sa_sigaction)(int, siginfo_t *, void *);
107 void (*sa_restorer)(void);
112 On some architectures a union is involved: do not assign to both
119 field is not intended for application use.
120 (POSIX does not specify a
123 Some further details of purpose of this field can be found in
127 specifies the action to be associated with
131 for the default action,
133 to ignore this signal, or a pointer to a signal handling function.
134 This function receives the signal number as its only argument.
144 specifies the signal-handling function for
146 This function receives the signal number as its first argument, a
149 as its second argument and a pointer to a
151 (cast to \fIvoid\ *\fP) as its third argument.
152 (Commonly, the handler function doesn't make any use of the third argument.
155 for further information about
159 specifies a mask of signals which should be blocked
160 (i.e., added to the signal mask of the thread in which
161 the signal handler is invoked)
162 during execution of the signal handler.
163 In addition, the signal which triggered the handler
164 will be blocked, unless the
169 specifies a set of flags which modify the behavior of the signal.
170 It is formed by the bitwise OR of zero or more of the following:
178 do not receive notification when child processes stop (i.e., when they
180 .BR SIGSTOP ", " SIGTSTP ", " SIGTTIN ", "
183 or resume (i.e., they receive
187 This flag is meaningful only when establishing a handler for
190 .BR SA_NOCLDWAIT " (since Linux 2.6)"
191 .\" To be precise: Linux 2.5.60 -- MTK
196 do not transform children into zombies when they terminate.
199 This flag is meaningful only when establishing a handler for
201 or when setting that signal's disposition to
206 flag is set when establishing a handler for
208 POSIX.1 leaves it unspecified whether a
210 signal is generated when a child process terminates.
213 signal is generated in this case;
214 on some other implementations, it is not.
217 Do not prevent the signal from being received from within its own signal
219 This flag is meaningful only when establishing a signal handler.
221 is an obsolete, nonstandard synonym for this flag.
224 Call the signal handler on an alternate signal stack provided by
226 If an alternate stack is not available, the default stack will be used.
227 This flag is meaningful only when establishing a signal handler.
230 Restore the signal action to the default upon entry to the signal handler.
231 This flag is meaningful only when establishing a signal handler.
233 is an obsolete, nonstandard synonym for this flag.
236 Provide behavior compatible with BSD signal semantics by making certain
237 system calls restartable across signals.
238 This flag is meaningful only when establishing a signal handler.
241 for a discussion of system call restarting.
244 .IR "Not intended for application use" .
245 This flag is used by C libraries to indicate that the
247 field contains the address of a "signal trampoline".
252 .BR SA_SIGINFO " (since Linux 2.2)"
253 The signal handler takes three arguments, not one.
256 should be set instead of
258 This flag is meaningful only when establishing a signal handler.
261 .\" field was added in Linux 2.1.86.)
268 is a struct with the following fields:
273 int si_signo; /* Signal number */
274 int si_errno; /* An errno value */
275 int si_code; /* Signal code */
276 int si_trapno; /* Trap number that caused
277 hardware-generated signal
278 (unused on most architectures) */
280 .\" The siginfo_t 'si_trapno' field seems to be used only on SPARC and Alpha;
281 .\" this page could use a little more detail on its purpose there.
282 pid_t si_pid; /* Sending process ID */
283 uid_t si_uid; /* Real user ID of sending process */
284 int si_status; /* Exit value or signal */
285 clock_t si_utime; /* User time consumed */
286 clock_t si_stime; /* System time consumed */
287 sigval_t si_value; /* Signal value */
288 int si_int; /* POSIX.1b signal */
289 void *si_ptr; /* POSIX.1b signal */
290 int si_overrun; /* Timer overrun count; POSIX.1b timers */
291 int si_timerid; /* Timer ID; POSIX.1b timers */
292 .\" In the kernel: si_tid
293 void *si_addr; /* Memory location which caused fault */
294 long si_band; /* Band event (was \fIint\fP in
295 glibc 2.3.2 and earlier) */
296 int si_fd; /* File descriptor */
297 short si_addr_lsb; /* Least significant bit of address
298 (since Linux 2.6.32) */
303 .IR si_signo ", " si_errno " and " si_code
304 are defined for all signals.
306 is generally unused on Linux.)
307 The rest of the struct may be a union, so that one should
308 read only the fields that are meaningful for the given signal:
315 .IR si_pid " and " si_uid .
316 In addition, signals sent with
319 .IR si_int " and " si_ptr
320 with the values specified by the sender of the signal;
325 Signals sent by POSIX.1b timers (since Linux 2.6) fill in
331 field is an internal ID used by the kernel to identify
332 the timer; it is not the same as the timer ID returned by
333 .BR timer_create (2).
336 field is the timer overrun count;
337 this is the same information as is obtained by a call to
338 .BR timer_getoverrun (2).
339 These fields are nonstandard Linux extensions.
341 Signals sent for message queue notification (see the description of
346 .IR si_int / si_ptr ,
352 with the process ID of the message sender; and
354 with the real user ID of the message sender.
358 .IR si_pid ", " si_uid ", " si_status ", " si_utime ", and " si_stime ,
359 providing information about the child.
362 field is the process ID of the child;
364 is the child's real user ID.
367 field contains the exit status of the child (if
371 or the signal number that caused the process to change state.
376 contain the user and system CPU time used by the child process;
377 these fields do not include the times used by waited-for children (unlike
381 In kernels up to 2.6, and since 2.6.27, these fields report
383 .IR sysconf(_SC_CLK_TCK) .
384 In 2.6 kernels before 2.6.27,
385 a bug meant that these fields reported time in units
386 of the (configurable) system jiffy (see
389 .\" When si_utime and si_stime where originally implemented, the
390 .\" measurement unit was HZ, which was the same as clock ticks
391 .\" (sysconf(_SC_CLK_TCK)). In 2.6, HZ became configurable, and
392 .\" was *still* used as the unit to return the info these fields,
393 .\" with the result that the field values depended on the the
394 .\" configured HZ. Of course, the should have been measured in
395 .\" USER_HZ instead, so that sysconf(_SC_CLK_TCK) could be used to
396 .\" convert to seconds. I have a queued patch to fix this:
397 .\" http://thread.gmane.org/gmane.linux.kernel/698061/ .
398 .\" This patch made it into 2.6.27.
399 .\" But note that these fields still don't return the times of
400 .\" waited-for children (as is done by getrusage() and times()
401 .\" and wait4()). Solaris 8 does include child times.
411 with the address of the fault.
412 .\" FIXME . SIGTRAP also sets the following for ptrace_notify() ?
413 .\" info.si_code = exit_code;
414 .\" info.si_pid = task_pid_vnr(current);
415 .\" info.si_uid = current_uid(); /* Real UID */
416 On some architectures,
417 these signals also fill in the
428 This field indicates the least significant bit of the reported address
429 and therefore the extent of the corruption.
430 For example, if a full page was corrupted,
433 .IR log2(sysconf(_SC_PAGESIZE)) .
437 are Linux-specific extensions.
440 (the two names are synonyms on Linux)
442 .IR si_band " and " si_fd .
445 event is a bit mask containing the same values as are filled in the
451 field indicates the file descriptor for which the I/O event occurred.
454 is a value (not a bit mask)
455 indicating why this signal was sent.
456 The following list shows the values which can be placed in
458 for any signal, along with reason that the signal was generated.
474 POSIX message queue state changed (since Linux 2.6.6); see
483 (only in kernels up to Linux 2.2; from Linux 2.4 onward
494 .\" SI_DETHREAD is defined in 2.6.9 sources, but isn't implemented
495 .\" It appears to have been an idea that was tried during 2.5.6
496 .\" through to 2.5.24 and then was backed out.
499 The following values can be placed in
513 illegal addressing mode
531 The following values can be placed in
539 integer divide by zero
545 floating-point divide by zero
548 floating-point overflow
551 floating-point underflow
554 floating-point inexact result
557 floating-point invalid operation
560 subscript out of range
563 The following values can be placed in
571 address not mapped to object
574 invalid permissions for mapped object
577 The following values can be placed in
585 invalid address alignment
588 nonexistent physical address
591 object-specific hardware error
593 .BR BUS_MCEERR_AR " (since Linux 2.6.32)"
594 Hardware memory error consumed on a machine check; action required.
596 .BR BUS_MCEERR_AO " (since Linux 2.6.32)"
597 Hardware memory error detected in process but not consumed; action optional.
600 The following values can be placed in
613 .BR TRAP_BRANCH " (since Linux 2.4)"
614 process taken branch trap
616 .BR TRAP_HWBKPT " (since Linux 2.4)"
617 hardware breakpoint/watchpoint
620 The following values can be placed in
634 child terminated abnormally
637 traced child has trapped
643 stopped child has continued (since Linux 2.6.9)
646 The following values can be placed in
657 output buffers available
660 input message available
666 high priority input available
673 returns 0 on success; on error, \-1 is returned, and
675 is set to indicate the error.
679 .IR act " or " oldact
680 points to memory which is not a valid part of the process address space.
683 An invalid signal was specified.
684 This will also be generated if an attempt
685 is made to change the action for
686 .BR SIGKILL " or " SIGSTOP ", "
687 which cannot be caught or ignored.
690 .\" SVr4 does not document the EINTR condition.
694 inherits a copy of its parent's signal dispositions.
697 the dispositions of handled signals are reset to the default;
698 the dispositions of ignored signals are left unchanged.
700 According to POSIX, the behavior of a process is undefined after it
706 signal that was not generated by
710 Integer division by zero has undefined result.
711 On some architectures it will generate a
714 (Also dividing the most negative integer by \-1 may generate
716 Ignoring this signal might lead to an endless loop.
718 POSIX.1-1990 disallowed setting the action for
722 POSIX.1-2001 allows this possibility, so that ignoring
724 can be used to prevent the creation of zombies (see
726 Nevertheless, the historical BSD and System\ V behaviors for ignoring
728 differ, so that the only completely portable method of ensuring that
729 terminated children do not become zombies is to catch the
735 POSIX.1-1990 specified only
743 Use of these latter values in
745 may be less portable in applications intended for older
746 UNIX implementations.
750 flag is compatible with the SVr4 flag of the same name.
754 flag is compatible with the SVr4 flag of the same name under kernels
756 On older kernels the Linux implementation
757 allowed the receipt of any signal, not just the one we are installing
758 (effectively overriding any
763 can be called with a NULL second argument to query the current signal
765 It can also be used to check whether a given signal is valid for
766 the current machine by calling it with NULL second and third arguments.
768 It is not possible to block
769 .BR SIGKILL " or " SIGSTOP
770 (by specifying them in
772 Attempts to do so are silently ignored.
776 for details on manipulating signal sets.
780 for a list of the async-signal-safe functions that can be
781 safely called inside from inside a signal handler.
783 Before the introduction of
785 it was also possible to get some additional information,
788 with second argument of type
789 .IR "struct sigcontext".
790 See the relevant Linux kernel sources for details.
791 This use is obsolete now.
793 In kernels up to and including 2.6.13, specifying
797 prevents not only the delivered signal from being masked during
798 execution of the handler, but also the signals specified in
800 This bug was fixed in kernel 2.6.14.
809 .BR restart_syscall (2),
819 .BR siginterrupt (3),
826 This page is part of release 3.76 of the Linux
829 A description of the project,
830 information about reporting bugs,
831 and the latest version of this page,
833 \%http://www.kernel.org/doc/man\-pages/.