]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man7/signal.7
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man7 / signal.7
CommitLineData
fea681da 1.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
f527d6fe 2.\" and Copyright (c) 2002, 2006, 2020 by Michael Kerrisk <mtk.manpages@gmail.com>
743bc395
MK
3.\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
4.\" <mtk.manpages@gmail.com>
fea681da 5.\"
5fbde956 6.\" SPDX-License-Identifier: Linux-man-pages-copyleft
1b88e9c2 7.\"
fea681da
MK
8.\" Modified Sat Jul 24 17:34:08 1993 by Rik Faith (faith@cs.unc.edu)
9.\" Modified Sun Jan 7 01:41:27 1996 by Andries Brouwer (aeb@cwi.nl)
10.\" Modified Sun Apr 14 12:02:29 1996 by Andries Brouwer (aeb@cwi.nl)
11.\" Modified Sat Nov 13 16:28:23 1999 by Andries Brouwer (aeb@cwi.nl)
c11b1abf
MK
12.\" Modified 10 Apr 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
13.\" Modified 7 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 14.\" Added information on real-time signals
c11b1abf 15.\" Modified 13 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 16.\" Noted that SIGSTKFLT is in fact unused
1c1634c0 17.\" 2004-12-03, Modified mtk, added notes on RLIMIT_SIGPENDING
ae74cd0d
MK
18.\" 2006-04-24, mtk, Added text on changing signal dispositions,
19.\" signal mask, and pending signals.
743bc395
MK
20.\" 2008-07-04, mtk:
21.\" Added section on system call restarting (SA_RESTART)
22.\" Added section on stop/cont signals interrupting syscalls.
2411effe 23.\" 2008-10-05, mtk: various additions
fea681da 24.\"
4c1c5274 25.TH signal 7 (date) "Linux man-pages (unreleased)"
fea681da 26.SH NAME
2411effe 27signal \- overview of signals
fea681da
MK
28.SH DESCRIPTION
29Linux supports both POSIX reliable signals (hereinafter
30"standard signals") and POSIX real-time signals.
73d8cece 31.SS Signal dispositions
c13182ef 32Each signal has a current
ae74cd0d 33.IR disposition ,
c13182ef 34which determines how the process behaves when it is delivered
ae74cd0d 35the signal.
a721e8b2 36.PP
1fa9fdb1 37The entries in the "Action" column of the table below specify
ae74cd0d 38the default disposition for each signal, as follows:
4279e42d
AC
39.TP
40Term
fea681da 41Default action is to terminate the process.
4279e42d
AC
42.TP
43Ign
fea681da 44Default action is to ignore the signal.
4279e42d
AC
45.TP
46Core
ae74cd0d
MK
47Default action is to terminate the process and dump core (see
48.BR core (5)).
4279e42d
AC
49.TP
50Stop
fea681da 51Default action is to stop the process.
4279e42d
AC
52.TP
53Cont
ae74cd0d 54Default action is to continue the process if it is currently stopped.
fea681da 55.PP
ae74cd0d
MK
56A process can change the disposition of a signal using
57.BR sigaction (2)
7edfdaca 58or
ae74cd0d 59.BR signal (2).
7edfdaca
MK
60(The latter is less portable when establishing a signal handler;
61see
62.BR signal (2)
63for details.)
c13182ef 64Using these system calls, a process can elect one of the
6beb1671 65following behaviors to occur on delivery of the signal:
c13182ef 66perform the default action; ignore the signal;
ae74cd0d 67or catch the signal with a
c13182ef
MK
68.IR "signal handler" ,
69a programmer-defined function that is automatically invoked
ae74cd0d 70when the signal is delivered.
705ac54d
MK
71.PP
72By default, a signal handler is invoked on the
eeccef1d
MK
73normal process stack.
74It is possible to arrange that the signal handler
75uses an alternate stack; see
76.BR sigaltstack (2)
705ac54d 77for a discussion of how to do this and when it might be useful.
a721e8b2 78.PP
ae74cd0d 79The signal disposition is a per-process attribute:
c13182ef 80in a multithreaded application, the disposition of a
ae74cd0d 81particular signal is the same for all threads.
a721e8b2 82.PP
d5c88298
MK
83A child created via
84.BR fork (2)
85inherits a copy of its parent's signal dispositions.
86During an
87.BR execve (2),
88the dispositions of handled signals are reset to the default;
89the dispositions of ignored signals are left unchanged.
c634028a 90.SS Sending a signal
7a414038
MK
91The following system calls and library functions allow
92the caller to send a signal:
1f11ae8a 93.TP
7a414038
MK
94.BR raise (3)
95Sends a signal to the calling thread.
96.TP
97.BR kill (2)
98Sends a signal to a specified process,
99to all members of a specified process group,
100or to all processes on the system.
101.TP
bdeb6c88
MK
102.BR pidfd_send_signal (2)
103Sends a signal to a process identified by a PID file descriptor.
104.TP
498aad50 105.BR killpg (3)
7a414038
MK
106Sends a signal to all of the members of a specified process group.
107.TP
108.BR pthread_kill (3)
109Sends a signal to a specified POSIX thread in the same process as
110the caller.
111.TP
112.BR tgkill (2)
113Sends a signal to a specified thread within a specific process.
114(This is the system call used to implement
115.BR pthread_kill (3).)
116.TP
485ab701 117.BR sigqueue (3)
7a414038 118Sends a real-time signal with accompanying data to a specified process.
c634028a 119.SS Waiting for a signal to be caught
0cec2472
MK
120The following system calls suspend execution of the calling
121thread until a signal is caught
22fe4981 122(or an unhandled signal terminates the process):
1f11ae8a 123.TP
22fe4981
MK
124.BR pause (2)
125Suspends execution until any signal is caught.
126.TP
127.BR sigsuspend (2)
128Temporarily changes the signal mask (see below) and suspends
129execution until one of the unmasked signals is caught.
f527d6fe 130.\"
c634028a 131.SS Synchronously accepting a signal
e66d51d1
MK
132Rather than asynchronously catching a signal via a signal handler,
133it is possible to synchronously accept the signal, that is,
134to block execution until the signal is delivered,
135at which point the kernel returns information about the
136signal to the caller.
137There are two general ways to do this:
22356d97 138.IP \(bu 3
e66d51d1
MK
139.BR sigwaitinfo (2),
140.BR sigtimedwait (2),
141and
142.BR sigwait (3)
143suspend execution until one of the signals in a specified
144set is delivered.
145Each of these calls returns information about the delivered signal.
22356d97 146.IP \(bu
e66d51d1
MK
147.BR signalfd (2)
148returns a file descriptor that can be used to read information
149about signals that are delivered to the caller.
150Each
151.BR read (2)
152from this file descriptor blocks until one of the signals
153in the set specified in the
154.BR signalfd (2)
155call is delivered to the caller.
156The buffer returned by
157.BR read (2)
158contains a structure describing the signal.
73d8cece 159.SS Signal mask and pending signals
ae74cd0d
MK
160A signal may be
161.IR blocked ,
162which means that it will not be delivered until it is later unblocked.
163Between the time when it is generated and when it is delivered
c13182ef 164a signal is said to be
ae74cd0d 165.IR pending .
a721e8b2 166.PP
c13182ef
MK
167Each thread in a process has an independent
168.IR "signal mask" ,
ae74cd0d
MK
169which indicates the set of signals that the thread is currently blocking.
170A thread can manipulate its signal mask using
171.BR pthread_sigmask (3).
c13182ef 172In a traditional single-threaded application,
ae74cd0d
MK
173.BR sigprocmask (2)
174can be used to manipulate the signal mask.
a721e8b2 175.PP
d5c88298
MK
176A child created via
177.BR fork (2)
178inherits a copy of its parent's signal mask;
179the signal mask is preserved across
180.BR execve (2).
a721e8b2 181.PP
3b9d4409
MK
182A signal may be process-directed or thread-directed.
183A process-directed signal is one that is targeted at (and thus pending for)
184the process as a whole.
185A signal may be process-directed
186because it was generated by the kernel for reasons
187other than a hardware exception, or because it was sent using
188.BR kill (2)
189or
190.BR sigqueue (3).
96f49e54 191A thread-directed signal is one that is targeted at a specific thread.
3b9d4409
MK
192A signal may be thread-directed because it was generated as a consequence
193of executing a specific machine-language instruction
194that triggered a hardware exception (e.g.,
5a5574b9 195.B SIGSEGV
3b9d4409
MK
196for an invalid memory access, or
197.B SIGFPE
c1d62739 198for a math error), or because it was
3b9d4409
MK
199targeted at a specific thread using
200interfaces such as
201.BR tgkill (2)
202or
203.BR pthread_kill (3).
204.PP
ae74cd0d
MK
205A process-directed signal may be delivered to any one of the
206threads that does not currently have the signal blocked.
3220cf5f
MK
207.\" Joseph C. Sible notes:
208.\" On Linux, if the main thread has the signal unblocked, then the kernel
209.\" will always deliver the signal there, citing this kernel code
210.\"
211.\" Per this comment in kernel/signal.c since time immemorial:
212.\"
213.\" /*
214.\" * Now find a thread we can wake up to take the signal off the queue.
215.\" *
216.\" * If the main thread wants the signal, it gets first crack.
217.\" * Probably the least surprising to the average bear.
218.\" */
219.\"
220.\" But this does not mean the signal will be delivered only in the
221.\" main thread, since if a handler is already executing in the main thread
222.\" (and thus the signal is blocked in that thread), then a further
223.\" might be delivered in a different thread.
224.\"
c13182ef 225If more than one of the threads has the signal unblocked, then the
ae74cd0d 226kernel chooses an arbitrary thread to which to deliver the signal.
a721e8b2 227.PP
ae74cd0d
MK
228A thread can obtain the set of signals that it currently has pending
229using
230.BR sigpending (2).
c13182ef
MK
231This set will consist of the union of the set of pending
232process-directed signals and the set of signals pending for
ae74cd0d 233the calling thread.
a721e8b2 234.PP
d5c88298
MK
235A child created via
236.BR fork (2)
237initially has an empty pending signal set;
238the pending signal set is preserved across an
239.BR execve (2).
4672536d
MK
240.\"
241.SS Execution of signal handlers
242Whenever there is a transition from kernel-mode to user-mode execution
243(e.g., on return from a system call or scheduling of a thread onto the CPU),
42e6553d
MK
244the kernel checks whether there is a pending unblocked signal
245for which the process has established a signal handler.
4672536d 246If there is such a pending signal, the following steps occur:
22356d97 247.IP (1) 5
4672536d
MK
248The kernel performs the necessary preparatory steps for execution of
249the signal handler:
250.RS
22356d97 251.IP (1.1) 7
4672536d 252The signal is removed from the set of pending signals.
22356d97 253.IP (1.2)
17cf67cc
MK
254If the signal handler was installed by a call to
255.BR sigaction (2)
256that specified the
1ae6b2c7 257.B SA_ONSTACK
17cf67cc 258flag and the thread has defined an alternate signal stack (using
4672536d
MK
259.BR sigaltstack (2)),
260then that stack is installed.
22356d97 261.IP (1.3)
4672536d 262Various pieces of signal-related context are saved
e7a5700f 263into a special frame that is created on the stack.
4672536d
MK
264The saved information includes:
265.RS
22356d97 266.IP \(bu 3
4672536d
MK
267the program counter register
268(i.e., the address of the next instruction in the main program that
269should be executed when the signal handler returns);
22356d97 270.IP \(bu
e7a5700f
MK
271architecture-specific register state required for resuming the
272interrupted program;
22356d97 273.IP \(bu
4672536d 274the thread's current signal mask;
22356d97 275.IP \(bu
4672536d
MK
276the thread's alternate signal stack settings.
277.RE
6430ba7a
MK
278.IP
279(If the signal handler was installed using the
280.BR sigaction (2)
281.B SA_SIGINFO
282flag, then the above information is accessible via the
938dd97e
MK
283.I ucontext_t
284object that is pointed to by the third argument of the signal handler.)
22356d97 285.IP (1.4)
e7a5700f
MK
286Any signals specified in
287.I act\->sa_mask
288when registering the handler with
289.BR sigprocmask (2)
290are added to the thread's signal mask.
291The signal being delivered is also
292added to the signal mask, unless
293.B SA_NODEFER
294was specified when registering the handler.
4672536d
MK
295These signals are thus blocked while the handler executes.
296.RE
22356d97 297.IP (2)
4672536d 298The kernel constructs a frame for the signal handler on the stack.
e7a5700f
MK
299The kernel sets the program counter for the thread to point to the first
300instruction of the signal handler function,
301and configures the return address for that function to point to a piece
302of user-space code known as the signal trampoline (described in
4672536d 303.BR sigreturn (2)).
22356d97 304.IP (3)
4672536d
MK
305The kernel passes control back to user-space, where execution
306commences at the start of the signal handler function.
22356d97 307.IP (4)
4672536d 308When the signal handler returns, control passes to the signal trampoline code.
22356d97 309.IP (5)
4672536d
MK
310The signal trampoline calls
311.BR sigreturn (2),
e7a5700f 312a system call that uses the information in the stack frame created in step 1
42e6553d
MK
313to restore the thread to its state before the signal handler was
314called.
315The thread's signal mask and alternate signal stack settings
316are restored as part of this procedure.
4672536d
MK
317Upon completion of the call to
318.BR sigreturn (2),
319the kernel transfers control back to user space,
320and the thread recommences execution at the point where it was
321interrupted by the signal handler.
322.PP
323Note that if the signal handler does not return
324(e.g., control is transferred out of the handler using
e066dcb3 325.BR siglongjmp (3),
4672536d
MK
326or the handler executes a new program with
327.BR execve (2)),
328then the final step is not performed.
329In particular, in such scenarios it is the programmer's responsibility
17cf67cc
MK
330to restore the state of the signal mask (using
331.BR sigprocmask (2)),
332if it is desired to unblock the signals that were blocked on entry
4672536d 333to the signal handler.
17cf67cc
MK
334(Note that
335.BR siglongjmp (3)
336may or may not restore the signal mask, depending on the
337.I savesigs
338value that was specified in the corresponding call to
339.BR sigsetjmp (3).)
42e6553d
MK
340.PP
341From the kernel's point of view,
342execution of the signal handler code is exactly the same as the execution
343of any other user-space code.
344That is to say, the kernel does not record any special state information
0580884c 345indicating that the thread is currently executing inside a signal handler.
42e6553d
MK
346All necessary state information is maintained in user-space registers
347and the user-space stack.
348The depth to which nested signal handlers may be invoked is thus
349limited only by the user-space stack (and sensible software design!).
4672536d 350.\"
73d8cece 351.SS Standard signals
c13182ef 352Linux supports the standard signals listed below.
1fa9fdb1
MK
353The second column of the table indicates which standard (if any)
354specified the signal: "P1990" indicates that the signal is described
355in the original POSIX.1-1990 standard;
356"P2001" indicates that the signal was added in SUSv2 and POSIX.1-2001.
fea681da
MK
357.TS
358l c c l
359____
360lB c c l.
6043ed9d 361Signal Standard Action Comment
1fa9fdb1
MK
362SIGABRT P1990 Core Abort signal from \fBabort\fP(3)
363SIGALRM P1990 Term Timer signal from \fBalarm\fP(2)
364SIGBUS P2001 Core Bus error (bad memory access)
365SIGCHLD P1990 Ign Child stopped or terminated
366SIGCLD \- Ign A synonym for \fBSIGCHLD\fP
367SIGCONT P1990 Cont Continue if stopped
368SIGEMT \- Term Emulator trap
369SIGFPE P1990 Core Floating-point exception
6043ed9d 370SIGHUP P1990 Term Hangup detected on controlling terminal
fea681da 371 or death of controlling process
6043ed9d 372SIGILL P1990 Core Illegal Instruction
1fa9fdb1
MK
373SIGINFO \- A synonym for \fBSIGPWR\fP
374SIGINT P1990 Term Interrupt from keyboard
375SIGIO \- Term I/O now possible (4.2BSD)
376SIGIOT \- Core IOT trap. A synonym for \fBSIGABRT\fP
6043ed9d 377SIGKILL P1990 Term Kill signal
1fa9fdb1 378SIGLOST \- Term File lock lost (unused)
6043ed9d 379SIGPIPE P1990 Term Broken pipe: write to pipe with no
9af4022a 380 readers; see \fBpipe\fP(7)
08a964c9
MK
381SIGPOLL P2001 Term Pollable event (Sys V);
382 synonym for \fBSIGIO\fP
6043ed9d 383SIGPROF P2001 Term Profiling timer expired
1fa9fdb1
MK
384SIGPWR \- Term Power failure (System V)
385SIGQUIT P1990 Core Quit from keyboard
386SIGSEGV P1990 Core Invalid memory reference
387SIGSTKFLT \- Term Stack fault on coprocessor (unused)
388SIGSTOP P1990 Stop Stop process
389SIGTSTP P1990 Stop Stop typed at terminal
6043ed9d 390SIGSYS P2001 Core Bad system call (SVr4);
0288ee4c 391 see also \fBseccomp\fP(2)
1fa9fdb1 392SIGTERM P1990 Term Termination signal
6043ed9d 393SIGTRAP P2001 Core Trace/breakpoint trap
1fa9fdb1
MK
394SIGTTIN P1990 Stop Terminal input for background process
395SIGTTOU P1990 Stop Terminal output for background process
396SIGUNUSED \- Core Synonymous with \fBSIGSYS\fP
6043ed9d 397SIGURG P2001 Ign Urgent condition on socket (4.2BSD)
1fa9fdb1
MK
398SIGUSR1 P1990 Term User-defined signal 1
399SIGUSR2 P1990 Term User-defined signal 2
6043ed9d
MK
400SIGVTALRM P2001 Term Virtual alarm clock (4.2BSD)
401SIGXCPU P2001 Core CPU time limit exceeded (4.2BSD);
eb8e63a9 402 see \fBsetrlimit\fP(2)
6043ed9d 403SIGXFSZ P2001 Core File size limit exceeded (4.2BSD);
bd741e0f 404 see \fBsetrlimit\fP(2)
1fa9fdb1 405SIGWINCH \- Ign Window resize signal (4.3BSD, Sun)
fea681da 406.TE
bdbc9b44 407.PP
1fa9fdb1
MK
408The signals
409.B SIGKILL
410and
411.B SIGSTOP
412cannot be caught, blocked, or ignored.
413.PP
d9bfdb9c 414Up to and including Linux 2.2, the default behavior for
c3f60223 415.BR SIGSYS ", " SIGXCPU ", " SIGXFSZ ,
fea681da
MK
416and (on architectures other than SPARC and MIPS)
417.B SIGBUS
418was to terminate the process (without a core dump).
008f1ecc 419(On some other UNIX systems the default action for
fea681da
MK
420.BR SIGXCPU " and " SIGXFSZ
421is to terminate the process without a core dump.)
4dec66f9 422Linux 2.4 conforms to the POSIX.1-2001 requirements for these signals,
fea681da 423terminating the process with a core dump.
a721e8b2 424.PP
fea681da 425.B SIGEMT
4dec66f9 426is not specified in POSIX.1-2001, but nevertheless appears
008f1ecc 427on most other UNIX systems,
d24e2319 428where its default action is typically to terminate
fea681da 429the process with a core dump.
a721e8b2 430.PP
fea681da 431.B SIGPWR
4dec66f9 432(which is not specified in POSIX.1-2001) is typically ignored
008f1ecc 433by default on those other UNIX systems where it appears.
a721e8b2 434.PP
fea681da 435.B SIGIO
4dec66f9 436(which is not specified in POSIX.1-2001) is ignored by default
008f1ecc 437on several other UNIX systems.
1fa9fdb1 438.\"
c7871135
MK
439.SS Queueing and delivery semantics for standard signals
440If multiple standard signals are pending for a process,
441the order in which the signals are delivered is unspecified.
442.PP
443Standard signals do not queue.
444If multiple instances of a standard signal are generated while
445that signal is blocked,
446then only one instance of the signal is marked as pending
447(and the signal will be delivered just once when it is unblocked).
9b6aa9d1 448In the case where a standard signal is already pending, the
cd9b34fc 449.I siginfo_t
9b6aa9d1
MK
450structure (see
451.BR sigaction (2))
452associated with that signal is not overwritten
453on arrival of subsequent instances of the same signal.
454Thus, the process will receive the information
455associated with the first instance of the signal.
c7871135 456.\"
9a10a144
MK
457.SS Signal numbering for standard signals
458The numeric value for each signal is given in the table below.
459As shown in the table, many signals have different numeric values
460on different architectures.
461The first numeric value in each table row shows the signal number
462on x86, ARM, and most other architectures;
463the second value is for Alpha and SPARC; the third is for MIPS;
464and the last is for PARISC.
465A dash (\-) denotes that a signal is absent on the corresponding architecture.
466.TS
467l c c c c l
468l c c c c l
469______
470lB c c c c l.
471Signal x86/ARM Alpha/ MIPS PARISC Notes
472 most others SPARC
473SIGHUP \01 \01 \01 \01
474SIGINT \02 \02 \02 \02
475SIGQUIT \03 \03 \03 \03
476SIGILL \04 \04 \04 \04
477SIGTRAP \05 \05 \05 \05
478SIGABRT \06 \06 \06 \06
479SIGIOT \06 \06 \06 \06
480SIGBUS \07 10 10 10
481SIGEMT \- \07 \07 -
482SIGFPE \08 \08 \08 \08
483SIGKILL \09 \09 \09 \09
484SIGUSR1 10 30 16 16
485SIGSEGV 11 11 11 11
486SIGUSR2 12 31 17 17
487SIGPIPE 13 13 13 13
488SIGALRM 14 14 14 14
489SIGTERM 15 15 15 15
490SIGSTKFLT 16 \- \- \07
491SIGCHLD 17 20 18 18
492SIGCLD \- \- 18 \-
493SIGCONT 18 19 25 26
494SIGSTOP 19 17 23 24
495SIGTSTP 20 18 24 25
496SIGTTIN 21 21 26 27
497SIGTTOU 22 22 27 28
498SIGURG 23 16 21 29
499SIGXCPU 24 24 30 12
500SIGXFSZ 25 25 31 30
501SIGVTALRM 26 26 28 20
502SIGPROF 27 27 29 21
503SIGWINCH 28 28 20 23
504SIGIO 29 23 22 22
505SIGPOLL Same as SIGIO
506SIGPWR 30 29/\- 19 19
507SIGINFO \- 29/\- \- \-
508SIGLOST \- \-/29 \- \-
509SIGSYS 31 12 12 31
510SIGUNUSED 31 \- \- 31
511.TE
512.PP
513Note the following:
22356d97 514.IP \(bu 3
9a10a144
MK
515Where defined,
516.B SIGUNUSED
517is synonymous with
518.BR SIGSYS .
519Since glibc 2.26,
520.B SIGUNUSED
521is no longer defined on any architecture.
22356d97 522.IP \(bu
9a10a144
MK
523Signal 29 is
524.BR SIGINFO / SIGPWR
525(synonyms for the same value) on Alpha but
526.B SIGLOST
527on SPARC.
528.\"
73d8cece 529.SS Real-time signals
6c6aa9a8 530Starting with version 2.2,
4dec66f9
MK
531Linux supports real-time signals as originally defined in the POSIX.1b
532real-time extensions (and now included in POSIX.1-2001).
5a5574b9
MK
533The range of supported real-time signals is defined by the macros
534.B SIGRTMIN
535and
536.BR SIGRTMAX .
537POSIX.1-2001 requires that an implementation support at least
538.B _POSIX_RTSIG_MAX
539(8) real-time signals.
540.PP
373ed9ba
MK
541The Linux kernel supports a range of 33 different real-time
542signals, numbered 32 to 64.
5a5574b9 543However, the glibc POSIX threads implementation internally uses
e0bf9127 544two (for NPTL) or three (for LinuxThreads) real-time signals
5a5574b9
MK
545(see
546.BR pthreads (7)),
547and adjusts the value of
548.B SIGRTMIN
549suitably (to 34 or 35).
550Because the range of available real-time signals varies according
551to the glibc threading implementation (and this variation can occur
cf50118f 552at run time according to the available kernel and glibc),
008f1ecc 553and indeed the range of real-time signals varies across UNIX systems,
5a5574b9
MK
554programs should
555.IR "never refer to real-time signals using hard-coded numbers" ,
556but instead should always refer to real-time signals using the notation
fea681da 557.BR SIGRTMIN +n,
e0bf9127 558and include suitable (run-time) checks that
5a5574b9
MK
559.BR SIGRTMIN +n
560does not exceed
561.BR SIGRTMAX .
fea681da
MK
562.PP
563Unlike standard signals, real-time signals have no predefined meanings:
564the entire set of real-time signals can be used for application-defined
565purposes.
fea681da
MK
566.PP
567The default action for an unhandled real-time signal is to terminate the
568receiving process.
569.PP
570Real-time signals are distinguished by the following:
22356d97 571.IP \(bu 3
fea681da
MK
572Multiple instances of real-time signals can be queued.
573By contrast, if multiple instances of a standard signal are delivered
574while that signal is currently blocked, then only one instance is queued.
22356d97 575.IP \(bu
fea681da 576If the signal is sent using
485ab701 577.BR sigqueue (3),
fea681da
MK
578an accompanying value (either an integer or a pointer) can be sent
579with the signal.
580If the receiving process establishes a handler for this signal using the
9fdfa163 581.B SA_SIGINFO
fea681da 582flag to
1c1cbf3d 583.BR sigaction (2),
fea681da
MK
584then it can obtain this data via the
585.I si_value
586field of the
587.I siginfo_t
588structure passed as the second argument to the handler.
589Furthermore, the
590.I si_pid
591and
592.I si_uid
593fields of this structure can be used to obtain the PID
594and real user ID of the process sending the signal.
22356d97 595.IP \(bu
fea681da
MK
596Real-time signals are delivered in a guaranteed order.
597Multiple real-time signals of the same type are delivered in the order
598they were sent.
599If different real-time signals are sent to a process, they are delivered
600starting with the lowest-numbered signal.
601(I.e., low-numbered signals have highest priority.)
4564433c
MK
602By contrast, if multiple standard signals are pending for a process,
603the order in which they are delivered is unspecified.
fea681da
MK
604.PP
605If both standard and real-time signals are pending for a process,
606POSIX leaves it unspecified which is delivered first.
607Linux, like many other implementations, gives priority
608to standard signals in this case.
609.PP
610According to POSIX, an implementation should permit at least
5a5574b9
MK
611.B _POSIX_SIGQUEUE_MAX
612(32) real-time signals to be queued to
fea681da 613a process.
1c1634c0
MK
614However, Linux does things differently.
615In kernels up to and including 2.6.7, Linux imposes
fea681da
MK
616a system-wide limit on the number of queued real-time signals
617for all processes.
618This limit can be viewed and (with privilege) changed via the
b49c2acb 619.I /proc/sys/kernel/rtsig\-max
fea681da
MK
620file.
621A related file,
b49c2acb 622.IR /proc/sys/kernel/rtsig\-nr ,
fea681da 623can be used to find out how many real-time signals are currently queued.
1c1634c0
MK
624In Linux 2.6.8, these
625.I /proc
de7e5e18 626interfaces were replaced by the
1c1634c0
MK
627.B RLIMIT_SIGPENDING
628resource limit, which specifies a per-user limit for queued
c0722da0 629signals; see
1c1634c0
MK
630.BR setrlimit (2)
631for further details.
a721e8b2 632.PP
360c1900 633The addition of real-time signals required the widening
530156fe
MK
634of the signal set structure
635.RI ( sigset_t )
636from 32 to 64 bits.
637Consequently, various system calls were superseded by new system calls
638that supported the larger signal sets.
639The old and new system calls are as follows:
640.TS
641lb lb
642l l.
643Linux 2.0 and earlier Linux 2.2 and later
644\fBsigaction\fP(2) \fBrt_sigaction\fP(2)
645\fBsigpending\fP(2) \fBrt_sigpending\fP(2)
646\fBsigprocmask\fP(2) \fBrt_sigprocmask\fP(2)
647\fBsigreturn\fP(2) \fBrt_sigreturn\fP(2)
648\fBsigsuspend\fP(2) \fBrt_sigsuspend\fP(2)
649\fBsigtimedwait\fP(2) \fBrt_sigtimedwait\fP(2)
650.TE
651.\"
c634028a 652.SS Interruption of system calls and library functions by signal handlers
72710182
MK
653If a signal handler is invoked while a system call or library
654function call is blocked, then either:
22356d97 655.IP \(bu 3
72710182 656the call is automatically restarted after the signal handler returns; or
22356d97 657.IP \(bu
72710182 658the call fails with the error
af3c87d0 659.BR EINTR .
72710182
MK
660.PP
661Which of these two behaviors occurs depends on the interface and
662whether or not the signal handler was established using the
1ae6b2c7 663.B SA_RESTART
af3c87d0
MK
664flag (see
665.BR sigaction (2)).
008f1ecc 666The details vary across UNIX systems;
164be4fc 667below, the details for Linux.
a721e8b2 668.PP
72710182 669If a blocked call to one of the following interfaces is interrupted
a23d8efa 670by a signal handler, then the call is automatically restarted
72710182 671after the signal handler returns if the
1ae6b2c7 672.B SA_RESTART
a23d8efa 673flag was used; otherwise the call fails with the error
af3c87d0
MK
674.BR EINTR :
675.\" The following system calls use ERESTARTSYS,
676.\" so that they are restartable
22356d97 677.IP \(bu 3
af3c87d0
MK
678.BR read (2),
679.BR readv (2),
680.BR write (2),
681.BR writev (2),
682and
683.BR ioctl (2)
684calls on "slow" devices.
72710182
MK
685A "slow" device is one where the I/O call may block for an
686indefinite time, for example, a terminal, pipe, or socket.
72710182
MK
687If an I/O call on a slow device has already transferred some
688data by the time it is interrupted by a signal handler,
af3c87d0
MK
689then the call will return a success status
690(normally, the number of bytes transferred).
ae1c1caa
MK
691Note that a (local) disk is not a slow device according to this definition;
692I/O operations on disk devices are not interrupted by signals.
22356d97 693.IP \(bu
af3c87d0 694.BR open (2),
72ee5ec2 695if it can block (e.g., when opening a FIFO; see
af3c87d0 696.BR fifo (7)).
22356d97 697.IP \(bu
af3c87d0
MK
698.BR wait (2),
699.BR wait3 (2),
700.BR wait4 (2),
701.BR waitid (2),
702and
703.BR waitpid (2).
22356d97 704.IP \(bu
af3c87d0 705Socket interfaces:
72710182 706.\" If a timeout (setsockopt()) is in effect on the socket, then these
af3c87d0
MK
707.\" system calls switch to using EINTR. Consequently, they and are not
708.\" automatically restarted, and they show the stop/cont behavior
709.\" described below. (Verified from 2.6.26 source, and by experiment; mtk)
710.BR accept (2),
711.BR connect (2),
712.BR recv (2),
713.BR recvfrom (2),
88fb4f09 714.BR recvmmsg (2),
af3c87d0
MK
715.BR recvmsg (2),
716.BR send (2),
717.BR sendto (2),
718and
4f6d71a1 719.BR sendmsg (2),
6248a90b 720.\" FIXME What about sendmmsg()?
4f6d71a1 721unless a timeout has been set on the socket (see below).
22356d97 722.IP \(bu
af3c87d0
MK
723File locking interfaces:
724.BR flock (2)
725and
6f0dcebc 726the
1ae6b2c7 727.B F_SETLKW
6f0dcebc 728and
1ae6b2c7 729.B F_OFD_SETLKW
6f0dcebc 730operations of
af3c87d0 731.BR fcntl (2)
22356d97 732.IP \(bu
af3c87d0 733POSIX message queue interfaces:
c1667735
MK
734.BR mq_receive (3),
735.BR mq_timedreceive (3),
736.BR mq_send (3),
af3c87d0 737and
c1667735 738.BR mq_timedsend (3).
22356d97 739.IP \(bu
af3c87d0
MK
740.BR futex (2)
741.B FUTEX_WAIT
4b139190
MK
742(since Linux 2.6.22;
743.\" commit 72c1bbf308c75a136803d2d76d0e18258be14c7a
744beforehand, always failed with
af3c87d0 745.BR EINTR ).
22356d97 746.IP \(bu
3168ff2d 747.BR getrandom (2).
22356d97 748.IP \(bu
d53ad479
MK
749.BR pthread_mutex_lock (3),
750.BR pthread_cond_wait (3),
751and related APIs.
22356d97 752.IP \(bu
4b139190
MK
753.BR futex (2)
754.BR FUTEX_WAIT_BITSET .
22356d97 755.IP \(bu
af3c87d0
MK
756POSIX semaphore interfaces:
757.BR sem_wait (3)
758and
759.BR sem_timedwait (3)
4b139190
MK
760(since Linux 2.6.22;
761.\" as a consequence of the 2.6.22 changes in the futex() implementation
762beforehand, always failed with
af3c87d0 763.BR EINTR ).
22356d97 764.IP \(bu
8b6e88b2
MK
765.BR read (2)
766from an
767.BR inotify (7)
768file descriptor
769(since Linux 3.8;
770.\" commit 1ca39ab9d21ac93f94b9e3eb364ea9a5cf2aba06
771beforehand, always failed with
772.BR EINTR ).
af3c87d0
MK
773.PP
774The following interfaces are never restarted after
775being interrupted by a signal handler,
776regardless of the use of
495edd81
MK
777.BR SA_RESTART ;
778they always fail with the error
779.B EINTR
780when interrupted by a signal handler:
af3c87d0
MK
781.\" These are the system calls that give EINTR or ERESTARTNOHAND
782.\" on interruption by a signal handler.
22356d97 783.IP \(bu 3
8efc0168
MK
784"Input" socket interfaces, when a timeout
785.RB ( SO_RCVTIMEO )
786has been set on the socket using
4f6d71a1
MK
787.BR setsockopt (2):
788.BR accept (2),
789.BR recv (2),
790.BR recvfrom (2),
88fb4f09 791.BR recvmmsg (2)
8efc0168 792(also with a non-NULL
1ae6b2c7 793.I timeout
88fb4f09 794argument),
4f6d71a1 795and
8efc0168 796.BR recvmsg (2).
22356d97 797.IP \(bu
8efc0168 798"Output" socket interfaces, when a timeout
4b139190 799.RB ( SO_RCVTIMEO )
8efc0168
MK
800has been set on the socket using
801.BR setsockopt (2):
4f6d71a1
MK
802.BR connect (2),
803.BR send (2),
804.BR sendto (2),
805and
8efc0168 806.BR sendmsg (2).
6248a90b 807.\" FIXME What about sendmmsg()?
22356d97 808.IP \(bu
af3c87d0
MK
809Interfaces used to wait for signals:
810.BR pause (2),
811.BR sigsuspend (2),
743bc395 812.BR sigtimedwait (2),
af3c87d0
MK
813and
814.BR sigwaitinfo (2).
22356d97 815.IP \(bu
af3c87d0
MK
816File descriptor multiplexing interfaces:
817.BR epoll_wait (2),
818.BR epoll_pwait (2),
819.BR poll (2),
820.BR ppoll (2),
821.BR select (2),
822and
823.BR pselect (2).
22356d97 824.IP \(bu
b24473a3 825System V IPC interfaces:
af3c87d0
MK
826.\" On some other systems, SA_RESTART does restart these system calls
827.BR msgrcv (2),
828.BR msgsnd (2),
829.BR semop (2),
830and
831.BR semtimedop (2).
22356d97 832.IP \(bu
af3c87d0
MK
833Sleep interfaces:
834.BR clock_nanosleep (2),
835.BR nanosleep (2),
af3c87d0
MK
836and
837.BR usleep (3).
22356d97 838.IP \(bu
af3c87d0 839.BR io_getevents (2).
495edd81
MK
840.PP
841The
842.BR sleep (3)
843function is also never restarted if interrupted by a handler,
844but gives a success return: the number of seconds remaining to sleep.
730a8d48
MK
845.PP
846In certain circumstances, the
847.BR seccomp (2)
848user-space notification feature can lead to restarting of system calls
849that would otherwise never be restarted by
850.BR SA_RESTART ;
851for details, see
852.BR seccomp_unotify (2).
853.\"
c634028a 854.SS Interruption of system calls and library functions by stop signals
48b9ec3f
MK
855On Linux, even in the absence of signal handlers,
856certain blocking interfaces can fail with the error
1ae6b2c7 857.B EINTR
48b9ec3f
MK
858after the process is stopped by one of the stop signals
859and then resumed via
860.BR SIGCONT .
861This behavior is not sanctioned by POSIX.1, and doesn't occur
862on other systems.
a721e8b2 863.PP
48b9ec3f 864The Linux interfaces that display this behavior are:
22356d97 865.IP \(bu 3
8efc0168
MK
866"Input" socket interfaces, when a timeout
867.RB ( SO_RCVTIMEO )
868has been set on the socket using
4f6d71a1
MK
869.BR setsockopt (2):
870.BR accept (2),
871.BR recv (2),
872.BR recvfrom (2),
88fb4f09 873.BR recvmmsg (2)
8efc0168 874(also with a non-NULL
1ae6b2c7 875.I timeout
88fb4f09 876argument),
4f6d71a1 877and
8efc0168 878.BR recvmsg (2).
22356d97 879.IP \(bu
8efc0168 880"Output" socket interfaces, when a timeout
4b139190 881.RB ( SO_RCVTIMEO )
8efc0168
MK
882has been set on the socket using
883.BR setsockopt (2):
4f6d71a1
MK
884.BR connect (2),
885.BR send (2),
886.BR sendto (2),
887and
4b139190
MK
888.\" FIXME What about sendmmsg()?
889.BR sendmsg (2),
890if a send timeout
891.RB ( SO_SNDTIMEO )
892has been set.
22356d97 893.IP \(bu
48b9ec3f
MK
894.BR epoll_wait (2),
895.BR epoll_pwait (2).
22356d97 896.IP \(bu
48b9ec3f
MK
897.BR semop (2),
898.BR semtimedop (2).
22356d97 899.IP \(bu
48b9ec3f
MK
900.BR sigtimedwait (2),
901.BR sigwaitinfo (2).
22356d97 902.IP \(bu
e3fe7572 903Linux 3.7 and earlier:
48b9ec3f
MK
904.BR read (2)
905from an
906.BR inotify (7)
e3fe7572
MK
907file descriptor
908.\" commit 1ca39ab9d21ac93f94b9e3eb364ea9a5cf2aba06
22356d97 909.IP \(bu
48b9ec3f
MK
910Linux 2.6.21 and earlier:
911.BR futex (2)
912.BR FUTEX_WAIT ,
913.BR sem_timedwait (3),
914.BR sem_wait (3).
22356d97 915.IP \(bu
48b9ec3f
MK
916Linux 2.6.8 and earlier:
917.BR msgrcv (2),
918.BR msgsnd (2).
22356d97 919.IP \(bu
48b9ec3f
MK
920Linux 2.4 and earlier:
921.BR nanosleep (2).
3113c7f3 922.SH STANDARDS
495edd81 923POSIX.1, except as noted.
81b8997f
MK
924.SH NOTES
925For a discussion of async-signal-safe functions, see
28a4c58c 926.BR signal\-safety (7).
81b8997f
MK
927.PP
928The
929.I /proc/[pid]/task/[tid]/status
930file contains various fields that show the signals
931that a thread is blocking
932.RI ( SigBlk ),
933catching
934.RI ( SigCgt ),
935or ignoring
936.RI ( SigIgn ).
937(The set of signals that are caught or ignored will be the same
938across all threads in a process.)
939Other fields show the set of pending signals that are directed to the thread
940.RI ( SigPnd )
941as well as the set of pending signals that are directed
942to the process as a whole
943.RI ( ShdPnd ).
944The corresponding fields in
945.I /proc/[pid]/status
946show the information for the main thread.
947See
948.BR proc (5)
949for further details.
d128b5b7
ZW
950.SH BUGS
951There are six signals that can be delivered
952as a consequence of a hardware exception:
953.BR SIGBUS ,
954.BR SIGEMT ,
955.BR SIGFPE ,
956.BR SIGILL ,
957.BR SIGSEGV ,
958and
959.BR SIGTRAP .
960Which of these signals is delivered,
961for any given hardware exception,
962is not documented and does not always make sense.
963.PP
964For example, an invalid memory access that causes delivery of
965.B SIGSEGV
966on one CPU architecture may cause delivery of
967.B SIGBUS
968on another architecture, or vice versa.
969.PP
970For another example, using the x86
971.I int
972instruction with a forbidden argument
973(any number other than 3 or 128)
974causes delivery of
975.BR SIGSEGV ,
976even though
977.B SIGILL
978would make more sense,
979because of how the CPU reports the forbidden operation to the kernel.
47297adb 980.SH SEE ALSO
fea681da 981.BR kill (1),
96123f41 982.BR clone (2),
8c69c923 983.BR getrlimit (2),
fea681da 984.BR kill (2),
c8fb1c6d 985.BR pidfd_send_signal (2),
d806bc05 986.BR restart_syscall (2),
23038eae 987.BR rt_sigqueueinfo (2),
af3c87d0
MK
988.BR setitimer (2),
989.BR setrlimit (2),
990.BR sgetmask (2),
991.BR sigaction (2),
8c69c923 992.BR sigaltstack (2),
af3c87d0 993.BR signal (2),
058c1165 994.BR signalfd (2),
af3c87d0
MK
995.BR sigpending (2),
996.BR sigprocmask (2),
7d80ac37 997.BR sigreturn (2),
af3c87d0
MK
998.BR sigsuspend (2),
999.BR sigwaitinfo (2),
8c69c923 1000.BR abort (3),
af3c87d0 1001.BR bsd_signal (3),
498aad50 1002.BR killpg (3),
8c69c923 1003.BR longjmp (3),
36757dc1 1004.BR pthread_sigqueue (3),
b4cb896f 1005.BR raise (3),
485ab701 1006.BR sigqueue (3),
af3c87d0 1007.BR sigset (3),
8c69c923
MK
1008.BR sigsetops (3),
1009.BR sigvec (3),
7c85aa6b 1010.BR sigwait (3),
af3c87d0 1011.BR strsignal (3),
1374ba42 1012.BR swapcontext (3),
af3c87d0 1013.BR sysv_signal (3),
e1a9bc1b 1014.BR core (5),
4f62997d 1015.BR proc (5),
cb066271 1016.BR nptl (7),
16ca4564
MK
1017.BR pthreads (7),
1018.BR sigevent (7)