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.
46 .\" 2015-01-17, Kees Cook <keescook@chromium.org>
47 .\" Added notes on ptrace SIGTRAP and SYS_SECCOMP.
49 .TH SIGACTION 2 2019-03-06 "Linux" "Linux Programmer's Manual"
51 sigaction, rt_sigaction \- examine and change a signal action
54 .B #include <signal.h>
56 .BI "int sigaction(int " signum ", const struct sigaction *" act ,
57 .BI " struct sigaction *" oldact );
61 Feature Test Macro Requirements for glibc (see
62 .BR feature_test_macros (7)):
70 _POSIX_C_SOURCE >= 199309L
75 system call is used to change the action taken by a process on
76 receipt of a specific signal.
79 for an overview of signals.)
82 specifies the signal and can be any valid signal except
89 is non-NULL, the new action for signal
95 is non-NULL, the previous action is saved in
100 structure is defined as something like:
105 void (*sa_handler)(int);
106 void (*sa_sigaction)(int, siginfo_t *, void *);
109 void (*sa_restorer)(void);
114 On some architectures a union is involved: do not assign to both
121 field is not intended for application use.
122 (POSIX does not specify a
125 Some further details of the purpose of this field can be found in
129 specifies the action to be associated with
133 for the default action,
135 to ignore this signal, or a pointer to a signal handling function.
136 This function receives the signal number as its only argument.
146 specifies the signal-handling function for
148 This function receives three arguments, as described below.
151 specifies a mask of signals which should be blocked
152 (i.e., added to the signal mask of the thread in which
153 the signal handler is invoked)
154 during execution of the signal handler.
155 In addition, the signal which triggered the handler
156 will be blocked, unless the
161 specifies a set of flags which modify the behavior of the signal.
162 It is formed by the bitwise OR of zero or more of the following:
170 do not receive notification when child processes stop (i.e., when they
172 .BR SIGSTOP ", " SIGTSTP ", " SIGTTIN ", "
175 or resume (i.e., they receive
179 This flag is meaningful only when establishing a handler for
182 .BR SA_NOCLDWAIT " (since Linux 2.6)"
183 .\" To be precise: Linux 2.5.60 -- MTK
188 do not transform children into zombies when they terminate.
191 This flag is meaningful only when establishing a handler for
193 or when setting that signal's disposition to
198 flag is set when establishing a handler for
200 POSIX.1 leaves it unspecified whether a
202 signal is generated when a child process terminates.
205 signal is generated in this case;
206 on some other implementations, it is not.
209 Do not prevent the signal from being received from within its own signal
211 This flag is meaningful only when establishing a signal handler.
213 is an obsolete, nonstandard synonym for this flag.
216 Call the signal handler on an alternate signal stack provided by
218 If an alternate stack is not available, the default stack will be used.
219 This flag is meaningful only when establishing a signal handler.
222 Restore the signal action to the default upon entry to the signal handler.
223 This flag is meaningful only when establishing a signal handler.
225 is an obsolete, nonstandard synonym for this flag.
228 Provide behavior compatible with BSD signal semantics by making certain
229 system calls restartable across signals.
230 This flag is meaningful only when establishing a signal handler.
233 for a discussion of system call restarting.
236 .IR "Not intended for application use" .
237 This flag is used by C libraries to indicate that the
239 field contains the address of a "signal trampoline".
244 .BR SA_SIGINFO " (since Linux 2.2)"
245 The signal handler takes three arguments, not one.
248 should be set instead of
250 This flag is meaningful only when establishing a signal handler.
253 .\" field was added in Linux 2.1.86.)
255 .SS The siginfo_t argument to a SA_SIGINFO handler
260 the signal handler address is passed via the
263 This handler takes three arguments, as follows:
268 handler(int sig, siginfo_t *info, void *ucontext)
275 These three arguments are as follows
278 The number of the signal that caused invocation of the handler.
283 which is a structure containing further information about the signal,
287 This is a pointer to a
289 structure, cast to \fIvoid\ *\fP.
290 The structure pointed to by this field contains
291 signal context information that was saved
292 on the user-space stack by the kernel; for details, see
294 Further information about the
296 structure can be found in
298 Commonly, the handler function doesn't make any use of the third argument.
302 data type is a structure with the following fields:
307 int si_signo; /* Signal number */
308 int si_errno; /* An errno value */
309 int si_code; /* Signal code */
310 int si_trapno; /* Trap number that caused
311 hardware-generated signal
312 (unused on most architectures) */
314 .\" The siginfo_t 'si_trapno' field seems to be used
315 .\" only on SPARC and Alpha; this page could use
316 .\" a little more detail on its purpose there.
317 pid_t si_pid; /* Sending process ID */
318 uid_t si_uid; /* Real user ID of sending process */
319 int si_status; /* Exit value or signal */
320 clock_t si_utime; /* User time consumed */
321 clock_t si_stime; /* System time consumed */
322 sigval_t si_value; /* Signal value */
323 int si_int; /* POSIX.1b signal */
324 void *si_ptr; /* POSIX.1b signal */
325 int si_overrun; /* Timer overrun count;
327 int si_timerid; /* Timer ID; POSIX.1b timers */
328 .\" In the kernel: si_tid
329 void *si_addr; /* Memory location which caused fault */
330 long si_band; /* Band event (was \fIint\fP in
331 glibc 2.3.2 and earlier) */
332 int si_fd; /* File descriptor */
333 short si_addr_lsb; /* Least significant bit of address
334 (since Linux 2.6.32) */
335 void *si_lower; /* Lower bound when address violation
336 occurred (since Linux 3.19) */
337 void *si_upper; /* Upper bound when address violation
338 occurred (since Linux 3.19) */
339 int si_pkey; /* Protection key on PTE that caused
340 fault (since Linux 4.6) */
341 void *si_call_addr; /* Address of system call instruction
343 int si_syscall; /* Number of attempted system call
345 unsigned int si_arch; /* Architecture of attempted system call
351 .IR si_signo ", " si_errno " and " si_code
352 are defined for all signals.
354 is generally unused on Linux.)
355 The rest of the struct may be a union, so that one should
356 read only the fields that are meaningful for the given signal:
363 .IR si_pid " and " si_uid .
364 In addition, signals sent with
367 .IR si_int " and " si_ptr
368 with the values specified by the sender of the signal;
373 Signals sent by POSIX.1b timers (since Linux 2.6) fill in
379 field is an internal ID used by the kernel to identify
380 the timer; it is not the same as the timer ID returned by
381 .BR timer_create (2).
384 field is the timer overrun count;
385 this is the same information as is obtained by a call to
386 .BR timer_getoverrun (2).
387 These fields are nonstandard Linux extensions.
389 Signals sent for message queue notification (see the description of
394 .IR si_int / si_ptr ,
400 with the process ID of the message sender; and
402 with the real user ID of the message sender.
406 .IR si_pid ", " si_uid ", " si_status ", " si_utime ", and " si_stime ,
407 providing information about the child.
410 field is the process ID of the child;
412 is the child's real user ID.
415 field contains the exit status of the child (if
419 or the signal number that caused the process to change state.
424 contain the user and system CPU time used by the child process;
425 these fields do not include the times used by waited-for children (unlike
429 In kernels up to 2.6, and since 2.6.27, these fields report
431 .IR sysconf(_SC_CLK_TCK) .
432 In 2.6 kernels before 2.6.27,
433 a bug meant that these fields reported time in units
434 of the (configurable) system jiffy (see
437 .\" When si_utime and si_stime where originally implemented, the
438 .\" measurement unit was HZ, which was the same as clock ticks
439 .\" (sysconf(_SC_CLK_TCK)). In 2.6, HZ became configurable, and
440 .\" was *still* used as the unit to return the info these fields,
441 .\" with the result that the field values depended on the
442 .\" configured HZ. Of course, the should have been measured in
443 .\" USER_HZ instead, so that sysconf(_SC_CLK_TCK) could be used to
444 .\" convert to seconds. I have a queued patch to fix this:
445 .\" http://thread.gmane.org/gmane.linux.kernel/698061/ .
446 .\" This patch made it into 2.6.27.
447 .\" But note that these fields still don't return the times of
448 .\" waited-for children (as is done by getrusage() and times()
449 .\" and wait4()). Solaris 8 does include child times.
459 with the address of the fault.
460 On some architectures,
461 these signals also fill in the
473 This field indicates the least significant bit of the reported address
474 and therefore the extent of the corruption.
475 For example, if a full page was corrupted,
478 .IR log2(sysconf(_SC_PAGESIZE)) .
481 is delivered in response to a
483 event (PTRACE_EVENT_foo),
485 is not populated, but
489 are populated with the respective process ID and user ID responsible for
493 the tracee will be shown as delivering the event.
497 are Linux-specific extensions.
516 (the two names are synonyms on Linux)
518 .IR si_band " and " si_fd .
521 event is a bit mask containing the same values as are filled in the
527 field indicates the file descriptor for which the I/O event occurred;
528 for further details, see the description of
534 generated (since Linux 3.5)
535 .\" commit a0727e8ce513fe6890416da960181ceb10fbfae6
536 when a seccomp filter returns
537 .BR SECCOMP_RET_TRAP ,
543 and other fields as described in
552 argument that is passed to a
554 signal handler is a value (not a bit mask)
555 indicating why this signal was sent.
562 and have the ptrace event in the high byte:
566 (SIGTRAP | PTRACE_EVENT_foo << 8).
572 event, the values that can appear in
574 are described in the remainder of this section.
576 the definitions of most of these symbols are obtained from
578 by defining feature test macros (before including
580 header file) as follows:
583 with the value 500 or greater;
587 .BR _XOPEN_SOURCE_EXTENDED ;
591 with the value 200809L or greater.
595 constants, the symbol definitions are provided only in the first two cases.
596 Before glibc 2.20, no feature test macros were required to obtain these symbols.
598 For a regular signal, the following list shows the values which can be
601 for any signal, along with the reason that the signal was generated.
616 .BR SI_MESGQ " (since Linux 2.6.6)"
617 POSIX message queue state changed; see
626 (only in kernels up to Linux 2.2; from Linux 2.4 onward
632 .BR SI_TKILL " (since Linux 2.4.19)"
636 .\" SI_DETHREAD is defined in 2.6.9 sources, but isn't implemented
637 .\" It appears to have been an idea that was tried during 2.5.6
638 .\" through to 2.5.24 and then was backed out.
641 The following values can be placed in
655 Illegal addressing mode.
670 Internal stack error.
673 The following values can be placed in
681 Integer divide by zero.
687 Floating-point divide by zero.
690 Floating-point overflow.
693 Floating-point underflow.
696 Floating-point inexact result.
699 Floating-point invalid operation.
702 Subscript out of range.
705 The following values can be placed in
713 Address not mapped to object.
716 Invalid permissions for mapped object.
718 .BR SEGV_BNDERR " (since Linux 3.19)"
719 .\" commit ee1b58d36aa1b5a79eaba11f5c3633c88231da83
720 Failed address bound checks.
722 .BR SEGV_PKUERR " (since Linux 4.6)"
723 .\" commit cd0ea35ff5511cde299a61c21a95889b4a71464e
724 Access was denied by memory protection keys.
727 The protection key which applied to this access is available via
731 The following values can be placed in
739 Invalid address alignment.
742 Nonexistent physical address.
745 Object-specific hardware error.
747 .BR BUS_MCEERR_AR " (since Linux 2.6.32)"
748 Hardware memory error consumed on a machine check; action required.
750 .BR BUS_MCEERR_AO " (since Linux 2.6.32)"
751 Hardware memory error detected in process but not consumed; action optional.
754 The following values can be placed in
767 .BR TRAP_BRANCH " (since Linux 2.4, IA64 only))"
768 Process taken branch trap.
770 .BR TRAP_HWBKPT " (since Linux 2.4, IA64 only))"
771 Hardware breakpoint/watchpoint.
774 The following values can be placed in
788 Child terminated abnormally.
791 Traced child has trapped.
796 .BR CLD_CONTINUED " (since Linux 2.6.9)"
797 Stopped child has continued.
800 The following values can be placed in
808 Data input available.
811 Output buffers available.
814 Input message available.
820 High priority input available.
826 The following value can be placed in
833 .BR SYS_SECCOMP " (since Linux 3.5)"
840 returns 0 on success; on error, \-1 is returned, and
842 is set to indicate the error.
846 .IR act " or " oldact
847 points to memory which is not a valid part of the process address space.
850 An invalid signal was specified.
851 This will also be generated if an attempt
852 is made to change the action for
853 .BR SIGKILL " or " SIGSTOP ", "
854 which cannot be caught or ignored.
856 POSIX.1-2001, POSIX.1-2008, SVr4.
857 .\" SVr4 does not document the EINTR condition.
861 inherits a copy of its parent's signal dispositions.
864 the dispositions of handled signals are reset to the default;
865 the dispositions of ignored signals are left unchanged.
867 According to POSIX, the behavior of a process is undefined after it
873 signal that was not generated by
877 Integer division by zero has undefined result.
878 On some architectures it will generate a
881 (Also dividing the most negative integer by \-1 may generate
883 Ignoring this signal might lead to an endless loop.
885 POSIX.1-1990 disallowed setting the action for
889 POSIX.1-2001 and later allow this possibility, so that ignoring
891 can be used to prevent the creation of zombies (see
893 Nevertheless, the historical BSD and System\ V behaviors for ignoring
895 differ, so that the only completely portable method of ensuring that
896 terminated children do not become zombies is to catch the
902 POSIX.1-1990 specified only
913 Use of these latter values in
915 may be less portable in applications intended for older
916 UNIX implementations.
920 flag is compatible with the SVr4 flag of the same name.
924 flag is compatible with the SVr4 flag of the same name under kernels
926 On older kernels the Linux implementation
927 allowed the receipt of any signal, not just the one we are installing
928 (effectively overriding any
933 can be called with a NULL second argument to query the current signal
935 It can also be used to check whether a given signal is valid for
936 the current machine by calling it with NULL second and third arguments.
938 It is not possible to block
939 .BR SIGKILL " or " SIGSTOP
940 (by specifying them in
942 Attempts to do so are silently ignored.
946 for details on manipulating signal sets.
949 .BR signal-safety (7)
950 for a list of the async-signal-safe functions that can be
951 safely called inside from inside a signal handler.
953 .SS C library/kernel differences
954 The glibc wrapper function for
958 on attempts to change the disposition of the two real-time signals
959 used internally by the NPTL threading implementation.
964 On architectures where the signal trampoline resides in the C library,
965 the glibc wrapper function for
967 places the address of the trampoline code in the
977 The original Linux system call was named
979 However, with the addition of real-time signals in Linux 2.2,
980 the fixed-size, 32-bit
982 type supported by that system call was no longer fit for purpose.
983 Consequently, a new system call,
985 was added to support an enlarged
988 The new system call takes a fourth argument,
989 .IR "size_t sigsetsize" ,
990 which specifies the size in bytes of the signal sets in
994 This argument is currently required to have the value
1001 wrapper function hides these details from us, transparently calling
1003 when the kernel provides it.
1006 Before the introduction of
1008 it was also possible to get some additional information about the signal.
1009 This was done by providing an
1011 signal handler with a second argument of type
1012 .IR "struct sigcontext" ,
1013 which is the same structure as the one that is passed in the
1017 structure that is passed (via a pointer) in the third argument of the
1020 See the relevant Linux kernel sources for details.
1021 This use is obsolete now.
1023 In kernels up to and including 2.6.13, specifying
1027 prevents not only the delivered signal from being masked during
1028 execution of the handler, but also the signals specified in
1030 This bug was fixed in kernel 2.6.14.
1038 .BR restart_syscall (2),
1040 .BR sigaltstack (2),
1044 .BR sigprocmask (2),
1050 .BR siginterrupt (3),