2 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
3 .\" and Copyright (c) 2002, 2006 by Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
5 .\" <mtk.manpages@gmail.com>
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.
27 .\" Modified Sat Jul 24 17:34:08 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified Sun Jan 7 01:41:27 1996 by Andries Brouwer (aeb@cwi.nl)
29 .\" Modified Sun Apr 14 12:02:29 1996 by Andries Brouwer (aeb@cwi.nl)
30 .\" Modified Sat Nov 13 16:28:23 1999 by Andries Brouwer (aeb@cwi.nl)
31 .\" Modified 10 Apr 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\" Modified 7 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Added information on real-time signals
34 .\" Modified 13 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
35 .\" Noted that SIGSTKFLT is in fact unused
36 .\" 2004-12-03, Modified mtk, added notes on RLIMIT_SIGPENDING
37 .\" 2006-04-24, mtk, Added text on changing signal dispositions,
38 .\" signal mask, and pending signals.
40 .\" Added section on system call restarting (SA_RESTART)
41 .\" Added section on stop/cont signals interrupting syscalls.
42 .\" 2008-10-05, mtk: various additions
44 .TH SIGNAL 7 2012-05-01 "Linux" "Linux Programmer's Manual"
46 signal \- overview of signals
48 Linux supports both POSIX reliable signals (hereinafter
49 "standard signals") and POSIX real-time signals.
50 .SS "Signal Dispositions"
51 Each signal has a current
53 which determines how the process behaves when it is delivered
56 The entries in the "Action" column of the tables below specify
57 the default disposition for each signal, as follows:
59 Default action is to terminate the process.
61 Default action is to ignore the signal.
63 Default action is to terminate the process and dump core (see
66 Default action is to stop the process.
68 Default action is to continue the process if it is currently stopped.
70 A process can change the disposition of a signal using
74 (The latter is less portable when establishing a signal handler;
78 Using these system calls, a process can elect one of the
79 following behaviors to occur on delivery of the signal:
80 perform the default action; ignore the signal;
81 or catch the signal with a
82 .IR "signal handler" ,
83 a programmer-defined function that is automatically invoked
84 when the signal is delivered.
85 (By default, the signal handler is invoked on the
87 It is possible to arrange that the signal handler
88 uses an alternate stack; see
90 for a discussion of how to do this and when it might be useful.)
92 The signal disposition is a per-process attribute:
93 in a multithreaded application, the disposition of a
94 particular signal is the same for all threads.
98 inherits a copy of its parent's signal dispositions.
101 the dispositions of handled signals are reset to the default;
102 the dispositions of ignored signals are left unchanged.
104 The following system calls and library functions allow
105 the caller to send a signal:
108 Sends a signal to the calling thread.
111 Sends a signal to a specified process,
112 to all members of a specified process group,
113 or to all processes on the system.
116 Sends a signal to all of the members of a specified process group.
119 Sends a signal to a specified POSIX thread in the same process as
123 Sends a signal to a specified thread within a specific process.
124 (This is the system call used to implement
125 .BR pthread_kill (3).)
128 Sends a real-time signal with accompanying data to a specified process.
129 .SS Waiting for a Signal to be Caught
130 The following system calls suspend execution of the calling process
131 or thread until a signal is caught
132 (or an unhandled signal terminates the process):
135 Suspends execution until any signal is caught.
138 Temporarily changes the signal mask (see below) and suspends
139 execution until one of the unmasked signals is caught.
140 .SS Synchronously Accepting a Signal
141 Rather than asynchronously catching a signal via a signal handler,
142 it is possible to synchronously accept the signal, that is,
143 to block execution until the signal is delivered,
144 at which point the kernel returns information about the
145 signal to the caller.
146 There are two general ways to do this:
149 .BR sigtimedwait (2),
152 suspend execution until one of the signals in a specified
154 Each of these calls returns information about the delivered signal.
157 returns a file descriptor that can be used to read information
158 about signals that are delivered to the caller.
161 from this file descriptor blocks until one of the signals
162 in the set specified in the
164 call is delivered to the caller.
165 The buffer returned by
167 contains a structure describing the signal.
168 .SS "Signal Mask and Pending Signals"
171 which means that it will not be delivered until it is later unblocked.
172 Between the time when it is generated and when it is delivered
173 a signal is said to be
176 Each thread in a process has an independent
178 which indicates the set of signals that the thread is currently blocking.
179 A thread can manipulate its signal mask using
180 .BR pthread_sigmask (3).
181 In a traditional single-threaded application,
183 can be used to manipulate the signal mask.
187 inherits a copy of its parent's signal mask;
188 the signal mask is preserved across
191 A signal may be generated (and thus pending)
192 for a process as a whole (e.g., when sent using
194 or for a specific thread (e.g., certain signals,
200 consequence of executing a specific machine-language instruction
201 are thread directed, as are signals targeted at a specific thread using
202 .BR pthread_kill (3)).
203 A process-directed signal may be delivered to any one of the
204 threads that does not currently have the signal blocked.
205 If more than one of the threads has the signal unblocked, then the
206 kernel chooses an arbitrary thread to which to deliver the signal.
208 A thread can obtain the set of signals that it currently has pending
211 This set will consist of the union of the set of pending
212 process-directed signals and the set of signals pending for
217 initially has an empty pending signal set;
218 the pending signal set is preserved across an
220 .SS "Standard Signals"
221 Linux supports the standard signals listed below.
222 Several signal numbers
223 are architecture-dependent, as indicated in the "Value" column.
224 (Where three values are given, the first one is usually valid for
226 the middle one for x86, arm, and most other architectures,
227 and the last one for mips.
228 (Values for parisc are
230 shown; see the kernel source for signal numbering on that architecture.)
231 A \- denotes that a signal is absent on the corresponding architecture.)
233 First the signals described in the original POSIX.1-1990 standard.
238 Signal Value Action Comment
239 SIGHUP \01 Term Hangup detected on controlling terminal
240 or death of controlling process
241 SIGINT \02 Term Interrupt from keyboard
242 SIGQUIT \03 Core Quit from keyboard
243 SIGILL \04 Core Illegal Instruction
244 SIGABRT \06 Core Abort signal from \fBabort\fP(3)
245 SIGFPE \08 Core Floating point exception
246 SIGKILL \09 Term Kill signal
247 SIGSEGV 11 Core Invalid memory reference
248 SIGPIPE 13 Term Broken pipe: write to pipe with no
250 SIGALRM 14 Term Timer signal from \fBalarm\fP(2)
251 SIGTERM 15 Term Termination signal
252 SIGUSR1 30,10,16 Term User-defined signal 1
253 SIGUSR2 31,12,17 Term User-defined signal 2
254 SIGCHLD 20,17,18 Ign Child stopped or terminated
255 SIGCONT 19,18,25 Cont Continue if stopped
256 SIGSTOP 17,19,23 Stop Stop process
257 SIGTSTP 18,20,24 Stop Stop typed at tty
258 SIGTTIN 21,21,26 Stop tty input for background process
259 SIGTTOU 22,22,27 Stop tty output for background process
266 cannot be caught, blocked, or ignored.
268 Next the signals not in the POSIX.1-1990 standard but described in
269 SUSv2 and POSIX.1-2001.
274 Signal Value Action Comment
275 SIGBUS 10,7,10 Core Bus error (bad memory access)
276 SIGPOLL Term Pollable event (Sys V).
277 Synonym for \fBSIGIO\fP
278 SIGPROF 27,27,29 Term Profiling timer expired
279 SIGSYS 12,31,12 Core Bad argument to routine (SVr4)
280 SIGTRAP 5 Core Trace/breakpoint trap
281 SIGURG 16,23,21 Ign Urgent condition on socket (4.2BSD)
282 SIGVTALRM 26,26,28 Term Virtual alarm clock (4.2BSD)
283 SIGXCPU 24,24,30 Core CPU time limit exceeded (4.2BSD)
284 SIGXFSZ 25,25,31 Core File size limit exceeded (4.2BSD)
287 Up to and including Linux 2.2, the default behavior for
288 .BR SIGSYS ", " SIGXCPU ", " SIGXFSZ ", "
289 and (on architectures other than SPARC and MIPS)
291 was to terminate the process (without a core dump).
292 (On some other UNIX systems the default action for
293 .BR SIGXCPU " and " SIGXFSZ
294 is to terminate the process without a core dump.)
295 Linux 2.4 conforms to the POSIX.1-2001 requirements for these signals,
296 terminating the process with a core dump.
298 Next various other signals.
303 Signal Value Action Comment
304 SIGIOT 6 Core IOT trap. A synonym for \fBSIGABRT\fP
306 SIGSTKFLT \-,16,\- Term Stack fault on coprocessor (unused)
307 SIGIO 23,29,22 Term I/O now possible (4.2BSD)
308 SIGCLD \-,\-,18 Ign A synonym for \fBSIGCHLD\fP
309 SIGPWR 29,30,19 Term Power failure (System V)
310 SIGINFO 29,\-,\- A synonym for \fBSIGPWR\fP
311 SIGLOST \-,\-,\- Term File lock lost (unused)
312 SIGWINCH 28,28,20 Ign Window resize signal (4.3BSD, Sun)
313 SIGUNUSED \-,31,\- Core Synonymous with \fBSIGSYS\fP
325 is not specified in POSIX.1-2001, but nevertheless appears
326 on most other UNIX systems,
327 where its default action is typically to terminate
328 the process with a core dump.
331 (which is not specified in POSIX.1-2001) is typically ignored
332 by default on those other UNIX systems where it appears.
335 (which is not specified in POSIX.1-2001) is ignored by default
336 on several other UNIX systems.
341 .\" parisc is the only exception: SIGSYS is 12, SIGUNUSED is 31
343 on most architectures.
344 .SS "Real-time Signals"
345 Linux supports real-time signals as originally defined in the POSIX.1b
346 real-time extensions (and now included in POSIX.1-2001).
347 The range of supported real-time signals is defined by the macros
351 POSIX.1-2001 requires that an implementation support at least
353 (8) real-time signals.
355 The Linux kernel supports a range of 32 different real-time
356 signals, numbered 33 to 64.
357 However, the glibc POSIX threads implementation internally uses
358 two (for NPTL) or three (for LinuxThreads) real-time signals
361 and adjusts the value of
363 suitably (to 34 or 35).
364 Because the range of available real-time signals varies according
365 to the glibc threading implementation (and this variation can occur
366 at run time according to the available kernel and glibc),
367 and indeed the range of real-time signals varies across UNIX systems,
369 .IR "never refer to real-time signals using hard-coded numbers" ,
370 but instead should always refer to real-time signals using the notation
372 and include suitable (run-time) checks that
377 Unlike standard signals, real-time signals have no predefined meanings:
378 the entire set of real-time signals can be used for application-defined
381 The default action for an unhandled real-time signal is to terminate the
384 Real-time signals are distinguished by the following:
386 Multiple instances of real-time signals can be queued.
387 By contrast, if multiple instances of a standard signal are delivered
388 while that signal is currently blocked, then only one instance is queued.
390 If the signal is sent using
392 an accompanying value (either an integer or a pointer) can be sent
394 If the receiving process establishes a handler for this signal using the
398 then it can obtain this data via the
402 structure passed as the second argument to the handler.
407 fields of this structure can be used to obtain the PID
408 and real user ID of the process sending the signal.
410 Real-time signals are delivered in a guaranteed order.
411 Multiple real-time signals of the same type are delivered in the order
413 If different real-time signals are sent to a process, they are delivered
414 starting with the lowest-numbered signal.
415 (I.e., low-numbered signals have highest priority.)
416 By contrast, if multiple standard signals are pending for a process,
417 the order in which they are delivered is unspecified.
419 If both standard and real-time signals are pending for a process,
420 POSIX leaves it unspecified which is delivered first.
421 Linux, like many other implementations, gives priority
422 to standard signals in this case.
424 According to POSIX, an implementation should permit at least
425 .B _POSIX_SIGQUEUE_MAX
426 (32) real-time signals to be queued to
428 However, Linux does things differently.
429 In kernels up to and including 2.6.7, Linux imposes
430 a system-wide limit on the number of queued real-time signals
432 This limit can be viewed and (with privilege) changed via the
433 .I /proc/sys/kernel/rtsig-max
436 .IR /proc/sys/kernel/rtsig-nr ,
437 can be used to find out how many real-time signals are currently queued.
438 In Linux 2.6.8, these
440 interfaces were replaced by the
442 resource limit, which specifies a per-user limit for queued
446 .SS "Async-signal-safe functions"
448 A signal handler function must be very careful,
449 since processing elsewhere may be interrupted
450 at some arbitrary point in the execution of the program.
451 POSIX has the concept of "safe function".
452 If a signal interrupts the execution of an unsafe function, and
454 calls an unsafe function, then the behavior of the program is undefined.
456 POSIX.1-2004 (also known as POSIX.1-2001 Technical Corrigendum 2)
457 requires an implementation to guarantee that the following
458 functions can be safely called inside a signal handler:
583 POSIX.1-2008 removes fpathconf(), pathconf(), and sysconf()
584 from the above list, and adds the following functions:
610 .SS Interruption of System Calls and Library Functions by Signal Handlers
611 If a signal handler is invoked while a system call or library
612 function call is blocked, then either:
614 the call is automatically restarted after the signal handler returns; or
616 the call fails with the error
619 Which of these two behaviors occurs depends on the interface and
620 whether or not the signal handler was established using the
624 The details vary across UNIX systems;
625 below, the details for Linux.
627 If a blocked call to one of the following interfaces is interrupted
628 by a signal handler, then the call will be automatically restarted
629 after the signal handler returns if the
631 flag was used; otherwise the call will fail with the error
633 .\" The following system calls use ERESTARTSYS,
634 .\" so that they are restartable
643 calls on "slow" devices.
644 A "slow" device is one where the I/O call may block for an
645 indefinite time, for example, a terminal, pipe, or socket.
646 (A disk is not a slow device according to this definition.)
647 If an I/O call on a slow device has already transferred some
648 data by the time it is interrupted by a signal handler,
649 then the call will return a success status
650 (normally, the number of bytes transferred).
653 if it can block (e.g., when opening a FIFO; see
664 .\" If a timeout (setsockopt()) is in effect on the socket, then these
665 .\" system calls switch to using EINTR. Consequently, they and are not
666 .\" automatically restarted, and they show the stop/cont behavior
667 .\" described below. (Verified from 2.6.26 source, and by experiment; mtk)
677 unless a timeout has been set on the socket (see below).
679 File locking interfaces:
685 POSIX message queue interfaces:
687 .BR mq_timedreceive (3),
690 .BR mq_timedsend (3).
694 (since Linux 2.6.22; beforehand, always failed with
697 POSIX semaphore interfaces:
700 .BR sem_timedwait (3)
701 (since Linux 2.6.22; beforehand, always failed with
705 The following interfaces are never restarted after
706 being interrupted by a signal handler,
707 regardless of the use of
709 they always fail with the error
711 when interrupted by a signal handler:
712 .\" These are the system calls that give EINTR or ERESTARTNOHAND
713 .\" on interruption by a signal handler.
716 Socket interfaces, when a timeout has been set on the socket using
735 Interfaces used to wait for signals:
738 .BR sigtimedwait (2),
742 File descriptor multiplexing interfaces:
751 System V IPC interfaces:
752 .\" On some other systems, SA_RESTART does restart these system calls
760 .BR clock_nanosleep (2),
770 .BR io_getevents (2).
775 function is also never restarted if interrupted by a handler,
776 but gives a success return: the number of seconds remaining to sleep.
777 .SS Interruption of System Calls and Library Functions by Stop Signals
778 On Linux, even in the absence of signal handlers,
779 certain blocking interfaces can fail with the error
781 after the process is stopped by one of the stop signals
784 This behavior is not sanctioned by POSIX.1, and doesn't occur
787 The Linux interfaces that display this behavior are:
790 Socket interfaces, when a timeout has been set on the socket using
815 .BR sigtimedwait (2),
823 Linux 2.6.21 and earlier:
826 .BR sem_timedwait (3),
829 Linux 2.6.8 and earlier:
833 Linux 2.4 and earlier:
837 POSIX.1, except as noted.
838 .\" It must be a *very* long time since this was true:
843 .\" have the same value.
844 .\" The latter is commented out in the kernel source, but
845 .\" the build process of some software still thinks that
853 .BR rt_sigqueueinfo (2),
869 .BR pthread_sigqueue (3),