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 2017-05-03 "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 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 the signal number as its first argument, a
151 as its second argument and a pointer to a
153 (cast to \fIvoid\ *\fP) as its third argument.
154 (Commonly, the handler function doesn't make any use of the third argument.
157 for further information about
161 specifies a mask of signals which should be blocked
162 (i.e., added to the signal mask of the thread in which
163 the signal handler is invoked)
164 during execution of the signal handler.
165 In addition, the signal which triggered the handler
166 will be blocked, unless the
171 specifies a set of flags which modify the behavior of the signal.
172 It is formed by the bitwise OR of zero or more of the following:
180 do not receive notification when child processes stop (i.e., when they
182 .BR SIGSTOP ", " SIGTSTP ", " SIGTTIN ", "
185 or resume (i.e., they receive
189 This flag is meaningful only when establishing a handler for
192 .BR SA_NOCLDWAIT " (since Linux 2.6)"
193 .\" To be precise: Linux 2.5.60 -- MTK
198 do not transform children into zombies when they terminate.
201 This flag is meaningful only when establishing a handler for
203 or when setting that signal's disposition to
208 flag is set when establishing a handler for
210 POSIX.1 leaves it unspecified whether a
212 signal is generated when a child process terminates.
215 signal is generated in this case;
216 on some other implementations, it is not.
219 Do not prevent the signal from being received from within its own signal
221 This flag is meaningful only when establishing a signal handler.
223 is an obsolete, nonstandard synonym for this flag.
226 Call the signal handler on an alternate signal stack provided by
228 If an alternate stack is not available, the default stack will be used.
229 This flag is meaningful only when establishing a signal handler.
232 Restore the signal action to the default upon entry to the signal handler.
233 This flag is meaningful only when establishing a signal handler.
235 is an obsolete, nonstandard synonym for this flag.
238 Provide behavior compatible with BSD signal semantics by making certain
239 system calls restartable across signals.
240 This flag is meaningful only when establishing a signal handler.
243 for a discussion of system call restarting.
246 .IR "Not intended for application use" .
247 This flag is used by C libraries to indicate that the
249 field contains the address of a "signal trampoline".
254 .BR SA_SIGINFO " (since Linux 2.2)"
255 The signal handler takes three arguments, not one.
258 should be set instead of
260 This flag is meaningful only when establishing a signal handler.
263 .\" field was added in Linux 2.1.86.)
265 .SS The siginfo_t argument to a SA_SIGINFO handler
270 the signal handler address is passed via the
273 This handler takes three arguments, as follows:
278 handler(int sig, siginfo_t *info, void *ucontext)
287 data type is a structure with the following fields:
292 int si_signo; /* Signal number */
293 int si_errno; /* An errno value */
294 int si_code; /* Signal code */
295 int si_trapno; /* Trap number that caused
296 hardware-generated signal
297 (unused on most architectures) */
299 .\" The siginfo_t 'si_trapno' field seems to be used
300 .\" only on SPARC and Alpha; this page could use
301 .\" a little more detail on its purpose there.
302 pid_t si_pid; /* Sending process ID */
303 uid_t si_uid; /* Real user ID of sending process */
304 int si_status; /* Exit value or signal */
305 clock_t si_utime; /* User time consumed */
306 clock_t si_stime; /* System time consumed */
307 sigval_t si_value; /* Signal value */
308 int si_int; /* POSIX.1b signal */
309 void *si_ptr; /* POSIX.1b signal */
310 int si_overrun; /* Timer overrun count;
312 int si_timerid; /* Timer ID; POSIX.1b timers */
313 .\" In the kernel: si_tid
314 void *si_addr; /* Memory location which caused fault */
315 long si_band; /* Band event (was \fIint\fP in
316 glibc 2.3.2 and earlier) */
317 int si_fd; /* File descriptor */
318 short si_addr_lsb; /* Least significant bit of address
319 (since Linux 2.6.32) */
320 void *si_lower; /* Lower bound when address violation
321 occurred (since Linux 3.19) */
322 void *si_upper; /* Upper bound when address violation
323 occurred (since Linux 3.19) */
324 int si_pkey; /* Protection key on PTE that caused
325 fault (since Linux 4.6) */
326 void *si_call_addr; /* Address of system call instruction
328 int si_syscall; /* Number of attempted system call
330 unsigned int si_arch; /* Architecture of attempted system call
336 .IR si_signo ", " si_errno " and " si_code
337 are defined for all signals.
339 is generally unused on Linux.)
340 The rest of the struct may be a union, so that one should
341 read only the fields that are meaningful for the given signal:
348 .IR si_pid " and " si_uid .
349 In addition, signals sent with
352 .IR si_int " and " si_ptr
353 with the values specified by the sender of the signal;
358 Signals sent by POSIX.1b timers (since Linux 2.6) fill in
364 field is an internal ID used by the kernel to identify
365 the timer; it is not the same as the timer ID returned by
366 .BR timer_create (2).
369 field is the timer overrun count;
370 this is the same information as is obtained by a call to
371 .BR timer_getoverrun (2).
372 These fields are nonstandard Linux extensions.
374 Signals sent for message queue notification (see the description of
379 .IR si_int / si_ptr ,
385 with the process ID of the message sender; and
387 with the real user ID of the message sender.
391 .IR si_pid ", " si_uid ", " si_status ", " si_utime ", and " si_stime ,
392 providing information about the child.
395 field is the process ID of the child;
397 is the child's real user ID.
400 field contains the exit status of the child (if
404 or the signal number that caused the process to change state.
409 contain the user and system CPU time used by the child process;
410 these fields do not include the times used by waited-for children (unlike
414 In kernels up to 2.6, and since 2.6.27, these fields report
416 .IR sysconf(_SC_CLK_TCK) .
417 In 2.6 kernels before 2.6.27,
418 a bug meant that these fields reported time in units
419 of the (configurable) system jiffy (see
422 .\" When si_utime and si_stime where originally implemented, the
423 .\" measurement unit was HZ, which was the same as clock ticks
424 .\" (sysconf(_SC_CLK_TCK)). In 2.6, HZ became configurable, and
425 .\" was *still* used as the unit to return the info these fields,
426 .\" with the result that the field values depended on the
427 .\" configured HZ. Of course, the should have been measured in
428 .\" USER_HZ instead, so that sysconf(_SC_CLK_TCK) could be used to
429 .\" convert to seconds. I have a queued patch to fix this:
430 .\" http://thread.gmane.org/gmane.linux.kernel/698061/ .
431 .\" This patch made it into 2.6.27.
432 .\" But note that these fields still don't return the times of
433 .\" waited-for children (as is done by getrusage() and times()
434 .\" and wait4()). Solaris 8 does include child times.
444 with the address of the fault.
445 On some architectures,
446 these signals also fill in the
458 This field indicates the least significant bit of the reported address
459 and therefore the extent of the corruption.
460 For example, if a full page was corrupted,
463 .IR log2(sysconf(_SC_PAGESIZE)) .
466 is delivered in response to a
468 event (PTRACE_EVENT_foo),
470 is not populated, but
474 are populated with the respective process ID and user ID responsible for
478 the tracee will be shown as delivering the event.
482 are Linux-specific extensions.
501 (the two names are synonyms on Linux)
503 .IR si_band " and " si_fd .
506 event is a bit mask containing the same values as are filled in the
512 field indicates the file descriptor for which the I/O event occurred;
513 for further details, see the description of
519 generated (since Linux 3.5)
520 .\" commit a0727e8ce513fe6890416da960181ceb10fbfae6
521 when a seccomp filter returns
522 .BR SECCOMP_RET_TRAP ,
528 and other fields as described in
537 argument that is passed to a
539 signal handler is a value (not a bit mask)
540 indicating why this signal was sent.
547 and have the ptrace event in the high byte:
550 (SIGTRAP | PTRACE_EVENT_foo << 8).
555 event, the values that can appear in
557 are described in the remainder of this section.
559 the definitions of most of these symbols are obtained from
561 by defining feature test macros (before including
563 header file) as follows:
566 with the value 500 or greater;
570 .BR _XOPEN_SOURCE_EXTENDED ;
574 with the value 200809L or greater.
578 constants, the symbol definitions are provided only in the first two cases.
579 Before glibc 2.20, no feature test macros were required to obtain these symbols.
581 For a regular signal, the following list shows the values which can be
584 for any signal, along with the reason that the signal was generated.
599 .BR SI_MESGQ " (since Linux 2.6.6)"
600 POSIX message queue state changed; see
609 (only in kernels up to Linux 2.2; from Linux 2.4 onward
615 .BR SI_TKILL " (since Linux 2.4.19)"
619 .\" SI_DETHREAD is defined in 2.6.9 sources, but isn't implemented
620 .\" It appears to have been an idea that was tried during 2.5.6
621 .\" through to 2.5.24 and then was backed out.
624 The following values can be placed in
638 Illegal addressing mode.
653 Internal stack error.
656 The following values can be placed in
664 Integer divide by zero.
670 Floating-point divide by zero.
673 Floating-point overflow.
676 Floating-point underflow.
679 Floating-point inexact result.
682 Floating-point invalid operation.
685 Subscript out of range.
688 The following values can be placed in
696 Address not mapped to object.
699 Invalid permissions for mapped object.
701 .BR SEGV_BNDERR " (since Linux 3.19)"
702 .\" commit ee1b58d36aa1b5a79eaba11f5c3633c88231da83
703 Failed address bound checks.
705 .BR SEGV_PKUERR " (since Linux 4.6)"
706 .\" commit cd0ea35ff5511cde299a61c21a95889b4a71464e
707 Access was denied by memory protection keys.
710 The protection key which applied to this access is available via
714 The following values can be placed in
722 Invalid address alignment.
725 Nonexistent physical address.
728 Object-specific hardware error.
730 .BR BUS_MCEERR_AR " (since Linux 2.6.32)"
731 Hardware memory error consumed on a machine check; action required.
733 .BR BUS_MCEERR_AO " (since Linux 2.6.32)"
734 Hardware memory error detected in process but not consumed; action optional.
737 The following values can be placed in
750 .BR TRAP_BRANCH " (since Linux 2.4, IA64 only))"
751 Process taken branch trap.
753 .BR TRAP_HWBKPT " (since Linux 2.4, IA64 only))"
754 Hardware breakpoint/watchpoint.
757 The following values can be placed in
771 Child terminated abnormally.
774 Traced child has trapped.
779 .BR CLD_CONTINUED " (since Linux 2.6.9)"
780 Stopped child has continued.
783 The following values can be placed in
791 Data input available.
794 Output buffers available.
797 Input message available.
803 High priority input available.
809 The following value can be placed in
816 .BR SYS_SECCOMP " (since Linux 3.5)"
823 returns 0 on success; on error, \-1 is returned, and
825 is set to indicate the error.
829 .IR act " or " oldact
830 points to memory which is not a valid part of the process address space.
833 An invalid signal was specified.
834 This will also be generated if an attempt
835 is made to change the action for
836 .BR SIGKILL " or " SIGSTOP ", "
837 which cannot be caught or ignored.
839 POSIX.1-2001, POSIX.1-2008, SVr4.
840 .\" SVr4 does not document the EINTR condition.
844 inherits a copy of its parent's signal dispositions.
847 the dispositions of handled signals are reset to the default;
848 the dispositions of ignored signals are left unchanged.
850 According to POSIX, the behavior of a process is undefined after it
856 signal that was not generated by
860 Integer division by zero has undefined result.
861 On some architectures it will generate a
864 (Also dividing the most negative integer by \-1 may generate
866 Ignoring this signal might lead to an endless loop.
868 POSIX.1-1990 disallowed setting the action for
872 POSIX.1-2001 and later allow this possibility, so that ignoring
874 can be used to prevent the creation of zombies (see
876 Nevertheless, the historical BSD and System\ V behaviors for ignoring
878 differ, so that the only completely portable method of ensuring that
879 terminated children do not become zombies is to catch the
885 POSIX.1-1990 specified only
896 Use of these latter values in
898 may be less portable in applications intended for older
899 UNIX implementations.
903 flag is compatible with the SVr4 flag of the same name.
907 flag is compatible with the SVr4 flag of the same name under kernels
909 On older kernels the Linux implementation
910 allowed the receipt of any signal, not just the one we are installing
911 (effectively overriding any
916 can be called with a NULL second argument to query the current signal
918 It can also be used to check whether a given signal is valid for
919 the current machine by calling it with NULL second and third arguments.
921 It is not possible to block
922 .BR SIGKILL " or " SIGSTOP
923 (by specifying them in
925 Attempts to do so are silently ignored.
929 for details on manipulating signal sets.
932 .BR signal-safety (7)
933 for a list of the async-signal-safe functions that can be
934 safely called inside from inside a signal handler.
936 .SS C library/kernel differences
937 The glibc wrapper function for
941 on attempts to change the disposition of the two real-time signals
942 used internally by the NPTL threading implementation.
947 The original Linux system call was named
949 However, with the addition of real-time signals in Linux 2.2,
950 the fixed-size, 32-bit
952 type supported by that system call was no longer fit for purpose.
953 Consequently, a new system call,
955 was added to support an enlarged
958 The new system call takes a fourth argument,
959 .IR "size_t sigsetsize" ,
960 which specifies the size in bytes of the signal sets in
964 This argument is currently required to have the value
971 wrapper function hides these details from us, transparently calling
973 when the kernel provides it.
976 Before the introduction of
978 it was also possible to get some additional information,
981 with second argument of type
982 .IR "struct sigcontext".
983 See the relevant Linux kernel sources for details.
984 This use is obsolete now.
986 In kernels up to and including 2.6.13, specifying
990 prevents not only the delivered signal from being masked during
991 execution of the handler, but also the signals specified in
993 This bug was fixed in kernel 2.6.14.
1001 .BR restart_syscall (2),
1003 .BR sigaltstack (2),
1007 .BR sigprocmask (2),
1013 .BR siginterrupt (3),