]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/signal.7
wfix
[thirdparty/man-pages.git] / man7 / signal.7
1 '\" t
2 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
3 .\" and Copyright (c) 2002, 2006 by Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
5 .\" <mtk.manpages@gmail.com>
6 .\"
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date. The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein. The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"
27 .\" Modified Sat Jul 24 17:34:08 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified Sun Jan 7 01:41:27 1996 by Andries Brouwer (aeb@cwi.nl)
29 .\" Modified Sun Apr 14 12:02:29 1996 by Andries Brouwer (aeb@cwi.nl)
30 .\" Modified Sat Nov 13 16:28:23 1999 by Andries Brouwer (aeb@cwi.nl)
31 .\" Modified 10 Apr 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\" Modified 7 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Added information on real-time signals
34 .\" Modified 13 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
35 .\" Noted that SIGSTKFLT is in fact unused
36 .\" 2004-12-03, Modified mtk, added notes on RLIMIT_SIGPENDING
37 .\" 2006-04-24, mtk, Added text on changing signal dispositions,
38 .\" signal mask, and pending signals.
39 .\" 2008-07-04, mtk:
40 .\" Added section on system call restarting (SA_RESTART)
41 .\" Added section on stop/cont signals interrupting syscalls.
42 .\"
43 .TH SIGNAL 7 2008-07-07 "Linux" "Linux Programmer's Manual"
44 .SH NAME
45 signal \- list of available signals
46 .SH DESCRIPTION
47 Linux supports both POSIX reliable signals (hereinafter
48 "standard signals") and POSIX real-time signals.
49 .SS "Signal Dispositions"
50 Each signal has a current
51 .IR disposition ,
52 which determines how the process behaves when it is delivered
53 the signal.
54
55 The entries in the "Action" column of the tables below specify
56 the default disposition for each signal, as follows:
57 .IP Term
58 Default action is to terminate the process.
59 .IP Ign
60 Default action is to ignore the signal.
61 .IP Core
62 Default action is to terminate the process and dump core (see
63 .BR core (5)).
64 .IP Stop
65 Default action is to stop the process.
66 .IP Cont
67 Default action is to continue the process if it is currently stopped.
68 .PP
69 A process can change the disposition of a signal using
70 .BR sigaction (2)
71 or (less portably)
72 .BR signal (2).
73 Using these system calls, a process can elect one of the
74 following behaviors to occur on delivery of the signal:
75 perform the default action; ignore the signal;
76 or catch the signal with a
77 .IR "signal handler" ,
78 a programmer-defined function that is automatically invoked
79 when the signal is delivered.
80
81 The signal disposition is a per-process attribute:
82 in a multithreaded application, the disposition of a
83 particular signal is the same for all threads.
84 .SS "Signal Mask and Pending Signals"
85 A signal may be
86 .IR blocked ,
87 which means that it will not be delivered until it is later unblocked.
88 Between the time when it is generated and when it is delivered
89 a signal is said to be
90 .IR pending .
91
92 Each thread in a process has an independent
93 .IR "signal mask" ,
94 which indicates the set of signals that the thread is currently blocking.
95 A thread can manipulate its signal mask using
96 .BR pthread_sigmask (3).
97 In a traditional single-threaded application,
98 .BR sigprocmask (2)
99 can be used to manipulate the signal mask.
100
101 A signal may be generated (and thus pending)
102 for a process as a whole (e.g., when sent using
103 .BR kill (2))
104 or for a specific thread (e.g., certain signals,
105 such as
106 .B SIGSEGV
107 and
108 .BR SIGFPE ,
109 generated as a
110 consequence of executing a specific machine-language instruction
111 are thread directed, as are signals targeted at a specific thread using
112 .BR pthread_kill (3)).
113 A process-directed signal may be delivered to any one of the
114 threads that does not currently have the signal blocked.
115 If more than one of the threads has the signal unblocked, then the
116 kernel chooses an arbitrary thread to which to deliver the signal.
117
118 A thread can obtain the set of signals that it currently has pending
119 using
120 .BR sigpending (2).
121 This set will consist of the union of the set of pending
122 process-directed signals and the set of signals pending for
123 the calling thread.
124 .SS "Standard Signals"
125 Linux supports the standard signals listed below.
126 Several signal numbers
127 are architecture-dependent, as indicated in the "Value" column.
128 (Where three values are given, the first one is usually valid for
129 alpha and sparc,
130 the middle one for ix86, ia64, ppc, s390, arm and sh,
131 and the last one for mips.
132 .\" parisc is a law unto itself
133 A \- denotes that a signal is absent on the corresponding architecture.)
134
135 First the signals described in the original POSIX.1-1990 standard.
136 .TS
137 l c c l
138 ____
139 lB c c l.
140 Signal Value Action Comment
141 SIGHUP \01 Term Hangup detected on controlling terminal
142 or death of controlling process
143 SIGINT \02 Term Interrupt from keyboard
144 SIGQUIT \03 Core Quit from keyboard
145 SIGILL \04 Core Illegal Instruction
146 SIGABRT \06 Core Abort signal from \fBabort\fP(3)
147 SIGFPE \08 Core Floating point exception
148 SIGKILL \09 Term Kill signal
149 SIGSEGV 11 Core Invalid memory reference
150 SIGPIPE 13 Term Broken pipe: write to pipe with no
151 readers
152 SIGALRM 14 Term Timer signal from \fBalarm\fP(2)
153 SIGTERM 15 Term Termination signal
154 SIGUSR1 30,10,16 Term User-defined signal 1
155 SIGUSR2 31,12,17 Term User-defined signal 2
156 SIGCHLD 20,17,18 Ign Child stopped or terminated
157 SIGCONT 19,18,25 Cont Continue if stopped
158 SIGSTOP 17,19,23 Stop Stop process
159 SIGTSTP 18,20,24 Stop Stop typed at tty
160 SIGTTIN 21,21,26 Stop tty input for background process
161 SIGTTOU 22,22,27 Stop tty output for background process
162 .TE
163
164 The signals
165 .B SIGKILL
166 and
167 .B SIGSTOP
168 cannot be caught, blocked, or ignored.
169
170 Next the signals not in the POSIX.1-1990 standard but described in
171 SUSv2 and POSIX.1-2001.
172 .TS
173 l c c l
174 ____
175 lB c c l.
176 Signal Value Action Comment
177 SIGBUS 10,7,10 Core Bus error (bad memory access)
178 SIGPOLL Term Pollable event (Sys V).
179 Synonym for \fBSIGIO\fP
180 SIGPROF 27,27,29 Term Profiling timer expired
181 SIGSYS 12,\-,12 Core Bad argument to routine (SVr4)
182 SIGTRAP 5 Core Trace/breakpoint trap
183 SIGURG 16,23,21 Ign Urgent condition on socket (4.2BSD)
184 SIGVTALRM 26,26,28 Term Virtual alarm clock (4.2BSD)
185 SIGXCPU 24,24,30 Core CPU time limit exceeded (4.2BSD)
186 SIGXFSZ 25,25,31 Core File size limit exceeded (4.2BSD)
187 .TE
188
189 Up to and including Linux 2.2, the default behavior for
190 .BR SIGSYS ", " SIGXCPU ", " SIGXFSZ ", "
191 and (on architectures other than SPARC and MIPS)
192 .B SIGBUS
193 was to terminate the process (without a core dump).
194 (On some other Unix systems the default action for
195 .BR SIGXCPU " and " SIGXFSZ
196 is to terminate the process without a core dump.)
197 Linux 2.4 conforms to the POSIX.1-2001 requirements for these signals,
198 terminating the process with a core dump.
199
200 Next various other signals.
201 .TS
202 l c c l
203 ____
204 lB c c l.
205 Signal Value Action Comment
206 SIGIOT 6 Core IOT trap. A synonym for \fBSIGABRT\fP
207 SIGEMT 7,\-,7 Term
208 SIGSTKFLT \-,16,\- Term Stack fault on coprocessor (unused)
209 SIGIO 23,29,22 Term I/O now possible (4.2BSD)
210 SIGCLD \-,\-,18 Ign A synonym for \fBSIGCHLD\fP
211 SIGPWR 29,30,19 Term Power failure (System V)
212 SIGINFO 29,\-,\- A synonym for \fBSIGPWR\fP
213 SIGLOST \-,\-,\- Term File lock lost
214 SIGWINCH 28,28,20 Ign Window resize signal (4.3BSD, Sun)
215 SIGUNUSED \-,31,\- Term Unused signal (will be \fBSIGSYS\fP)
216 .TE
217
218 (Signal 29 is
219 .B SIGINFO
220 /
221 .B SIGPWR
222 on an alpha but
223 .B SIGLOST
224 on a sparc.)
225
226 .B SIGEMT
227 is not specified in POSIX.1-2001, but nevertheless appears
228 on most other Unix systems,
229 where its default action is typically to terminate
230 the process with a core dump.
231
232 .B SIGPWR
233 (which is not specified in POSIX.1-2001) is typically ignored
234 by default on those other Unix systems where it appears.
235
236 .B SIGIO
237 (which is not specified in POSIX.1-2001) is ignored by default
238 on several other Unix systems.
239 .SS "Real-time Signals"
240 Linux supports real-time signals as originally defined in the POSIX.1b
241 real-time extensions (and now included in POSIX.1-2001).
242 The range of supported real-time signals is defined by the macros
243 .B SIGRTMIN
244 and
245 .BR SIGRTMAX .
246 POSIX.1-2001 requires that an implementation support at least
247 .B _POSIX_RTSIG_MAX
248 (8) real-time signals.
249 .PP
250 The Linux kernel supports a range of 32 different real-time
251 signals, numbered 33 to 64.
252 However, the glibc POSIX threads implementation internally uses
253 two (for NPTL) or three (for LinuxThreads) real-time signals
254 (see
255 .BR pthreads (7)),
256 and adjusts the value of
257 .B SIGRTMIN
258 suitably (to 34 or 35).
259 Because the range of available real-time signals varies according
260 to the glibc threading implementation (and this variation can occur
261 at run time according to the available kernel and glibc),
262 and indeed the range of real-time signals varies across Unix systems,
263 programs should
264 .IR "never refer to real-time signals using hard-coded numbers" ,
265 but instead should always refer to real-time signals using the notation
266 .BR SIGRTMIN +n,
267 and include suitable (run-time) checks that
268 .BR SIGRTMIN +n
269 does not exceed
270 .BR SIGRTMAX .
271 .PP
272 Unlike standard signals, real-time signals have no predefined meanings:
273 the entire set of real-time signals can be used for application-defined
274 purposes.
275 (Note, however, that the LinuxThreads implementation uses the first
276 three real-time signals.)
277 .PP
278 The default action for an unhandled real-time signal is to terminate the
279 receiving process.
280 .PP
281 Real-time signals are distinguished by the following:
282 .IP 1. 4
283 Multiple instances of real-time signals can be queued.
284 By contrast, if multiple instances of a standard signal are delivered
285 while that signal is currently blocked, then only one instance is queued.
286 .IP 2. 4
287 If the signal is sent using
288 .BR sigqueue (2),
289 an accompanying value (either an integer or a pointer) can be sent
290 with the signal.
291 If the receiving process establishes a handler for this signal using the
292 .B SA_SIGINFO
293 flag to
294 .BR sigaction (2)
295 then it can obtain this data via the
296 .I si_value
297 field of the
298 .I siginfo_t
299 structure passed as the second argument to the handler.
300 Furthermore, the
301 .I si_pid
302 and
303 .I si_uid
304 fields of this structure can be used to obtain the PID
305 and real user ID of the process sending the signal.
306 .IP 3. 4
307 Real-time signals are delivered in a guaranteed order.
308 Multiple real-time signals of the same type are delivered in the order
309 they were sent.
310 If different real-time signals are sent to a process, they are delivered
311 starting with the lowest-numbered signal.
312 (I.e., low-numbered signals have highest priority.)
313 By contrast, if multiple standard signals are pending for a process,
314 the order in which they are delivered is unspecified.
315 .PP
316 If both standard and real-time signals are pending for a process,
317 POSIX leaves it unspecified which is delivered first.
318 Linux, like many other implementations, gives priority
319 to standard signals in this case.
320 .PP
321 According to POSIX, an implementation should permit at least
322 .B _POSIX_SIGQUEUE_MAX
323 (32) real-time signals to be queued to
324 a process.
325 However, Linux does things differently.
326 In kernels up to and including 2.6.7, Linux imposes
327 a system-wide limit on the number of queued real-time signals
328 for all processes.
329 This limit can be viewed and (with privilege) changed via the
330 .I /proc/sys/kernel/rtsig-max
331 file.
332 A related file,
333 .IR /proc/sys/kernel/rtsig-nr ,
334 can be used to find out how many real-time signals are currently queued.
335 In Linux 2.6.8, these
336 .I /proc
337 interfaces were replaced by the
338 .B RLIMIT_SIGPENDING
339 resource limit, which specifies a per-user limit for queued
340 signals; see
341 .BR setrlimit (2)
342 for further details.
343 .SS "Async-signal-safe functions"
344 .PP
345 A signal handling routine established by
346 .BR sigaction (2)
347 or
348 .BR signal (2)
349 must be very careful, since processing elsewhere may be interrupted
350 at some arbitrary point in the execution of the program.
351 POSIX has the concept of "safe function".
352 If a signal interrupts the execution of an unsafe function, and
353 .I handler
354 calls an unsafe function, then the behavior of the program is undefined.
355
356 POSIX.1-2004 (also known as POSIX.1-2001 Technical Corrigendum 2)
357 requires an implementation to guarantee that the following
358 functions can be safely called inside a signal handler:
359 .\" FIXME . SUSv4 adds functions to this list, and removes a few.
360
361 .in +4
362 .nf
363 _Exit()
364 _exit()
365 abort()
366 accept()
367 access()
368 aio_error()
369 aio_return()
370 aio_suspend()
371 alarm()
372 bind()
373 cfgetispeed()
374 cfgetospeed()
375 cfsetispeed()
376 cfsetospeed()
377 chdir()
378 chmod()
379 chown()
380 clock_gettime()
381 close()
382 connect()
383 creat()
384 dup()
385 dup2()
386 execle()
387 execve()
388 fchmod()
389 fchown()
390 fcntl()
391 fdatasync()
392 fork()
393 fpathconf()
394 fstat()
395 fsync()
396 ftruncate()
397 getegid()
398 geteuid()
399 getgid()
400 getgroups()
401 getpeername()
402 getpgrp()
403 getpid()
404 getppid()
405 getsockname()
406 getsockopt()
407 getuid()
408 kill()
409 link()
410 listen()
411 lseek()
412 lstat()
413 mkdir()
414 mkfifo()
415 open()
416 pathconf()
417 pause()
418 pipe()
419 poll()
420 posix_trace_event()
421 pselect()
422 raise()
423 read()
424 readlink()
425 recv()
426 recvfrom()
427 recvmsg()
428 rename()
429 rmdir()
430 select()
431 sem_post()
432 send()
433 sendmsg()
434 sendto()
435 setgid()
436 setpgid()
437 setsid()
438 setsockopt()
439 setuid()
440 shutdown()
441 sigaction()
442 sigaddset()
443 sigdelset()
444 sigemptyset()
445 sigfillset()
446 sigismember()
447 signal()
448 sigpause()
449 sigpending()
450 sigprocmask()
451 sigqueue()
452 sigset()
453 sigsuspend()
454 sleep()
455 sockatmark()
456 socket()
457 socketpair()
458 stat()
459 symlink()
460 sysconf()
461 tcdrain()
462 tcflow()
463 tcflush()
464 tcgetattr()
465 tcgetpgrp()
466 tcsendbreak()
467 tcsetattr()
468 tcsetpgrp()
469 time()
470 timer_getoverrun()
471 timer_gettime()
472 timer_settime()
473 times()
474 umask()
475 uname()
476 unlink()
477 utime()
478 wait()
479 waitpid()
480 write()
481 .fi
482 .in
483 .SS Interruption of System Calls and Library Functions by Signal Handlers
484 If a signal handler is invoked while a system call or library
485 function call is blocked, then either:
486 .IP * 2
487 the call is automatically restarted after the signal handler returns; or
488 .IP *
489 the call fails with the error
490 .BR EINTR .
491 .PP
492 Which of these two behaviors occurs depends on the interface and
493 whether or not the signal handler was established using the
494 .BR SA_RESTART
495 flag (see
496 .BR sigaction (2)).
497 The details vary across Unix systems;
498 below, the details for Linux.
499
500 If a blocked call to one of the following interfaces is interrupted
501 by a signal handler, then the call will be automatically restarted
502 after the signal handler returns if the
503 .BR SA_RESTART
504 flag was used; otherwise the call will fail with the error
505 .BR EINTR :
506 .\" The following system calls use ERESTARTSYS,
507 .\" so that they are restartable
508 .RS 4
509 .IP * 2
510 .BR read (2),
511 .BR readv (2),
512 .BR write (2),
513 .BR writev (2),
514 and
515 .BR ioctl (2)
516 calls on "slow" devices.
517 A "slow" device is one where the I/O call may block for an
518 indefinite time, for example, a terminal, pipe, or socket.
519 (A disk is not a slow device according to this definition.)
520 If an I/O call on a slow device has already transferred some
521 data by the time it is interrupted by a signal handler,
522 then the call will return a success status
523 (normally, the number of bytes transferred).
524 .IP *
525 .BR open (2),
526 if it can block (e.g., when opening a FIFO; see
527 .BR fifo (7)).
528 .IP *
529 .BR wait (2),
530 .BR wait3 (2),
531 .BR wait4 (2),
532 .BR waitid (2),
533 and
534 .BR waitpid (2).
535 .IP *
536 Socket interfaces:
537 .\" If a timeout (setsockopt()) is in effect on the socket, then these
538 .\" system calls switch to using EINTR. Consequently, they and are not
539 .\" automatically restarted, and they show the stop/cont behavior
540 .\" described below. (Verified from 2.6.26 source, and by experiment; mtk)
541 .BR accept (2),
542 .BR connect (2),
543 .BR recv (2),
544 .BR recvfrom (2),
545 .BR recvmsg (2),
546 .BR send (2),
547 .BR sendto (2),
548 and
549 .BR sendmsg (2).
550 .IP *
551 File locking interfaces:
552 .BR flock (2)
553 and
554 .BR fcntl (2)
555 .BR F_SETLKW .
556 .IP *
557 POSIX message queue interfaces:
558 .BR mq_receive (3),
559 .BR mq_timedreceive (3),
560 .BR mq_send (3),
561 and
562 .BR mq_timedsend (3).
563 .IP *
564 .BR futex (2)
565 .B FUTEX_WAIT
566 (since Linux 2.6.22; beforehand, always failed with
567 .BR EINTR ).
568 .IP *
569 POSIX semaphore interfaces:
570 .BR sem_wait (3)
571 and
572 .BR sem_timedwait (3)
573 (since Linux 2.6.22; beforehand, always failed with
574 .BR EINTR ).
575 .RE
576 .PP
577 The following interfaces are never restarted after
578 being interrupted by a signal handler,
579 regardless of the use of
580 .BR SA_RESTART ;
581 they always fail with the error
582 .B EINTR
583 when interrupted by a signal handler:
584 .\" These are the system calls that give EINTR or ERESTARTNOHAND
585 .\" on interruption by a signal handler.
586 .RS 4
587 .IP * 2
588 Interfaces used to wait for signals:
589 .BR pause (2),
590 .BR sigsuspend (2),
591 .BR sigtimedwait (2),
592 and
593 .BR sigwaitinfo (2).
594 .IP *
595 File descriptor multiplexing interfaces:
596 .BR epoll_wait (2),
597 .BR epoll_pwait (2),
598 .BR poll (2),
599 .BR ppoll (2),
600 .BR select (2),
601 and
602 .BR pselect (2).
603 .IP *
604 System V IPC interfaces:
605 .\" On some other systems, SA_RESTART does restart these system calls
606 .BR msgrcv (2),
607 .BR msgsnd (2),
608 .BR semop (2),
609 and
610 .BR semtimedop (2).
611 .IP *
612 Sleep interfaces:
613 .BR clock_nanosleep (2),
614 .BR nanosleep (2),
615 and
616 .BR usleep (3).
617 .IP *
618 .BR read (2)
619 from an
620 .BR inotify (7)
621 file descriptor.
622 .IP *
623 .BR io_getevents (2).
624 .RE
625 .PP
626 The
627 .BR sleep (3)
628 function is also never restarted if interrupted by a handler,
629 but gives a success return: the number of seconds remaining to sleep.
630 .SS Interruption of System Calls and Library Functions by Stop Signals
631 On Linux, even in the absence of signal handlers,
632 certain blocking interfaces can fail with the error
633 .BR EINTR
634 after the process is stopped by one of the stop signals
635 and then resumed via
636 .BR SIGCONT .
637 This behavior is not sanctioned by POSIX.1, and doesn't occur
638 on other systems.
639
640 The Linux interfaces that display this behavior are:
641 .RS 4
642 .IP * 2
643 .BR epoll_wait (2),
644 .BR epoll_pwait (2).
645 .IP *
646 .BR semop (2),
647 .BR semtimedop (2).
648 .IP *
649 .BR sigtimedwait (2),
650 .BR sigwaitinfo (2).
651 .IP *
652 .BR read (2)
653 from an
654 .BR inotify (7)
655 file descriptor.
656 .IP *
657 Linux 2.6.21 and earlier:
658 .BR futex (2)
659 .BR FUTEX_WAIT ,
660 .BR sem_timedwait (3),
661 .BR sem_wait (3).
662 .IP *
663 Linux 2.6.8 and earlier:
664 .BR msgrcv (2),
665 .BR msgsnd (2).
666 .IP *
667 Linux 2.4 and earlier:
668 .BR nanosleep (2).
669 .RE
670 .SH "CONFORMING TO"
671 POSIX.1, except as noted.
672 .SH BUGS
673 .B SIGIO
674 and
675 .B SIGLOST
676 have the same value.
677 The latter is commented out in the kernel source, but
678 the build process of some software still thinks that
679 signal 29 is
680 .BR SIGLOST .
681 .SH "SEE ALSO"
682 .BR kill (1),
683 .BR getrlimit (2),
684 .BR kill (2),
685 .BR killpg (2),
686 .BR setitimer (2),
687 .BR setrlimit (2),
688 .BR sgetmask (2),
689 .BR sigaction (2),
690 .BR sigaltstack (2),
691 .BR signal (2),
692 .BR signalfd (2),
693 .BR sigpending (2),
694 .BR sigprocmask (2),
695 .BR sigqueue (2),
696 .BR sigsuspend (2),
697 .BR sigwaitinfo (2),
698 .BR abort (3),
699 .BR bsd_signal (3),
700 .BR longjmp (3),
701 .BR raise (3),
702 .BR sigset (3),
703 .BR sigsetops (3),
704 .BR sigvec (3),
705 .BR sigwait (3),
706 .BR strsignal (3),
707 .BR sysv_signal (3),
708 .BR core (5),
709 .BR proc (5),
710 .BR pthreads (7)