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