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.
42 .\" 2010-06-11 Andi Kleen, add hwpoison signal extensions
43 .\" 2010-06-11 mtk, improvements to discussion of various siginfo_t fields.
45 .TH SIGACTION 2 2010-06-16 "Linux" "Linux Programmer's Manual"
47 sigaction \- examine and change a signal action
50 .B #include <signal.h>
52 .BI "int sigaction(int " signum ", const struct sigaction *" act ,
53 .BI " struct sigaction *" oldact );
57 Feature Test Macro Requirements for glibc (see
58 .BR feature_test_macros (7)):
63 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
68 system call is used to change the action taken by a process on
69 receipt of a specific signal.
72 for an overview of signals.)
75 specifies the signal and can be any valid signal except
82 is non-NULL, the new action for signal
88 is non-NULL, the previous action is saved in
93 structure is defined as something like:
98 void (*sa_handler)(int);
99 void (*sa_sigaction)(int, siginfo_t *, void *);
102 void (*sa_restorer)(void);
107 On some architectures a union is involved: do not assign to both
114 element is obsolete and should not be used.
115 POSIX does not specify a
120 specifies the action to be associated with
124 for the default action,
126 to ignore this signal, or a pointer to a signal handling function.
127 This function receives the signal number as its only argument.
137 specifies the signal-handling function for
139 This function receives the signal number as its first argument, a
142 as its second argument and a pointer to a
144 (cast to \fIvoid\ *\fP) as its third argument.
147 specifies a mask of signals which should be blocked
148 (i.e., added to the signal mask of the thread in which
149 the signal handler is invoked)
150 during execution of the signal handler.
151 In addition, the signal which triggered the handler
152 will be blocked, unless the
157 specifies a set of flags which modify the behavior of the signal.
158 It is formed by the bitwise OR of zero or more of the following:
166 do not receive notification when child processes stop (i.e., when they
168 .BR SIGSTOP ", " SIGTSTP ", " SIGTTIN
171 or resume (i.e., they receive
175 This flag is only meaningful when establishing a handler for
178 .BR SA_NOCLDWAIT " (since Linux 2.6)"
179 .\" To be precise: Linux 2.5.60 -- MTK
184 do not transform children into zombies when they terminate.
187 This flag is only meaningful when establishing a handler for
189 or when setting that signal's disposition to
194 flag is set when establishing a handler for
196 POSIX.1 leaves it unspecified whether a
198 signal is generated when a child process terminates.
201 signal is generated in this case;
202 on some other implementations, it is not.
205 Do not prevent the signal from being received from within its own signal
207 This flag is only meaningful when establishing a signal handler.
209 is an obsolete, nonstandard synonym for this flag.
212 Call the signal handler on an alternate signal stack provided by
214 If an alternate stack is not available, the default stack will be used.
215 This flag is only meaningful when establishing a signal handler.
218 Restore the signal action to the default state once the signal handler
220 This flag is only meaningful when establishing a signal handler.
222 is an obsolete, nonstandard synonym for this flag.
225 Provide behavior compatible with BSD signal semantics by making certain
226 system calls restartable across signals.
227 This flag is only meaningful when establishing a signal handler.
230 for a discussion of system call restarting.
232 .BR SA_SIGINFO " (since Linux 2.2)"
233 The signal handler takes 3 arguments, not one.
236 should be set instead of
238 This flag is only meaningful when establishing a signal handler.
241 .\" field was added in Linux 2.1.86.)
248 is a struct with the following elements:
253 int si_signo; /* Signal number */
254 int si_errno; /* An errno value */
255 int si_code; /* Signal code */
256 int si_trapno; /* Trap number that caused
257 hardware-generated signal
258 (unused on most architectures) */
260 .\" si_trapno seems to be only used on SPARC and Alpha;
261 .\" this page could use a little more detail on its purpose there.
262 pid_t si_pid; /* Sending process ID */
263 uid_t si_uid; /* Real user ID of sending process */
264 int si_status; /* Exit value or signal */
265 clock_t si_utime; /* User time consumed */
266 clock_t si_stime; /* System time consumed */
267 sigval_t si_value; /* Signal value */
268 int si_int; /* POSIX.1b signal */
269 void *si_ptr; /* POSIX.1b signal */
270 int si_overrun; /* Timer overrun count; POSIX.1b timers */
271 int si_timerid; /* Timer ID; POSIX.1b timers */
272 .\" In the kernel: si_tid
273 void *si_addr; /* Memory location which caused fault */
274 long si_band; /* Band event (was \fIint\fP in
275 glibc 2.3.2 and earlier) */
276 int si_fd; /* File descriptor */
277 short si_addr_lsb; /* Least significant bit of address
278 (since kernel 2.6.32) */
283 .IR si_signo ", " si_errno " and " si_code
284 are defined for all signals.
286 is generally unused on Linux.)
287 The rest of the struct may be a union, so that one should only
288 read the fields that are meaningful for the given signal:
295 .IR si_pid " and " si_uid .
296 In addition, signals sent with
299 .IR si_int " and " si_ptr
300 with the values specified by the sender the signal;
305 Signals sent by POSIX.1b timers (since Linux 2.6) fill in
311 field is an internal ID used by the kernel to identify
312 the timer; it is not the same as the timer ID returned by
313 .BR timer_create (2).
316 field is the timer overrun count;
317 this is the same information as is obtained by a call to
318 .BR timer_getoverrun (2).
319 These fields are nonstandard Linux extensions.
321 Signals sent for message queue notification (see the description of
326 .IR si_int / si_ptr ,
332 with the process ID of the message sender; and
334 with the real user ID of the message sender.
338 .IR si_pid ", " si_uid ", " si_status ", " si_utime " and " si_stime ,
339 providing information about the child.
342 field is the process ID of the child;
344 is the child's real user ID.
347 field contains the exit status of the child (if
351 or the signal number that caused the process to change state.
356 contain the user and system CPU time used by the child process;
357 these fields do not include the times used by waited-for children (unlike
361 In kernels up to 2.6, and since 2.6.27, these fields report
363 .IR sysconf(_SC_CLK_TCK) .
364 In 2.6 kernels before 2.6.27,
365 a bug meant that these fields reported time in units
366 of the (configurable) system jiffy (see
369 .\" When si_utime and si_stime where originally implemented, the
370 .\" measurement unit was HZ, which was the same as clock ticks
371 .\" (sysconf(_SC_CLK_TCK)). In 2.6, HZ became configurable, and
372 .\" was *still* used as the unit to return the info these fields,
373 .\" with the result that the field values depended on the the
374 .\" configured HZ. Of course, the should have been measured in
375 .\" USER_HZ instead, so that sysconf(_SC_CLK_TCK) could be used to
376 .\" convert to seconds. I have a queued patch to fix this:
377 .\" http://thread.gmane.org/gmane.linux.kernel/698061/ .
378 .\" This patch made it into 2.6.27.
379 .\" But note that these fields still don't return the times of
380 .\" waited-for children (as is done by getrusage() and times()
381 .\" and wait4()). Solaris 8 does include child times.
391 with the address of the fault.
392 .\" FIXME SIGTRAP also sets the following for ptrace_notify() ?
393 .\" info.si_code = exit_code;
394 .\" info.si_pid = task_pid_vnr(current);
395 .\" info.si_uid = current_uid(); /* Real UID */
396 On some architectures,
397 these signals also fill in the
408 This field indicates the least significant bit of the reported address
409 and therefore the extent of the corruption.
410 For example, if a full page was corrupted,
413 .IR log2(sysconf(_SC_PAGESIZE)) .
417 are Linux-specific extensions.
421 .IR si_band " and " si_fd .
424 event is a bit mask containing the same values as are filled in the
430 field indicates the file descriptor for which the I/O event occurred.
433 is a value (not a bit mask)
434 indicating why this signal was sent.
435 The following list shows the values which can be placed in
437 for any signal, along with reason that the signal was generated.
455 POSIX message queue state changed (since Linux 2.6.6); see
469 .\" SI_DETHREAD is defined in 2.6.9 sources, but isn't implemented
470 .\" It appears to have been an idea that was tried during 2.5.6
471 .\" through to 2.5.24 and then was backed out.
474 The following values can be placed in
488 illegal addressing mode
506 The following values can be placed in
514 integer divide by zero
520 floating-point divide by zero
523 floating-point overflow
526 floating-point underflow
529 floating-point inexact result
532 floating-point invalid operation
535 subscript out of range
538 The following values can be placed in
546 address not mapped to object
549 invalid permissions for mapped object
552 The following values can be placed in
560 invalid address alignment
563 nonexistent physical address
566 object-specific hardware error
568 .BR BUS_MCEERR_AR " (since Linux 2.6.32)"
569 Hardware memory error consumed on a machine check; action required.
571 .BR BUS_MCEERR_AO " (since Linux 2.6.32)"
572 Hardware memory error detected in process but not consumed; action optional.
575 The following values can be placed in
588 .BR TRAP_BRANCH " (since Linux 2.4)"
589 process taken branch trap
591 .BR TRAP_HWBKPT " (since Linux 2.4)"
592 hardware breakpoint/watchpoint
595 The following values can be placed in
609 child terminated abnormally
612 traced child has trapped
618 stopped child has continued (since Linux 2.6.9)
621 The following values can be placed in
632 output buffers available
635 input message available
641 high priority input available
648 returns 0 on success and \-1 on error.
652 .IR act " or " oldact
653 points to memory which is not a valid part of the process address space.
656 An invalid signal was specified.
657 This will also be generated if an attempt
658 is made to change the action for
659 .BR SIGKILL " or " SIGSTOP ", "
660 which cannot be caught or ignored.
663 .\" SVr4 does not document the EINTR condition.
667 inherits a copy of its parent's signal dispositions.
670 the dispositions of handled signals are reset to the default;
671 the dispositions of ignored signals are left unchanged.
673 According to POSIX, the behavior of a process is undefined after it
679 signal that was not generated by
683 Integer division by zero has undefined result.
684 On some architectures it will generate a
687 (Also dividing the most negative integer by \-1 may generate
689 Ignoring this signal might lead to an endless loop.
691 POSIX.1-1990 disallowed setting the action for
695 POSIX.1-2001 allows this possibility, so that ignoring
697 can be used to prevent the creation of zombies (see
699 Nevertheless, the historical BSD and System V behaviors for ignoring
701 differ, so that the only completely portable method of ensuring that
702 terminated children do not become zombies is to catch the
708 POSIX.1-1990 only specified
716 Use of these latter values in
718 may be less portable in applications intended for older
719 UNIX implementations.
723 flag is compatible with the SVr4 flag of the same name.
727 flag is compatible with the SVr4 flag of the same name under kernels
729 On older kernels the Linux implementation
730 allowed the receipt of any signal, not just the one we are installing
731 (effectively overriding any
736 can be called with a NULL second argument to query the current signal
738 It can also be used to check whether a given signal is valid for
739 the current machine by calling it with NULL second and third arguments.
741 It is not possible to block
742 .BR SIGKILL " or " SIGSTOP
743 (by specifying them in
745 Attempts to do so are silently ignored.
749 for details on manipulating signal sets.
753 for a list of the async-signal-safe functions that can be
754 safely called inside from inside a signal handler.
756 Before the introduction of
758 it was also possible to get some additional information,
761 with second argument of type
762 .IR "struct sigcontext".
763 See the relevant kernel sources for details.
764 This use is obsolete now.
766 In kernels up to and including 2.6.13, specifying
770 prevents not only the delivered signal from being masked during
771 execution of the handler, but also the signals specified in
773 This bug was fixed in kernel 2.6.14.
791 .BR siginterrupt (3),