]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | '\" t |
2 | .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) | |
743bc395 MK |
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> | |
fea681da | 6 | .\" |
93015253 | 7 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
8 | .\" Permission is granted to make and distribute verbatim copies of this |
9 | .\" manual provided the copyright notice and this permission notice are | |
10 | .\" preserved on all copies. | |
11 | .\" | |
12 | .\" Permission is granted to copy and distribute modified versions of this | |
13 | .\" manual under the conditions for verbatim copying, provided that the | |
14 | .\" entire resulting derived work is distributed under the terms of a | |
15 | .\" permission notice identical to this one. | |
c13182ef | 16 | .\" |
fea681da MK |
17 | .\" Since the Linux kernel and libraries are constantly changing, this |
18 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
19 | .\" responsibility for errors or omissions, or for damages resulting from | |
20 | .\" the use of the information contained herein. The author(s) may not | |
21 | .\" have taken the same level of care in the production of this manual, | |
22 | .\" which is licensed free of charge, as they might when working | |
23 | .\" professionally. | |
c13182ef | 24 | .\" |
fea681da MK |
25 | .\" Formatted or processed versions of this manual, if unaccompanied by |
26 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 27 | .\" %%%LICENSE_END |
1b88e9c2 | 28 | .\" |
fea681da MK |
29 | .\" Modified Sat Jul 24 17:34:08 1993 by Rik Faith (faith@cs.unc.edu) |
30 | .\" Modified Sun Jan 7 01:41:27 1996 by Andries Brouwer (aeb@cwi.nl) | |
31 | .\" Modified Sun Apr 14 12:02:29 1996 by Andries Brouwer (aeb@cwi.nl) | |
32 | .\" Modified Sat Nov 13 16:28:23 1999 by Andries Brouwer (aeb@cwi.nl) | |
c11b1abf MK |
33 | .\" Modified 10 Apr 2002, by Michael Kerrisk <mtk.manpages@gmail.com> |
34 | .\" Modified 7 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com> | |
fea681da | 35 | .\" Added information on real-time signals |
c11b1abf | 36 | .\" Modified 13 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 37 | .\" Noted that SIGSTKFLT is in fact unused |
1c1634c0 | 38 | .\" 2004-12-03, Modified mtk, added notes on RLIMIT_SIGPENDING |
ae74cd0d MK |
39 | .\" 2006-04-24, mtk, Added text on changing signal dispositions, |
40 | .\" signal mask, and pending signals. | |
743bc395 MK |
41 | .\" 2008-07-04, mtk: |
42 | .\" Added section on system call restarting (SA_RESTART) | |
43 | .\" Added section on stop/cont signals interrupting syscalls. | |
2411effe | 44 | .\" 2008-10-05, mtk: various additions |
fea681da | 45 | .\" |
67d2c687 | 46 | .TH SIGNAL 7 2015-05-07 "Linux" "Linux Programmer's Manual" |
fea681da | 47 | .SH NAME |
2411effe | 48 | signal \- overview of signals |
fea681da MK |
49 | .SH DESCRIPTION |
50 | Linux supports both POSIX reliable signals (hereinafter | |
51 | "standard signals") and POSIX real-time signals. | |
73d8cece | 52 | .SS Signal dispositions |
c13182ef | 53 | Each signal has a current |
ae74cd0d | 54 | .IR disposition , |
c13182ef | 55 | which determines how the process behaves when it is delivered |
ae74cd0d | 56 | the signal. |
fea681da | 57 | |
ae74cd0d MK |
58 | The entries in the "Action" column of the tables below specify |
59 | the default disposition for each signal, as follows: | |
fea681da MK |
60 | .IP Term |
61 | Default action is to terminate the process. | |
62 | .IP Ign | |
63 | Default action is to ignore the signal. | |
64 | .IP Core | |
ae74cd0d MK |
65 | Default action is to terminate the process and dump core (see |
66 | .BR core (5)). | |
fea681da MK |
67 | .IP Stop |
68 | Default action is to stop the process. | |
ae74cd0d MK |
69 | .IP Cont |
70 | Default action is to continue the process if it is currently stopped. | |
fea681da | 71 | .PP |
ae74cd0d MK |
72 | A process can change the disposition of a signal using |
73 | .BR sigaction (2) | |
7edfdaca | 74 | or |
ae74cd0d | 75 | .BR signal (2). |
7edfdaca MK |
76 | (The latter is less portable when establishing a signal handler; |
77 | see | |
78 | .BR signal (2) | |
79 | for details.) | |
c13182ef | 80 | Using these system calls, a process can elect one of the |
6beb1671 | 81 | following behaviors to occur on delivery of the signal: |
c13182ef | 82 | perform the default action; ignore the signal; |
ae74cd0d | 83 | or catch the signal with a |
c13182ef MK |
84 | .IR "signal handler" , |
85 | a programmer-defined function that is automatically invoked | |
ae74cd0d | 86 | when the signal is delivered. |
eeccef1d MK |
87 | (By default, the signal handler is invoked on the |
88 | normal process stack. | |
89 | It is possible to arrange that the signal handler | |
90 | uses an alternate stack; see | |
91 | .BR sigaltstack (2) | |
92 | for a discussion of how to do this and when it might be useful.) | |
ae74cd0d MK |
93 | |
94 | The signal disposition is a per-process attribute: | |
c13182ef | 95 | in a multithreaded application, the disposition of a |
ae74cd0d | 96 | particular signal is the same for all threads. |
d5c88298 MK |
97 | |
98 | A child created via | |
99 | .BR fork (2) | |
100 | inherits a copy of its parent's signal dispositions. | |
101 | During an | |
102 | .BR execve (2), | |
103 | the dispositions of handled signals are reset to the default; | |
104 | the dispositions of ignored signals are left unchanged. | |
c634028a | 105 | .SS Sending a signal |
7a414038 MK |
106 | The following system calls and library functions allow |
107 | the caller to send a signal: | |
4704a09b | 108 | .TP 16 |
7a414038 MK |
109 | .BR raise (3) |
110 | Sends a signal to the calling thread. | |
111 | .TP | |
112 | .BR kill (2) | |
113 | Sends a signal to a specified process, | |
114 | to all members of a specified process group, | |
115 | or to all processes on the system. | |
116 | .TP | |
117 | .BR killpg (2) | |
118 | Sends a signal to all of the members of a specified process group. | |
119 | .TP | |
120 | .BR pthread_kill (3) | |
121 | Sends a signal to a specified POSIX thread in the same process as | |
122 | the caller. | |
123 | .TP | |
124 | .BR tgkill (2) | |
125 | Sends a signal to a specified thread within a specific process. | |
126 | (This is the system call used to implement | |
127 | .BR pthread_kill (3).) | |
128 | .TP | |
485ab701 | 129 | .BR sigqueue (3) |
7a414038 | 130 | Sends a real-time signal with accompanying data to a specified process. |
c634028a | 131 | .SS Waiting for a signal to be caught |
22fe4981 MK |
132 | The following system calls suspend execution of the calling process |
133 | or thread until a signal is caught | |
134 | (or an unhandled signal terminates the process): | |
135 | .TP 16 | |
136 | .BR pause (2) | |
137 | Suspends execution until any signal is caught. | |
138 | .TP | |
139 | .BR sigsuspend (2) | |
140 | Temporarily changes the signal mask (see below) and suspends | |
141 | execution until one of the unmasked signals is caught. | |
c634028a | 142 | .SS Synchronously accepting a signal |
e66d51d1 MK |
143 | Rather than asynchronously catching a signal via a signal handler, |
144 | it is possible to synchronously accept the signal, that is, | |
145 | to block execution until the signal is delivered, | |
146 | at which point the kernel returns information about the | |
147 | signal to the caller. | |
148 | There are two general ways to do this: | |
4697f7a7 | 149 | .IP * 2 |
e66d51d1 MK |
150 | .BR sigwaitinfo (2), |
151 | .BR sigtimedwait (2), | |
152 | and | |
153 | .BR sigwait (3) | |
154 | suspend execution until one of the signals in a specified | |
155 | set is delivered. | |
156 | Each of these calls returns information about the delivered signal. | |
157 | .IP * | |
158 | .BR signalfd (2) | |
159 | returns a file descriptor that can be used to read information | |
160 | about signals that are delivered to the caller. | |
161 | Each | |
162 | .BR read (2) | |
163 | from this file descriptor blocks until one of the signals | |
164 | in the set specified in the | |
165 | .BR signalfd (2) | |
166 | call is delivered to the caller. | |
167 | The buffer returned by | |
168 | .BR read (2) | |
169 | contains a structure describing the signal. | |
73d8cece | 170 | .SS Signal mask and pending signals |
ae74cd0d MK |
171 | A signal may be |
172 | .IR blocked , | |
173 | which means that it will not be delivered until it is later unblocked. | |
174 | Between the time when it is generated and when it is delivered | |
c13182ef | 175 | a signal is said to be |
ae74cd0d MK |
176 | .IR pending . |
177 | ||
c13182ef MK |
178 | Each thread in a process has an independent |
179 | .IR "signal mask" , | |
ae74cd0d MK |
180 | which indicates the set of signals that the thread is currently blocking. |
181 | A thread can manipulate its signal mask using | |
182 | .BR pthread_sigmask (3). | |
c13182ef | 183 | In a traditional single-threaded application, |
ae74cd0d MK |
184 | .BR sigprocmask (2) |
185 | can be used to manipulate the signal mask. | |
186 | ||
d5c88298 MK |
187 | A child created via |
188 | .BR fork (2) | |
189 | inherits a copy of its parent's signal mask; | |
190 | the signal mask is preserved across | |
191 | .BR execve (2). | |
192 | ||
ae74cd0d MK |
193 | A signal may be generated (and thus pending) |
194 | for a process as a whole (e.g., when sent using | |
c13182ef MK |
195 | .BR kill (2)) |
196 | or for a specific thread (e.g., certain signals, | |
5a5574b9 MK |
197 | such as |
198 | .B SIGSEGV | |
199 | and | |
200 | .BR SIGFPE , | |
201 | generated as a | |
c13182ef | 202 | consequence of executing a specific machine-language instruction |
ae74cd0d | 203 | are thread directed, as are signals targeted at a specific thread using |
8869be19 | 204 | .BR pthread_kill (3)). |
ae74cd0d MK |
205 | A process-directed signal may be delivered to any one of the |
206 | threads that does not currently have the signal blocked. | |
c13182ef | 207 | If more than one of the threads has the signal unblocked, then the |
ae74cd0d MK |
208 | kernel chooses an arbitrary thread to which to deliver the signal. |
209 | ||
210 | A thread can obtain the set of signals that it currently has pending | |
211 | using | |
212 | .BR sigpending (2). | |
c13182ef MK |
213 | This set will consist of the union of the set of pending |
214 | process-directed signals and the set of signals pending for | |
ae74cd0d | 215 | the calling thread. |
d5c88298 MK |
216 | |
217 | A child created via | |
218 | .BR fork (2) | |
219 | initially has an empty pending signal set; | |
220 | the pending signal set is preserved across an | |
221 | .BR execve (2). | |
73d8cece | 222 | .SS Standard signals |
c13182ef MK |
223 | Linux supports the standard signals listed below. |
224 | Several signal numbers | |
a43eed0c | 225 | are architecture-dependent, as indicated in the "Value" column. |
ae74cd0d | 226 | (Where three values are given, the first one is usually valid for |
8c69c923 | 227 | alpha and sparc, |
df2b6326 | 228 | the middle one for x86, arm, and most other architectures, |
8c69c923 | 229 | and the last one for mips. |
0ab8aeec | 230 | (Values for parisc are |
df2b6326 | 231 | .I not |
66a9882e | 232 | shown; see the Linux kernel source for signal numbering on that architecture.) |
ae74cd0d MK |
233 | A \- denotes that a signal is absent on the corresponding architecture.) |
234 | ||
4dec66f9 | 235 | First the signals described in the original POSIX.1-1990 standard. |
fea681da MK |
236 | .TS |
237 | l c c l | |
238 | ____ | |
239 | lB c c l. | |
240 | Signal Value Action Comment | |
241 | SIGHUP \01 Term Hangup detected on controlling terminal | |
242 | or death of controlling process | |
243 | SIGINT \02 Term Interrupt from keyboard | |
244 | SIGQUIT \03 Core Quit from keyboard | |
245 | SIGILL \04 Core Illegal Instruction | |
d9c1ae64 | 246 | SIGABRT \06 Core Abort signal from \fBabort\fP(3) |
fea681da MK |
247 | SIGFPE \08 Core Floating point exception |
248 | SIGKILL \09 Term Kill signal | |
249 | SIGSEGV 11 Core Invalid memory reference | |
10a100d0 MK |
250 | SIGPIPE 13 Term Broken pipe: write to pipe with no |
251 | readers | |
d9c1ae64 | 252 | SIGALRM 14 Term Timer signal from \fBalarm\fP(2) |
fea681da | 253 | SIGTERM 15 Term Termination signal |
2706f299 MK |
254 | SIGUSR1 30,10,16 Term User-defined signal 1 |
255 | SIGUSR2 31,12,17 Term User-defined signal 2 | |
fea681da | 256 | SIGCHLD 20,17,18 Ign Child stopped or terminated |
ae74cd0d | 257 | SIGCONT 19,18,25 Cont Continue if stopped |
fea681da | 258 | SIGSTOP 17,19,23 Stop Stop process |
1285ff3d MK |
259 | SIGTSTP 18,20,24 Stop Stop typed at terminal |
260 | SIGTTIN 21,21,26 Stop Terminal input for background process | |
261 | SIGTTOU 22,22,27 Stop Terminal output for background process | |
fea681da MK |
262 | .TE |
263 | ||
264 | The signals | |
265 | .B SIGKILL | |
266 | and | |
267 | .B SIGSTOP | |
268 | cannot be caught, blocked, or ignored. | |
269 | ||
c13182ef | 270 | Next the signals not in the POSIX.1-1990 standard but described in |
4dec66f9 | 271 | SUSv2 and POSIX.1-2001. |
fea681da MK |
272 | .TS |
273 | l c c l | |
274 | ____ | |
275 | lB c c l. | |
276 | Signal Value Action Comment | |
277 | SIGBUS 10,7,10 Core Bus error (bad memory access) | |
10a100d0 MK |
278 | SIGPOLL Term Pollable event (Sys V). |
279 | Synonym for \fBSIGIO\fP | |
fea681da | 280 | SIGPROF 27,27,29 Term Profiling timer expired |
07b00378 | 281 | SIGSYS 12,31,12 Core Bad argument to routine (SVr4) |
fea681da | 282 | SIGTRAP 5 Core Trace/breakpoint trap |
66679b1f MK |
283 | SIGURG 16,23,21 Ign Urgent condition on socket (4.2BSD) |
284 | SIGVTALRM 26,26,28 Term Virtual alarm clock (4.2BSD) | |
285 | SIGXCPU 24,24,30 Core CPU time limit exceeded (4.2BSD) | |
286 | SIGXFSZ 25,25,31 Core File size limit exceeded (4.2BSD) | |
fea681da MK |
287 | .TE |
288 | ||
d9bfdb9c | 289 | Up to and including Linux 2.2, the default behavior for |
fea681da MK |
290 | .BR SIGSYS ", " SIGXCPU ", " SIGXFSZ ", " |
291 | and (on architectures other than SPARC and MIPS) | |
292 | .B SIGBUS | |
293 | was to terminate the process (without a core dump). | |
008f1ecc | 294 | (On some other UNIX systems the default action for |
fea681da MK |
295 | .BR SIGXCPU " and " SIGXFSZ |
296 | is to terminate the process without a core dump.) | |
4dec66f9 | 297 | Linux 2.4 conforms to the POSIX.1-2001 requirements for these signals, |
fea681da MK |
298 | terminating the process with a core dump. |
299 | ||
300 | Next various other signals. | |
fea681da MK |
301 | .TS |
302 | l c c l | |
303 | ____ | |
304 | lB c c l. | |
305 | Signal Value Action Comment | |
5a5574b9 | 306 | SIGIOT 6 Core IOT trap. A synonym for \fBSIGABRT\fP |
fea681da MK |
307 | SIGEMT 7,\-,7 Term |
308 | SIGSTKFLT \-,16,\- Term Stack fault on coprocessor (unused) | |
66679b1f | 309 | SIGIO 23,29,22 Term I/O now possible (4.2BSD) |
5a5574b9 | 310 | SIGCLD \-,\-,18 Ign A synonym for \fBSIGCHLD\fP |
fea681da | 311 | SIGPWR 29,30,19 Term Power failure (System V) |
5a5574b9 | 312 | SIGINFO 29,\-,\- A synonym for \fBSIGPWR\fP |
6cf29ace | 313 | SIGLOST \-,\-,\- Term File lock lost (unused) |
66679b1f | 314 | SIGWINCH 28,28,20 Ign Window resize signal (4.3BSD, Sun) |
07b00378 | 315 | SIGUNUSED \-,31,\- Core Synonymous with \fBSIGSYS\fP |
fea681da MK |
316 | .TE |
317 | ||
318 | (Signal 29 is | |
319 | .B SIGINFO | |
320 | / | |
321 | .B SIGPWR | |
322 | on an alpha but | |
323 | .B SIGLOST | |
324 | on a sparc.) | |
325 | ||
326 | .B SIGEMT | |
4dec66f9 | 327 | is not specified in POSIX.1-2001, but nevertheless appears |
008f1ecc | 328 | on most other UNIX systems, |
d24e2319 | 329 | where its default action is typically to terminate |
fea681da MK |
330 | the process with a core dump. |
331 | ||
332 | .B SIGPWR | |
4dec66f9 | 333 | (which is not specified in POSIX.1-2001) is typically ignored |
008f1ecc | 334 | by default on those other UNIX systems where it appears. |
fea681da MK |
335 | |
336 | .B SIGIO | |
4dec66f9 | 337 | (which is not specified in POSIX.1-2001) is ignored by default |
008f1ecc | 338 | on several other UNIX systems. |
07b00378 MK |
339 | |
340 | Where defined, | |
341 | .B SIGUNUSED | |
342 | is synonymous with | |
343 | .\" parisc is the only exception: SIGSYS is 12, SIGUNUSED is 31 | |
344 | .B SIGSYS | |
345 | on most architectures. | |
73d8cece | 346 | .SS Real-time signals |
6c6aa9a8 | 347 | Starting with version 2.2, |
4dec66f9 MK |
348 | Linux supports real-time signals as originally defined in the POSIX.1b |
349 | real-time extensions (and now included in POSIX.1-2001). | |
5a5574b9 MK |
350 | The range of supported real-time signals is defined by the macros |
351 | .B SIGRTMIN | |
352 | and | |
353 | .BR SIGRTMAX . | |
354 | POSIX.1-2001 requires that an implementation support at least | |
355 | .B _POSIX_RTSIG_MAX | |
356 | (8) real-time signals. | |
357 | .PP | |
373ed9ba MK |
358 | The Linux kernel supports a range of 33 different real-time |
359 | signals, numbered 32 to 64. | |
5a5574b9 | 360 | However, the glibc POSIX threads implementation internally uses |
e0bf9127 | 361 | two (for NPTL) or three (for LinuxThreads) real-time signals |
5a5574b9 MK |
362 | (see |
363 | .BR pthreads (7)), | |
364 | and adjusts the value of | |
365 | .B SIGRTMIN | |
366 | suitably (to 34 or 35). | |
367 | Because the range of available real-time signals varies according | |
368 | to the glibc threading implementation (and this variation can occur | |
cf50118f | 369 | at run time according to the available kernel and glibc), |
008f1ecc | 370 | and indeed the range of real-time signals varies across UNIX systems, |
5a5574b9 MK |
371 | programs should |
372 | .IR "never refer to real-time signals using hard-coded numbers" , | |
373 | but instead should always refer to real-time signals using the notation | |
fea681da | 374 | .BR SIGRTMIN +n, |
e0bf9127 | 375 | and include suitable (run-time) checks that |
5a5574b9 MK |
376 | .BR SIGRTMIN +n |
377 | does not exceed | |
378 | .BR SIGRTMAX . | |
fea681da MK |
379 | .PP |
380 | Unlike standard signals, real-time signals have no predefined meanings: | |
381 | the entire set of real-time signals can be used for application-defined | |
382 | purposes. | |
fea681da MK |
383 | .PP |
384 | The default action for an unhandled real-time signal is to terminate the | |
385 | receiving process. | |
386 | .PP | |
387 | Real-time signals are distinguished by the following: | |
388 | .IP 1. 4 | |
389 | Multiple instances of real-time signals can be queued. | |
390 | By contrast, if multiple instances of a standard signal are delivered | |
391 | while that signal is currently blocked, then only one instance is queued. | |
392 | .IP 2. 4 | |
393 | If the signal is sent using | |
485ab701 | 394 | .BR sigqueue (3), |
fea681da MK |
395 | an accompanying value (either an integer or a pointer) can be sent |
396 | with the signal. | |
397 | If the receiving process establishes a handler for this signal using the | |
9fdfa163 | 398 | .B SA_SIGINFO |
fea681da | 399 | flag to |
1c1cbf3d | 400 | .BR sigaction (2), |
fea681da MK |
401 | then it can obtain this data via the |
402 | .I si_value | |
403 | field of the | |
404 | .I siginfo_t | |
405 | structure passed as the second argument to the handler. | |
406 | Furthermore, the | |
407 | .I si_pid | |
408 | and | |
409 | .I si_uid | |
410 | fields of this structure can be used to obtain the PID | |
411 | and real user ID of the process sending the signal. | |
412 | .IP 3. 4 | |
413 | Real-time signals are delivered in a guaranteed order. | |
414 | Multiple real-time signals of the same type are delivered in the order | |
415 | they were sent. | |
416 | If different real-time signals are sent to a process, they are delivered | |
417 | starting with the lowest-numbered signal. | |
418 | (I.e., low-numbered signals have highest priority.) | |
4564433c MK |
419 | By contrast, if multiple standard signals are pending for a process, |
420 | the order in which they are delivered is unspecified. | |
fea681da MK |
421 | .PP |
422 | If both standard and real-time signals are pending for a process, | |
423 | POSIX leaves it unspecified which is delivered first. | |
424 | Linux, like many other implementations, gives priority | |
425 | to standard signals in this case. | |
426 | .PP | |
427 | According to POSIX, an implementation should permit at least | |
5a5574b9 MK |
428 | .B _POSIX_SIGQUEUE_MAX |
429 | (32) real-time signals to be queued to | |
fea681da | 430 | a process. |
1c1634c0 MK |
431 | However, Linux does things differently. |
432 | In kernels up to and including 2.6.7, Linux imposes | |
fea681da MK |
433 | a system-wide limit on the number of queued real-time signals |
434 | for all processes. | |
435 | This limit can be viewed and (with privilege) changed via the | |
436 | .I /proc/sys/kernel/rtsig-max | |
437 | file. | |
438 | A related file, | |
439 | .IR /proc/sys/kernel/rtsig-nr , | |
440 | can be used to find out how many real-time signals are currently queued. | |
1c1634c0 MK |
441 | In Linux 2.6.8, these |
442 | .I /proc | |
de7e5e18 | 443 | interfaces were replaced by the |
1c1634c0 MK |
444 | .B RLIMIT_SIGPENDING |
445 | resource limit, which specifies a per-user limit for queued | |
c0722da0 | 446 | signals; see |
1c1634c0 MK |
447 | .BR setrlimit (2) |
448 | for further details. | |
530156fe MK |
449 | |
450 | The addition or real-time signals required the widening | |
451 | of the signal set structure | |
452 | .RI ( sigset_t ) | |
453 | from 32 to 64 bits. | |
454 | Consequently, various system calls were superseded by new system calls | |
455 | that supported the larger signal sets. | |
456 | The old and new system calls are as follows: | |
457 | .TS | |
458 | lb lb | |
459 | l l. | |
460 | Linux 2.0 and earlier Linux 2.2 and later | |
461 | \fBsigaction\fP(2) \fBrt_sigaction\fP(2) | |
462 | \fBsigpending\fP(2) \fBrt_sigpending\fP(2) | |
463 | \fBsigprocmask\fP(2) \fBrt_sigprocmask\fP(2) | |
464 | \fBsigreturn\fP(2) \fBrt_sigreturn\fP(2) | |
465 | \fBsigsuspend\fP(2) \fBrt_sigsuspend\fP(2) | |
466 | \fBsigtimedwait\fP(2) \fBrt_sigtimedwait\fP(2) | |
467 | .TE | |
468 | .\" | |
73d8cece | 469 | .SS Async-signal-safe functions |
e8f5dd81 | 470 | .PP |
8d4eb5f8 MK |
471 | A signal handler function must be very careful, |
472 | since processing elsewhere may be interrupted | |
74d32233 | 473 | at some arbitrary point in the execution of the program. |
e8f5dd81 MK |
474 | POSIX has the concept of "safe function". |
475 | If a signal interrupts the execution of an unsafe function, and | |
476 | .I handler | |
477 | calls an unsafe function, then the behavior of the program is undefined. | |
a574189c | 478 | |
72ee5ec2 MK |
479 | POSIX.1-2004 (also known as POSIX.1-2001 Technical Corrigendum 2) |
480 | requires an implementation to guarantee that the following | |
e8f5dd81 MK |
481 | functions can be safely called inside a signal handler: |
482 | ||
a574189c MK |
483 | .in +4 |
484 | .nf | |
485 | _Exit() | |
486 | _exit() | |
487 | abort() | |
488 | accept() | |
489 | access() | |
490 | aio_error() | |
491 | aio_return() | |
492 | aio_suspend() | |
493 | alarm() | |
494 | bind() | |
495 | cfgetispeed() | |
496 | cfgetospeed() | |
497 | cfsetispeed() | |
498 | cfsetospeed() | |
499 | chdir() | |
500 | chmod() | |
501 | chown() | |
502 | clock_gettime() | |
503 | close() | |
504 | connect() | |
505 | creat() | |
506 | dup() | |
507 | dup2() | |
508 | execle() | |
509 | execve() | |
510 | fchmod() | |
511 | fchown() | |
512 | fcntl() | |
513 | fdatasync() | |
514 | fork() | |
515 | fpathconf() | |
516 | fstat() | |
517 | fsync() | |
518 | ftruncate() | |
519 | getegid() | |
520 | geteuid() | |
521 | getgid() | |
522 | getgroups() | |
523 | getpeername() | |
524 | getpgrp() | |
525 | getpid() | |
526 | getppid() | |
527 | getsockname() | |
528 | getsockopt() | |
529 | getuid() | |
530 | kill() | |
531 | link() | |
532 | listen() | |
533 | lseek() | |
534 | lstat() | |
535 | mkdir() | |
536 | mkfifo() | |
537 | open() | |
538 | pathconf() | |
539 | pause() | |
540 | pipe() | |
541 | poll() | |
542 | posix_trace_event() | |
543 | pselect() | |
544 | raise() | |
545 | read() | |
546 | readlink() | |
547 | recv() | |
548 | recvfrom() | |
549 | recvmsg() | |
550 | rename() | |
551 | rmdir() | |
552 | select() | |
553 | sem_post() | |
554 | send() | |
555 | sendmsg() | |
556 | sendto() | |
557 | setgid() | |
558 | setpgid() | |
559 | setsid() | |
560 | setsockopt() | |
561 | setuid() | |
562 | shutdown() | |
563 | sigaction() | |
564 | sigaddset() | |
565 | sigdelset() | |
566 | sigemptyset() | |
567 | sigfillset() | |
568 | sigismember() | |
569 | signal() | |
570 | sigpause() | |
571 | sigpending() | |
572 | sigprocmask() | |
573 | sigqueue() | |
574 | sigset() | |
575 | sigsuspend() | |
576 | sleep() | |
72ee5ec2 | 577 | sockatmark() |
07d72ca8 | 578 | socket() |
a574189c MK |
579 | socketpair() |
580 | stat() | |
581 | symlink() | |
582 | sysconf() | |
583 | tcdrain() | |
584 | tcflow() | |
585 | tcflush() | |
586 | tcgetattr() | |
587 | tcgetpgrp() | |
588 | tcsendbreak() | |
589 | tcsetattr() | |
590 | tcsetpgrp() | |
591 | time() | |
592 | timer_getoverrun() | |
593 | timer_gettime() | |
594 | timer_settime() | |
595 | times() | |
596 | umask() | |
597 | uname() | |
598 | unlink() | |
599 | utime() | |
600 | wait() | |
601 | waitpid() | |
602 | write() | |
603 | .fi | |
604 | .in | |
a0f7c7d8 MK |
605 | .PP |
606 | POSIX.1-2008 removes fpathconf(), pathconf(), and sysconf() | |
607 | from the above list, and adds the following functions: | |
608 | .PP | |
609 | .in +4n | |
610 | .nf | |
611 | execl() | |
612 | execv() | |
613 | faccessat() | |
614 | fchmodat() | |
615 | fchownat() | |
616 | fexecve() | |
617 | fstatat() | |
618 | futimens() | |
619 | linkat() | |
620 | mkdirat() | |
621 | mkfifoat() | |
622 | mknod() | |
623 | mknodat() | |
624 | openat() | |
625 | readlinkat() | |
626 | renameat() | |
627 | symlinkat() | |
628 | unlinkat() | |
629 | utimensat() | |
630 | utimes() | |
631 | .fi | |
632 | .in | |
adce1084 MK |
633 | .PP |
634 | POSIX.1-2008 Technical Corrigendum 1 (2013) | |
635 | adds the following functions: | |
636 | .PP | |
637 | .in +4n | |
638 | .nf | |
639 | fchdir() | |
640 | pthread_kill() | |
641 | pthread_self() | |
642 | pthread_sigmask() | |
643 | .fi | |
644 | .in | |
c634028a | 645 | .SS Interruption of system calls and library functions by signal handlers |
72710182 MK |
646 | If a signal handler is invoked while a system call or library |
647 | function call is blocked, then either: | |
648 | .IP * 2 | |
649 | the call is automatically restarted after the signal handler returns; or | |
650 | .IP * | |
651 | the call fails with the error | |
af3c87d0 | 652 | .BR EINTR . |
72710182 MK |
653 | .PP |
654 | Which of these two behaviors occurs depends on the interface and | |
655 | whether or not the signal handler was established using the | |
af3c87d0 MK |
656 | .BR SA_RESTART |
657 | flag (see | |
658 | .BR sigaction (2)). | |
008f1ecc | 659 | The details vary across UNIX systems; |
164be4fc | 660 | below, the details for Linux. |
af3c87d0 | 661 | |
72710182 MK |
662 | If a blocked call to one of the following interfaces is interrupted |
663 | by a signal handler, then the call will be automatically restarted | |
664 | after the signal handler returns if the | |
af3c87d0 | 665 | .BR SA_RESTART |
72710182 | 666 | flag was used; otherwise the call will fail with the error |
af3c87d0 MK |
667 | .BR EINTR : |
668 | .\" The following system calls use ERESTARTSYS, | |
669 | .\" so that they are restartable | |
670 | .RS 4 | |
671 | .IP * 2 | |
672 | .BR read (2), | |
673 | .BR readv (2), | |
674 | .BR write (2), | |
675 | .BR writev (2), | |
676 | and | |
677 | .BR ioctl (2) | |
678 | calls on "slow" devices. | |
72710182 MK |
679 | A "slow" device is one where the I/O call may block for an |
680 | indefinite time, for example, a terminal, pipe, or socket. | |
72710182 MK |
681 | If an I/O call on a slow device has already transferred some |
682 | data by the time it is interrupted by a signal handler, | |
af3c87d0 MK |
683 | then the call will return a success status |
684 | (normally, the number of bytes transferred). | |
ae1c1caa MK |
685 | Note that a (local) disk is not a slow device according to this definition; |
686 | I/O operations on disk devices are not interrupted by signals. | |
af3c87d0 MK |
687 | .IP * |
688 | .BR open (2), | |
72ee5ec2 | 689 | if it can block (e.g., when opening a FIFO; see |
af3c87d0 MK |
690 | .BR fifo (7)). |
691 | .IP * | |
692 | .BR wait (2), | |
693 | .BR wait3 (2), | |
694 | .BR wait4 (2), | |
695 | .BR waitid (2), | |
696 | and | |
697 | .BR waitpid (2). | |
698 | .IP * | |
699 | Socket interfaces: | |
72710182 | 700 | .\" If a timeout (setsockopt()) is in effect on the socket, then these |
af3c87d0 MK |
701 | .\" system calls switch to using EINTR. Consequently, they and are not |
702 | .\" automatically restarted, and they show the stop/cont behavior | |
703 | .\" described below. (Verified from 2.6.26 source, and by experiment; mtk) | |
704 | .BR accept (2), | |
705 | .BR connect (2), | |
706 | .BR recv (2), | |
707 | .BR recvfrom (2), | |
88fb4f09 | 708 | .BR recvmmsg (2), |
af3c87d0 MK |
709 | .BR recvmsg (2), |
710 | .BR send (2), | |
711 | .BR sendto (2), | |
712 | and | |
4b139190 | 713 | .\" FIXME What about sendmmsg()? |
4f6d71a1 MK |
714 | .BR sendmsg (2), |
715 | unless a timeout has been set on the socket (see below). | |
af3c87d0 MK |
716 | .IP * |
717 | File locking interfaces: | |
718 | .BR flock (2) | |
719 | and | |
6f0dcebc MK |
720 | the |
721 | .BR F_SETLKW | |
722 | and | |
723 | .BR F_OFD_SETLKW | |
724 | operations of | |
af3c87d0 | 725 | .BR fcntl (2) |
af3c87d0 MK |
726 | .IP * |
727 | POSIX message queue interfaces: | |
c1667735 MK |
728 | .BR mq_receive (3), |
729 | .BR mq_timedreceive (3), | |
730 | .BR mq_send (3), | |
af3c87d0 | 731 | and |
c1667735 | 732 | .BR mq_timedsend (3). |
af3c87d0 MK |
733 | .IP * |
734 | .BR futex (2) | |
735 | .B FUTEX_WAIT | |
4b139190 MK |
736 | (since Linux 2.6.22; |
737 | .\" commit 72c1bbf308c75a136803d2d76d0e18258be14c7a | |
738 | beforehand, always failed with | |
af3c87d0 MK |
739 | .BR EINTR ). |
740 | .IP * | |
3168ff2d MK |
741 | .BR getrandom (2). |
742 | .IP * | |
d53ad479 MK |
743 | .BR pthread_mutex_lock (3), |
744 | .BR pthread_cond_wait (3), | |
745 | and related APIs. | |
746 | .IP * | |
4b139190 MK |
747 | .BR futex (2) |
748 | .BR FUTEX_WAIT_BITSET . | |
749 | .IP * | |
af3c87d0 MK |
750 | POSIX semaphore interfaces: |
751 | .BR sem_wait (3) | |
752 | and | |
753 | .BR sem_timedwait (3) | |
4b139190 MK |
754 | (since Linux 2.6.22; |
755 | .\" as a consequence of the 2.6.22 changes in the futex() implementation | |
756 | beforehand, always failed with | |
af3c87d0 MK |
757 | .BR EINTR ). |
758 | .RE | |
759 | .PP | |
760 | The following interfaces are never restarted after | |
761 | being interrupted by a signal handler, | |
762 | regardless of the use of | |
495edd81 MK |
763 | .BR SA_RESTART ; |
764 | they always fail with the error | |
765 | .B EINTR | |
766 | when interrupted by a signal handler: | |
af3c87d0 MK |
767 | .\" These are the system calls that give EINTR or ERESTARTNOHAND |
768 | .\" on interruption by a signal handler. | |
769 | .RS 4 | |
770 | .IP * 2 | |
8efc0168 MK |
771 | "Input" socket interfaces, when a timeout |
772 | .RB ( SO_RCVTIMEO ) | |
773 | has been set on the socket using | |
4f6d71a1 MK |
774 | .BR setsockopt (2): |
775 | .BR accept (2), | |
776 | .BR recv (2), | |
777 | .BR recvfrom (2), | |
88fb4f09 | 778 | .BR recvmmsg (2) |
8efc0168 | 779 | (also with a non-NULL |
88fb4f09 MK |
780 | .IR timeout |
781 | argument), | |
4f6d71a1 | 782 | and |
8efc0168 MK |
783 | .BR recvmsg (2). |
784 | .IP * | |
785 | "Output" socket interfaces, when a timeout | |
4b139190 | 786 | .RB ( SO_RCVTIMEO ) |
8efc0168 MK |
787 | has been set on the socket using |
788 | .BR setsockopt (2): | |
4f6d71a1 MK |
789 | .BR connect (2), |
790 | .BR send (2), | |
791 | .BR sendto (2), | |
792 | and | |
4b139190 | 793 | .\" FIXME What about sendmmsg()? |
8efc0168 | 794 | .BR sendmsg (2). |
4f6d71a1 | 795 | .IP * |
af3c87d0 MK |
796 | Interfaces used to wait for signals: |
797 | .BR pause (2), | |
798 | .BR sigsuspend (2), | |
743bc395 | 799 | .BR sigtimedwait (2), |
af3c87d0 MK |
800 | and |
801 | .BR sigwaitinfo (2). | |
802 | .IP * | |
803 | File descriptor multiplexing interfaces: | |
804 | .BR epoll_wait (2), | |
805 | .BR epoll_pwait (2), | |
806 | .BR poll (2), | |
807 | .BR ppoll (2), | |
808 | .BR select (2), | |
809 | and | |
810 | .BR pselect (2). | |
811 | .IP * | |
b24473a3 | 812 | System V IPC interfaces: |
af3c87d0 MK |
813 | .\" On some other systems, SA_RESTART does restart these system calls |
814 | .BR msgrcv (2), | |
815 | .BR msgsnd (2), | |
816 | .BR semop (2), | |
817 | and | |
818 | .BR semtimedop (2). | |
819 | .IP * | |
820 | Sleep interfaces: | |
821 | .BR clock_nanosleep (2), | |
822 | .BR nanosleep (2), | |
af3c87d0 MK |
823 | and |
824 | .BR usleep (3). | |
825 | .IP * | |
4b139190 MK |
826 | .BR read (2) |
827 | from an | |
828 | .BR inotify (7) | |
829 | file descriptor. | |
830 | .IP * | |
af3c87d0 MK |
831 | .BR io_getevents (2). |
832 | .RE | |
495edd81 MK |
833 | .PP |
834 | The | |
835 | .BR sleep (3) | |
836 | function is also never restarted if interrupted by a handler, | |
837 | but gives a success return: the number of seconds remaining to sleep. | |
c634028a | 838 | .SS Interruption of system calls and library functions by stop signals |
48b9ec3f MK |
839 | On Linux, even in the absence of signal handlers, |
840 | certain blocking interfaces can fail with the error | |
841 | .BR EINTR | |
842 | after the process is stopped by one of the stop signals | |
843 | and then resumed via | |
844 | .BR SIGCONT . | |
845 | This behavior is not sanctioned by POSIX.1, and doesn't occur | |
846 | on other systems. | |
847 | ||
848 | The Linux interfaces that display this behavior are: | |
849 | .RS 4 | |
850 | .IP * 2 | |
8efc0168 MK |
851 | "Input" socket interfaces, when a timeout |
852 | .RB ( SO_RCVTIMEO ) | |
853 | has been set on the socket using | |
4f6d71a1 MK |
854 | .BR setsockopt (2): |
855 | .BR accept (2), | |
856 | .BR recv (2), | |
857 | .BR recvfrom (2), | |
88fb4f09 | 858 | .BR recvmmsg (2) |
8efc0168 | 859 | (also with a non-NULL |
88fb4f09 MK |
860 | .IR timeout |
861 | argument), | |
4f6d71a1 | 862 | and |
8efc0168 MK |
863 | .BR recvmsg (2). |
864 | .IP * | |
865 | "Output" socket interfaces, when a timeout | |
4b139190 | 866 | .RB ( SO_RCVTIMEO ) |
8efc0168 MK |
867 | has been set on the socket using |
868 | .BR setsockopt (2): | |
4f6d71a1 MK |
869 | .BR connect (2), |
870 | .BR send (2), | |
871 | .BR sendto (2), | |
872 | and | |
4b139190 MK |
873 | .\" FIXME What about sendmmsg()? |
874 | .BR sendmsg (2), | |
875 | if a send timeout | |
876 | .RB ( SO_SNDTIMEO ) | |
877 | has been set. | |
4f6d71a1 | 878 | .IP * 2 |
48b9ec3f MK |
879 | .BR epoll_wait (2), |
880 | .BR epoll_pwait (2). | |
881 | .IP * | |
882 | .BR semop (2), | |
883 | .BR semtimedop (2). | |
884 | .IP * | |
885 | .BR sigtimedwait (2), | |
886 | .BR sigwaitinfo (2). | |
887 | .IP * | |
888 | .BR read (2) | |
889 | from an | |
890 | .BR inotify (7) | |
891 | file descriptor. | |
892 | .IP * | |
893 | Linux 2.6.21 and earlier: | |
894 | .BR futex (2) | |
895 | .BR FUTEX_WAIT , | |
896 | .BR sem_timedwait (3), | |
897 | .BR sem_wait (3). | |
898 | .IP * | |
899 | Linux 2.6.8 and earlier: | |
900 | .BR msgrcv (2), | |
901 | .BR msgsnd (2). | |
902 | .IP * | |
903 | Linux 2.4 and earlier: | |
904 | .BR nanosleep (2). | |
905 | .RE | |
47297adb | 906 | .SH CONFORMING TO |
495edd81 | 907 | POSIX.1, except as noted. |
d396c177 MK |
908 | .\" It must be a *very* long time since this was true: |
909 | .\" .SH BUGS | |
910 | .\" .B SIGIO | |
911 | .\" and | |
912 | .\" .B SIGLOST | |
913 | .\" have the same value. | |
914 | .\" The latter is commented out in the kernel source, but | |
915 | .\" the build process of some software still thinks that | |
916 | .\" signal 29 is | |
917 | .\" .BR SIGLOST . | |
47297adb | 918 | .SH SEE ALSO |
fea681da | 919 | .BR kill (1), |
8c69c923 | 920 | .BR getrlimit (2), |
fea681da | 921 | .BR kill (2), |
af3c87d0 | 922 | .BR killpg (2), |
d806bc05 | 923 | .BR restart_syscall (2), |
23038eae | 924 | .BR rt_sigqueueinfo (2), |
af3c87d0 MK |
925 | .BR setitimer (2), |
926 | .BR setrlimit (2), | |
927 | .BR sgetmask (2), | |
928 | .BR sigaction (2), | |
8c69c923 | 929 | .BR sigaltstack (2), |
af3c87d0 | 930 | .BR signal (2), |
058c1165 | 931 | .BR signalfd (2), |
af3c87d0 MK |
932 | .BR sigpending (2), |
933 | .BR sigprocmask (2), | |
af3c87d0 MK |
934 | .BR sigsuspend (2), |
935 | .BR sigwaitinfo (2), | |
8c69c923 | 936 | .BR abort (3), |
af3c87d0 | 937 | .BR bsd_signal (3), |
8c69c923 | 938 | .BR longjmp (3), |
ae74cd0d | 939 | .BR raise (3), |
36757dc1 | 940 | .BR pthread_sigqueue (3), |
485ab701 | 941 | .BR sigqueue (3), |
af3c87d0 | 942 | .BR sigset (3), |
8c69c923 MK |
943 | .BR sigsetops (3), |
944 | .BR sigvec (3), | |
7c85aa6b | 945 | .BR sigwait (3), |
af3c87d0 MK |
946 | .BR strsignal (3), |
947 | .BR sysv_signal (3), | |
e1a9bc1b | 948 | .BR core (5), |
4f62997d | 949 | .BR proc (5), |
cb066271 | 950 | .BR nptl (7), |
16ca4564 MK |
951 | .BR pthreads (7), |
952 | .BR sigevent (7) |