Blame man7/signal.7

Packit 7cfc04
'\" t
Packit 7cfc04
.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
Packit 7cfc04
.\" and Copyright (c) 2002, 2006 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\" and Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
Packit 7cfc04
.\"     <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified Sat Jul 24 17:34:08 1993 by Rik Faith (faith@cs.unc.edu)
Packit 7cfc04
.\" Modified Sun Jan  7 01:41:27 1996 by Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\" Modified Sun Apr 14 12:02:29 1996 by Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\" Modified Sat Nov 13 16:28:23 1999 by Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\" Modified 10 Apr 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\" Modified  7 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"	Added information on real-time signals
Packit 7cfc04
.\" Modified 13 Jun 2002, by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"	Noted that SIGSTKFLT is in fact unused
Packit 7cfc04
.\" 2004-12-03, Modified mtk, added notes on RLIMIT_SIGPENDING
Packit 7cfc04
.\" 2006-04-24, mtk, Added text on changing signal dispositions,
Packit 7cfc04
.\"		signal mask, and pending signals.
Packit 7cfc04
.\" 2008-07-04, mtk:
Packit 7cfc04
.\"     Added section on system call restarting (SA_RESTART)
Packit 7cfc04
.\"     Added section on stop/cont signals interrupting syscalls.
Packit 7cfc04
.\" 2008-10-05, mtk: various additions
Packit 7cfc04
.\"
Packit 7cfc04
.TH SIGNAL 7  2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
signal \- overview of signals
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
Linux supports both POSIX reliable signals (hereinafter
Packit 7cfc04
"standard signals") and POSIX real-time signals.
Packit 7cfc04
.SS Signal dispositions
Packit 7cfc04
Each signal has a current
Packit 7cfc04
.IR disposition ,
Packit 7cfc04
which determines how the process behaves when it is delivered
Packit 7cfc04
the signal.
Packit 7cfc04
.PP
Packit 7cfc04
The entries in the "Action" column of the tables below specify
Packit 7cfc04
the default disposition for each signal, as follows:
Packit 7cfc04
.IP Term
Packit 7cfc04
Default action is to terminate the process.
Packit 7cfc04
.IP Ign
Packit 7cfc04
Default action is to ignore the signal.
Packit 7cfc04
.IP Core
Packit 7cfc04
Default action is to terminate the process and dump core (see
Packit 7cfc04
.BR core (5)).
Packit 7cfc04
.IP Stop
Packit 7cfc04
Default action is to stop the process.
Packit 7cfc04
.IP Cont
Packit 7cfc04
Default action is to continue the process if it is currently stopped.
Packit 7cfc04
.PP
Packit 7cfc04
A process can change the disposition of a signal using
Packit 7cfc04
.BR sigaction (2)
Packit 7cfc04
or
Packit 7cfc04
.BR signal (2).
Packit 7cfc04
(The latter is less portable when establishing a signal handler;
Packit 7cfc04
see
Packit 7cfc04
.BR signal (2)
Packit 7cfc04
for details.)
Packit 7cfc04
Using these system calls, a process can elect one of the
Packit 7cfc04
following behaviors to occur on delivery of the signal:
Packit 7cfc04
perform the default action; ignore the signal;
Packit 7cfc04
or catch the signal with a
Packit 7cfc04
.IR "signal handler" ,
Packit 7cfc04
a programmer-defined function that is automatically invoked
Packit 7cfc04
when the signal is delivered.
Packit 7cfc04
(By default, the signal handler is invoked on the
Packit 7cfc04
normal process stack.
Packit 7cfc04
It is possible to arrange that the signal handler
Packit 7cfc04
uses an alternate stack; see
Packit 7cfc04
.BR sigaltstack (2)
Packit 7cfc04
for a discussion of how to do this and when it might be useful.)
Packit 7cfc04
.PP
Packit 7cfc04
The signal disposition is a per-process attribute:
Packit 7cfc04
in a multithreaded application, the disposition of a
Packit 7cfc04
particular signal is the same for all threads.
Packit 7cfc04
.PP
Packit 7cfc04
A child created via
Packit 7cfc04
.BR fork (2)
Packit 7cfc04
inherits a copy of its parent's signal dispositions.
Packit 7cfc04
During an
Packit 7cfc04
.BR execve (2),
Packit 7cfc04
the dispositions of handled signals are reset to the default;
Packit 7cfc04
the dispositions of ignored signals are left unchanged.
Packit 7cfc04
.SS Sending a signal
Packit 7cfc04
The following system calls and library functions allow
Packit 7cfc04
the caller to send a signal:
Packit 7cfc04
.TP 16
Packit 7cfc04
.BR raise (3)
Packit 7cfc04
Sends a signal to the calling thread.
Packit 7cfc04
.TP
Packit 7cfc04
.BR kill (2)
Packit 7cfc04
Sends a signal to a specified process,
Packit 7cfc04
to all members of a specified process group,
Packit 7cfc04
or to all processes on the system.
Packit 7cfc04
.TP
Packit 7cfc04
.BR killpg (3)
Packit 7cfc04
Sends a signal to all of the members of a specified process group.
Packit 7cfc04
.TP
Packit 7cfc04
.BR pthread_kill (3)
Packit 7cfc04
Sends a signal to a specified POSIX thread in the same process as
Packit 7cfc04
the caller.
Packit 7cfc04
.TP
Packit 7cfc04
.BR tgkill (2)
Packit 7cfc04
Sends a signal to a specified thread within a specific process.
Packit 7cfc04
(This is the system call used to implement
Packit 7cfc04
.BR pthread_kill (3).)
Packit 7cfc04
.TP
Packit 7cfc04
.BR sigqueue (3)
Packit 7cfc04
Sends a real-time signal with accompanying data to a specified process.
Packit 7cfc04
.SS Waiting for a signal to be caught
Packit 7cfc04
The following system calls suspend execution of the calling process
Packit 7cfc04
or thread until a signal is caught
Packit 7cfc04
(or an unhandled signal terminates the process):
Packit 7cfc04
.TP 16
Packit 7cfc04
.BR pause (2)
Packit 7cfc04
Suspends execution until any signal is caught.
Packit 7cfc04
.TP
Packit 7cfc04
.BR sigsuspend (2)
Packit 7cfc04
Temporarily changes the signal mask (see below) and suspends
Packit 7cfc04
execution until one of the unmasked signals is caught.
Packit 7cfc04
.SS Synchronously accepting a signal
Packit 7cfc04
Rather than asynchronously catching a signal via a signal handler,
Packit 7cfc04
it is possible to synchronously accept the signal, that is,
Packit 7cfc04
to block execution until the signal is delivered,
Packit 7cfc04
at which point the kernel returns information about the
Packit 7cfc04
signal to the caller.
Packit 7cfc04
There are two general ways to do this:
Packit 7cfc04
.IP * 2
Packit 7cfc04
.BR sigwaitinfo (2),
Packit 7cfc04
.BR sigtimedwait (2),
Packit 7cfc04
and
Packit 7cfc04
.BR sigwait (3)
Packit 7cfc04
suspend execution until one of the signals in a specified
Packit 7cfc04
set is delivered.
Packit 7cfc04
Each of these calls returns information about the delivered signal.
Packit 7cfc04
.IP *
Packit 7cfc04
.BR signalfd (2)
Packit 7cfc04
returns a file descriptor that can be used to read information
Packit 7cfc04
about signals that are delivered to the caller.
Packit 7cfc04
Each
Packit 7cfc04
.BR read (2)
Packit 7cfc04
from this file descriptor blocks until one of the signals
Packit 7cfc04
in the set specified in the
Packit 7cfc04
.BR signalfd (2)
Packit 7cfc04
call is delivered to the caller.
Packit 7cfc04
The buffer returned by
Packit 7cfc04
.BR read (2)
Packit 7cfc04
contains a structure describing the signal.
Packit 7cfc04
.SS Signal mask and pending signals
Packit 7cfc04
A signal may be
Packit 7cfc04
.IR blocked ,
Packit 7cfc04
which means that it will not be delivered until it is later unblocked.
Packit 7cfc04
Between the time when it is generated and when it is delivered
Packit 7cfc04
a signal is said to be
Packit 7cfc04
.IR pending .
Packit 7cfc04
.PP
Packit 7cfc04
Each thread in a process has an independent
Packit 7cfc04
.IR "signal mask" ,
Packit 7cfc04
which indicates the set of signals that the thread is currently blocking.
Packit 7cfc04
A thread can manipulate its signal mask using
Packit 7cfc04
.BR pthread_sigmask (3).
Packit 7cfc04
In a traditional single-threaded application,
Packit 7cfc04
.BR sigprocmask (2)
Packit 7cfc04
can be used to manipulate the signal mask.
Packit 7cfc04
.PP
Packit 7cfc04
A child created via
Packit 7cfc04
.BR fork (2)
Packit 7cfc04
inherits a copy of its parent's signal mask;
Packit 7cfc04
the signal mask is preserved across
Packit 7cfc04
.BR execve (2).
Packit 7cfc04
.PP
Packit 7cfc04
A signal may be generated (and thus pending)
Packit 7cfc04
for a process as a whole (e.g., when sent using
Packit 7cfc04
.BR kill (2))
Packit 7cfc04
or for a specific thread (e.g., certain signals,
Packit 7cfc04
such as
Packit 7cfc04
.B SIGSEGV
Packit 7cfc04
and
Packit 7cfc04
.BR SIGFPE ,
Packit 7cfc04
generated as a
Packit 7cfc04
consequence of executing a specific machine-language instruction
Packit 7cfc04
are thread directed, as are signals targeted at a specific thread using
Packit 7cfc04
.BR pthread_kill (3)).
Packit 7cfc04
A process-directed signal may be delivered to any one of the
Packit 7cfc04
threads that does not currently have the signal blocked.
Packit 7cfc04
If more than one of the threads has the signal unblocked, then the
Packit 7cfc04
kernel chooses an arbitrary thread to which to deliver the signal.
Packit 7cfc04
.PP
Packit 7cfc04
A thread can obtain the set of signals that it currently has pending
Packit 7cfc04
using
Packit 7cfc04
.BR sigpending (2).
Packit 7cfc04
This set will consist of the union of the set of pending
Packit 7cfc04
process-directed signals and the set of signals pending for
Packit 7cfc04
the calling thread.
Packit 7cfc04
.PP
Packit 7cfc04
A child created via
Packit 7cfc04
.BR fork (2)
Packit 7cfc04
initially has an empty pending signal set;
Packit 7cfc04
the pending signal set is preserved across an
Packit 7cfc04
.BR execve (2).
Packit 7cfc04
.SS Standard signals
Packit 7cfc04
Linux supports the standard signals listed below.
Packit 7cfc04
Several signal numbers
Packit 7cfc04
are architecture-dependent, as indicated in the "Value" column.
Packit 7cfc04
(Where three values are given, the first one is usually valid for
Packit 7cfc04
alpha and sparc,
Packit 7cfc04
the middle one for x86, arm, and most other architectures,
Packit 7cfc04
and the last one for mips.
Packit 7cfc04
(Values for parisc are
Packit 7cfc04
.I not
Packit 7cfc04
shown; see the Linux kernel source for signal numbering on that architecture.)
Packit 7cfc04
A dash (\-) denotes that a signal is absent on the corresponding architecture.
Packit 7cfc04
.PP
Packit 7cfc04
First the signals described in the original POSIX.1-1990 standard.
Packit 7cfc04
.TS
Packit 7cfc04
l c c l
Packit 7cfc04
____
Packit 7cfc04
lB c c l.
Packit 7cfc04
Signal	Value	Action	Comment
Packit 7cfc04
SIGHUP	\01	Term	Hangup detected on controlling terminal
Packit 7cfc04
			or death of controlling process
Packit 7cfc04
SIGINT	\02	Term	Interrupt from keyboard
Packit 7cfc04
SIGQUIT	\03	Core	Quit from keyboard
Packit 7cfc04
SIGILL	\04	Core	Illegal Instruction
Packit 7cfc04
SIGABRT	\06	Core	Abort signal from \fBabort\fP(3)
Packit 7cfc04
SIGFPE	\08	Core	Floating-point exception
Packit 7cfc04
SIGKILL	\09	Term	Kill signal
Packit 7cfc04
SIGSEGV	11	Core	Invalid memory reference
Packit 7cfc04
SIGPIPE	13	Term	Broken pipe: write to pipe with no
Packit 7cfc04
			readers; see \fBpipe\fP(7)
Packit 7cfc04
SIGALRM	14	Term	Timer signal from \fBalarm\fP(2)
Packit 7cfc04
SIGTERM	15	Term	Termination signal
Packit 7cfc04
SIGUSR1	30,10,16	Term	User-defined signal 1
Packit 7cfc04
SIGUSR2	31,12,17	Term	User-defined signal 2
Packit 7cfc04
SIGCHLD	20,17,18	Ign	Child stopped or terminated
Packit 7cfc04
SIGCONT	19,18,25	Cont	Continue if stopped
Packit 7cfc04
SIGSTOP	17,19,23	Stop	Stop process
Packit 7cfc04
SIGTSTP	18,20,24	Stop	Stop typed at terminal
Packit 7cfc04
SIGTTIN	21,21,26	Stop	Terminal input for background process
Packit 7cfc04
SIGTTOU	22,22,27	Stop	Terminal output for background process
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
The signals
Packit 7cfc04
.B SIGKILL
Packit 7cfc04
and
Packit 7cfc04
.B SIGSTOP
Packit 7cfc04
cannot be caught, blocked, or ignored.
Packit 7cfc04
.PP
Packit 7cfc04
Next the signals not in the POSIX.1-1990 standard but described in
Packit 7cfc04
SUSv2 and POSIX.1-2001.
Packit 7cfc04
.TS
Packit 7cfc04
l c c l
Packit 7cfc04
____
Packit 7cfc04
lB c c l.
Packit 7cfc04
Signal	Value	Action	Comment
Packit 7cfc04
SIGBUS	10,7,10	Core	Bus error (bad memory access)
Packit 7cfc04
SIGPOLL		Term	Pollable event (Sys V).
Packit 7cfc04
			Synonym for \fBSIGIO\fP
Packit 7cfc04
SIGPROF	27,27,29	Term	Profiling timer expired
Packit 7cfc04
SIGSYS	12,31,12	Core	Bad system call (SVr4);
Packit 7cfc04
			see also \fBseccomp\fP(2)
Packit 7cfc04
SIGTRAP	5	Core	Trace/breakpoint trap
Packit 7cfc04
SIGURG	16,23,21	Ign	Urgent condition on socket (4.2BSD)
Packit 7cfc04
SIGVTALRM	26,26,28	Term	Virtual alarm clock (4.2BSD)
Packit 7cfc04
SIGXCPU	24,24,30	Core	CPU time limit exceeded (4.2BSD);
Packit 7cfc04
			see \fBsetrlimit\fP(2)
Packit 7cfc04
SIGXFSZ	25,25,31	Core	File size limit exceeded (4.2BSD);
Packit 7cfc04
			see \fBsetrlimit\fP(2)
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
Up to and including Linux 2.2, the default behavior for
Packit 7cfc04
.BR SIGSYS ", " SIGXCPU ", " SIGXFSZ ", "
Packit 7cfc04
and (on architectures other than SPARC and MIPS)
Packit 7cfc04
.B SIGBUS
Packit 7cfc04
was to terminate the process (without a core dump).
Packit 7cfc04
(On some other UNIX systems the default action for
Packit 7cfc04
.BR SIGXCPU " and " SIGXFSZ
Packit 7cfc04
is to terminate the process without a core dump.)
Packit 7cfc04
Linux 2.4 conforms to the POSIX.1-2001 requirements for these signals,
Packit 7cfc04
terminating the process with a core dump.
Packit 7cfc04
.PP
Packit 7cfc04
Next various other signals.
Packit 7cfc04
.TS
Packit 7cfc04
l c c l
Packit 7cfc04
____
Packit 7cfc04
lB c c l.
Packit 7cfc04
Signal	Value	Action	Comment
Packit 7cfc04
SIGIOT	6	Core	IOT trap. A synonym for \fBSIGABRT\fP
Packit 7cfc04
SIGEMT	7,\-,7	Term	Emulator trap
Packit 7cfc04
SIGSTKFLT	\-,16,\-	Term	Stack fault on coprocessor (unused)
Packit 7cfc04
SIGIO	23,29,22	Term	I/O now possible (4.2BSD)
Packit 7cfc04
SIGCLD	\-,\-,18	Ign	A synonym for \fBSIGCHLD\fP
Packit 7cfc04
SIGPWR	29,30,19	Term	Power failure (System V)
Packit 7cfc04
SIGINFO	29,\-,\-		A synonym for \fBSIGPWR\fP
Packit 7cfc04
SIGLOST	\-,\-,\-	Term	File lock lost (unused)
Packit 7cfc04
SIGWINCH	28,28,20	Ign	Window resize signal (4.3BSD, Sun)
Packit 7cfc04
SIGUNUSED	\-,31,\-	Core	Synonymous with \fBSIGSYS\fP
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
(Signal 29 is
Packit 7cfc04
.B SIGINFO
Packit 7cfc04
/
Packit 7cfc04
.B SIGPWR
Packit 7cfc04
on an alpha but
Packit 7cfc04
.B SIGLOST
Packit 7cfc04
on a sparc.)
Packit 7cfc04
.PP
Packit 7cfc04
.B SIGEMT
Packit 7cfc04
is not specified in POSIX.1-2001, but nevertheless appears
Packit 7cfc04
on most other UNIX systems,
Packit 7cfc04
where its default action is typically to terminate
Packit 7cfc04
the process with a core dump.
Packit 7cfc04
.PP
Packit 7cfc04
.B SIGPWR
Packit 7cfc04
(which is not specified in POSIX.1-2001) is typically ignored
Packit 7cfc04
by default on those other UNIX systems where it appears.
Packit 7cfc04
.PP
Packit 7cfc04
.B SIGIO
Packit 7cfc04
(which is not specified in POSIX.1-2001) is ignored by default
Packit 7cfc04
on several other UNIX systems.
Packit 7cfc04
.PP
Packit 7cfc04
Where defined,
Packit 7cfc04
.B SIGUNUSED
Packit 7cfc04
is synonymous with
Packit 7cfc04
.\" parisc is the only exception: SIGSYS is 12, SIGUNUSED is 31
Packit 7cfc04
.B SIGSYS
Packit 7cfc04
on most architectures.
Packit 7cfc04
Since glibc 2.26,
Packit 7cfc04
.B SIGUNUSED
Packit 7cfc04
is no longer defined on any architecture.
Packit 7cfc04
.SS Real-time signals
Packit 7cfc04
Starting with version 2.2,
Packit 7cfc04
Linux supports real-time signals as originally defined in the POSIX.1b
Packit 7cfc04
real-time extensions (and now included in POSIX.1-2001).
Packit 7cfc04
The range of supported real-time signals is defined by the macros
Packit 7cfc04
.B SIGRTMIN
Packit 7cfc04
and
Packit 7cfc04
.BR SIGRTMAX .
Packit 7cfc04
POSIX.1-2001 requires that an implementation support at least
Packit 7cfc04
.B _POSIX_RTSIG_MAX
Packit 7cfc04
(8) real-time signals.
Packit 7cfc04
.PP
Packit 7cfc04
The Linux kernel supports a range of 33 different real-time
Packit 7cfc04
signals, numbered 32 to 64.
Packit 7cfc04
However, the glibc POSIX threads implementation internally uses
Packit 7cfc04
two (for NPTL) or three (for LinuxThreads) real-time signals
Packit 7cfc04
(see
Packit 7cfc04
.BR pthreads (7)),
Packit 7cfc04
and adjusts the value of
Packit 7cfc04
.B SIGRTMIN
Packit 7cfc04
suitably (to 34 or 35).
Packit 7cfc04
Because the range of available real-time signals varies according
Packit 7cfc04
to the glibc threading implementation (and this variation can occur
Packit 7cfc04
at run time according to the available kernel and glibc),
Packit 7cfc04
and indeed the range of real-time signals varies across UNIX systems,
Packit 7cfc04
programs should
Packit 7cfc04
.IR "never refer to real-time signals using hard-coded numbers" ,
Packit 7cfc04
but instead should always refer to real-time signals using the notation
Packit 7cfc04
.BR SIGRTMIN +n,
Packit 7cfc04
and include suitable (run-time) checks that
Packit 7cfc04
.BR SIGRTMIN +n
Packit 7cfc04
does not exceed
Packit 7cfc04
.BR SIGRTMAX .
Packit 7cfc04
.PP
Packit 7cfc04
Unlike standard signals, real-time signals have no predefined meanings:
Packit 7cfc04
the entire set of real-time signals can be used for application-defined
Packit 7cfc04
purposes.
Packit 7cfc04
.PP
Packit 7cfc04
The default action for an unhandled real-time signal is to terminate the
Packit 7cfc04
receiving process.
Packit 7cfc04
.PP
Packit 7cfc04
Real-time signals are distinguished by the following:
Packit 7cfc04
.IP 1. 4
Packit 7cfc04
Multiple instances of real-time signals can be queued.
Packit 7cfc04
By contrast, if multiple instances of a standard signal are delivered
Packit 7cfc04
while that signal is currently blocked, then only one instance is queued.
Packit 7cfc04
.IP 2. 4
Packit 7cfc04
If the signal is sent using
Packit 7cfc04
.BR sigqueue (3),
Packit 7cfc04
an accompanying value (either an integer or a pointer) can be sent
Packit 7cfc04
with the signal.
Packit 7cfc04
If the receiving process establishes a handler for this signal using the
Packit 7cfc04
.B SA_SIGINFO
Packit 7cfc04
flag to
Packit 7cfc04
.BR sigaction (2),
Packit 7cfc04
then it can obtain this data via the
Packit 7cfc04
.I si_value
Packit 7cfc04
field of the
Packit 7cfc04
.I siginfo_t
Packit 7cfc04
structure passed as the second argument to the handler.
Packit 7cfc04
Furthermore, the
Packit 7cfc04
.I si_pid
Packit 7cfc04
and
Packit 7cfc04
.I si_uid
Packit 7cfc04
fields of this structure can be used to obtain the PID
Packit 7cfc04
and real user ID of the process sending the signal.
Packit 7cfc04
.IP 3. 4
Packit 7cfc04
Real-time signals are delivered in a guaranteed order.
Packit 7cfc04
Multiple real-time signals of the same type are delivered in the order
Packit 7cfc04
they were sent.
Packit 7cfc04
If different real-time signals are sent to a process, they are delivered
Packit 7cfc04
starting with the lowest-numbered signal.
Packit 7cfc04
(I.e., low-numbered signals have highest priority.)
Packit 7cfc04
By contrast, if multiple standard signals are pending for a process,
Packit 7cfc04
the order in which they are delivered is unspecified.
Packit 7cfc04
.PP
Packit 7cfc04
If both standard and real-time signals are pending for a process,
Packit 7cfc04
POSIX leaves it unspecified which is delivered first.
Packit 7cfc04
Linux, like many other implementations, gives priority
Packit 7cfc04
to standard signals in this case.
Packit 7cfc04
.PP
Packit 7cfc04
According to POSIX, an implementation should permit at least
Packit 7cfc04
.B _POSIX_SIGQUEUE_MAX
Packit 7cfc04
(32) real-time signals to be queued to
Packit 7cfc04
a process.
Packit 7cfc04
However, Linux does things differently.
Packit 7cfc04
In kernels up to and including 2.6.7, Linux imposes
Packit 7cfc04
a system-wide limit on the number of queued real-time signals
Packit 7cfc04
for all processes.
Packit 7cfc04
This limit can be viewed and (with privilege) changed via the
Packit 7cfc04
.I /proc/sys/kernel/rtsig-max
Packit 7cfc04
file.
Packit 7cfc04
A related file,
Packit 7cfc04
.IR /proc/sys/kernel/rtsig-nr ,
Packit 7cfc04
can be used to find out how many real-time signals are currently queued.
Packit 7cfc04
In Linux 2.6.8, these
Packit 7cfc04
.I /proc
Packit 7cfc04
interfaces were replaced by the
Packit 7cfc04
.B RLIMIT_SIGPENDING
Packit 7cfc04
resource limit, which specifies a per-user limit for queued
Packit 7cfc04
signals; see
Packit 7cfc04
.BR setrlimit (2)
Packit 7cfc04
for further details.
Packit 7cfc04
.PP
Packit 7cfc04
The addition of real-time signals required the widening
Packit 7cfc04
of the signal set structure
Packit 7cfc04
.RI ( sigset_t )
Packit 7cfc04
from 32 to 64 bits.
Packit 7cfc04
Consequently, various system calls were superseded by new system calls
Packit 7cfc04
that supported the larger signal sets.
Packit 7cfc04
The old and new system calls are as follows:
Packit 7cfc04
.TS
Packit 7cfc04
lb lb
Packit 7cfc04
l l.
Packit 7cfc04
Linux 2.0 and earlier	Linux 2.2 and later
Packit 7cfc04
\fBsigaction\fP(2)	\fBrt_sigaction\fP(2)
Packit 7cfc04
\fBsigpending\fP(2)	\fBrt_sigpending\fP(2)
Packit 7cfc04
\fBsigprocmask\fP(2)	\fBrt_sigprocmask\fP(2)
Packit 7cfc04
\fBsigreturn\fP(2)	\fBrt_sigreturn\fP(2)
Packit 7cfc04
\fBsigsuspend\fP(2)	\fBrt_sigsuspend\fP(2)
Packit 7cfc04
\fBsigtimedwait\fP(2)	\fBrt_sigtimedwait\fP(2)
Packit 7cfc04
.TE
Packit 7cfc04
.\"
Packit 7cfc04
.SS Interruption of system calls and library functions by signal handlers
Packit 7cfc04
If a signal handler is invoked while a system call or library
Packit 7cfc04
function call is blocked, then either:
Packit 7cfc04
.IP * 2
Packit 7cfc04
the call is automatically restarted after the signal handler returns; or
Packit 7cfc04
.IP *
Packit 7cfc04
the call fails with the error
Packit 7cfc04
.BR EINTR .
Packit 7cfc04
.PP
Packit 7cfc04
Which of these two behaviors occurs depends on the interface and
Packit 7cfc04
whether or not the signal handler was established using the
Packit 7cfc04
.BR SA_RESTART
Packit 7cfc04
flag (see
Packit 7cfc04
.BR sigaction (2)).
Packit 7cfc04
The details vary across UNIX systems;
Packit 7cfc04
below, the details for Linux.
Packit 7cfc04
.PP
Packit 7cfc04
If a blocked call to one of the following interfaces is interrupted
Packit 7cfc04
by a signal handler, then the call is automatically restarted
Packit 7cfc04
after the signal handler returns if the
Packit 7cfc04
.BR SA_RESTART
Packit 7cfc04
flag was used; otherwise the call fails with the error
Packit 7cfc04
.BR EINTR :
Packit 7cfc04
.\" The following system calls use ERESTARTSYS,
Packit 7cfc04
.\" so that they are restartable
Packit 7cfc04
.IP * 2
Packit 7cfc04
.BR read (2),
Packit 7cfc04
.BR readv (2),
Packit 7cfc04
.BR write (2),
Packit 7cfc04
.BR writev (2),
Packit 7cfc04
and
Packit 7cfc04
.BR ioctl (2)
Packit 7cfc04
calls on "slow" devices.
Packit 7cfc04
A "slow" device is one where the I/O call may block for an
Packit 7cfc04
indefinite time, for example, a terminal, pipe, or socket.
Packit 7cfc04
If an I/O call on a slow device has already transferred some
Packit 7cfc04
data by the time it is interrupted by a signal handler,
Packit 7cfc04
then the call will return a success status
Packit 7cfc04
(normally, the number of bytes transferred).
Packit 7cfc04
Note that a (local) disk is not a slow device according to this definition;
Packit 7cfc04
I/O operations on disk devices are not interrupted by signals.
Packit 7cfc04
.IP *
Packit 7cfc04
.BR open (2),
Packit 7cfc04
if it can block (e.g., when opening a FIFO; see
Packit 7cfc04
.BR fifo (7)).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR wait (2),
Packit 7cfc04
.BR wait3 (2),
Packit 7cfc04
.BR wait4 (2),
Packit 7cfc04
.BR waitid (2),
Packit 7cfc04
and
Packit 7cfc04
.BR waitpid (2).
Packit 7cfc04
.IP *
Packit 7cfc04
Socket interfaces:
Packit 7cfc04
.\" If a timeout (setsockopt()) is in effect on the socket, then these
Packit 7cfc04
.\" system calls switch to using EINTR.  Consequently, they and are not
Packit 7cfc04
.\" automatically restarted, and they show the stop/cont behavior
Packit 7cfc04
.\" described below.  (Verified from 2.6.26 source, and by experiment; mtk)
Packit 7cfc04
.BR accept (2),
Packit 7cfc04
.BR connect (2),
Packit 7cfc04
.BR recv (2),
Packit 7cfc04
.BR recvfrom (2),
Packit 7cfc04
.BR recvmmsg (2),
Packit 7cfc04
.BR recvmsg (2),
Packit 7cfc04
.BR send (2),
Packit 7cfc04
.BR sendto (2),
Packit 7cfc04
and
Packit 7cfc04
.BR sendmsg (2),
Packit 7cfc04
.\" FIXME What about sendmmsg()?
Packit 7cfc04
unless a timeout has been set on the socket (see below).
Packit 7cfc04
.IP *
Packit 7cfc04
File locking interfaces:
Packit 7cfc04
.BR flock (2)
Packit 7cfc04
and
Packit 7cfc04
the
Packit 7cfc04
.BR F_SETLKW
Packit 7cfc04
and
Packit 7cfc04
.BR F_OFD_SETLKW
Packit 7cfc04
operations of
Packit 7cfc04
.BR fcntl (2)
Packit 7cfc04
.IP *
Packit 7cfc04
POSIX message queue interfaces:
Packit 7cfc04
.BR mq_receive (3),
Packit 7cfc04
.BR mq_timedreceive (3),
Packit 7cfc04
.BR mq_send (3),
Packit 7cfc04
and
Packit 7cfc04
.BR mq_timedsend (3).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR futex (2)
Packit 7cfc04
.B FUTEX_WAIT
Packit 7cfc04
(since Linux 2.6.22;
Packit 7cfc04
.\" commit 72c1bbf308c75a136803d2d76d0e18258be14c7a
Packit 7cfc04
beforehand, always failed with
Packit 7cfc04
.BR EINTR ).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR getrandom (2).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR pthread_mutex_lock (3),
Packit 7cfc04
.BR pthread_cond_wait (3),
Packit 7cfc04
and related APIs.
Packit 7cfc04
.IP *
Packit 7cfc04
.BR futex (2)
Packit 7cfc04
.BR FUTEX_WAIT_BITSET .
Packit 7cfc04
.IP *
Packit 7cfc04
POSIX semaphore interfaces:
Packit 7cfc04
.BR sem_wait (3)
Packit 7cfc04
and
Packit 7cfc04
.BR sem_timedwait (3)
Packit 7cfc04
(since Linux 2.6.22;
Packit 7cfc04
.\" as a consequence of the 2.6.22 changes in the futex() implementation
Packit 7cfc04
beforehand, always failed with
Packit 7cfc04
.BR EINTR ).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR read (2)
Packit 7cfc04
from an
Packit 7cfc04
.BR inotify (7)
Packit 7cfc04
file descriptor
Packit 7cfc04
(since Linux 3.8;
Packit 7cfc04
.\" commit 1ca39ab9d21ac93f94b9e3eb364ea9a5cf2aba06
Packit 7cfc04
beforehand, always failed with
Packit 7cfc04
.BR EINTR ).
Packit 7cfc04
.PP
Packit 7cfc04
The following interfaces are never restarted after
Packit 7cfc04
being interrupted by a signal handler,
Packit 7cfc04
regardless of the use of
Packit 7cfc04
.BR SA_RESTART ;
Packit 7cfc04
they always fail with the error
Packit 7cfc04
.B EINTR
Packit 7cfc04
when interrupted by a signal handler:
Packit 7cfc04
.\" These are the system calls that give EINTR or ERESTARTNOHAND
Packit 7cfc04
.\" on interruption by a signal handler.
Packit 7cfc04
.IP * 2
Packit 7cfc04
"Input" socket interfaces, when a timeout
Packit 7cfc04
.RB ( SO_RCVTIMEO )
Packit 7cfc04
has been set on the socket using
Packit 7cfc04
.BR setsockopt (2):
Packit 7cfc04
.BR accept (2),
Packit 7cfc04
.BR recv (2),
Packit 7cfc04
.BR recvfrom (2),
Packit 7cfc04
.BR recvmmsg (2)
Packit 7cfc04
(also with a non-NULL
Packit 7cfc04
.IR timeout
Packit 7cfc04
argument),
Packit 7cfc04
and
Packit 7cfc04
.BR recvmsg (2).
Packit 7cfc04
.IP *
Packit 7cfc04
"Output" socket interfaces, when a timeout
Packit 7cfc04
.RB ( SO_RCVTIMEO )
Packit 7cfc04
has been set on the socket using
Packit 7cfc04
.BR setsockopt (2):
Packit 7cfc04
.BR connect (2),
Packit 7cfc04
.BR send (2),
Packit 7cfc04
.BR sendto (2),
Packit 7cfc04
and
Packit 7cfc04
.BR sendmsg (2).
Packit 7cfc04
.\" FIXME What about sendmmsg()?
Packit 7cfc04
.IP *
Packit 7cfc04
Interfaces used to wait for signals:
Packit 7cfc04
.BR pause (2),
Packit 7cfc04
.BR sigsuspend (2),
Packit 7cfc04
.BR sigtimedwait (2),
Packit 7cfc04
and
Packit 7cfc04
.BR sigwaitinfo (2).
Packit 7cfc04
.IP *
Packit 7cfc04
File descriptor multiplexing interfaces:
Packit 7cfc04
.BR epoll_wait (2),
Packit 7cfc04
.BR epoll_pwait (2),
Packit 7cfc04
.BR poll (2),
Packit 7cfc04
.BR ppoll (2),
Packit 7cfc04
.BR select (2),
Packit 7cfc04
and
Packit 7cfc04
.BR pselect (2).
Packit 7cfc04
.IP *
Packit 7cfc04
System V IPC interfaces:
Packit 7cfc04
.\" On some other systems, SA_RESTART does restart these system calls
Packit 7cfc04
.BR msgrcv (2),
Packit 7cfc04
.BR msgsnd (2),
Packit 7cfc04
.BR semop (2),
Packit 7cfc04
and
Packit 7cfc04
.BR semtimedop (2).
Packit 7cfc04
.IP *
Packit 7cfc04
Sleep interfaces:
Packit 7cfc04
.BR clock_nanosleep (2),
Packit 7cfc04
.BR nanosleep (2),
Packit 7cfc04
and
Packit 7cfc04
.BR usleep (3).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR io_getevents (2).
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR sleep (3)
Packit 7cfc04
function is also never restarted if interrupted by a handler,
Packit 7cfc04
but gives a success return: the number of seconds remaining to sleep.
Packit 7cfc04
.SS Interruption of system calls and library functions by stop signals
Packit 7cfc04
On Linux, even in the absence of signal handlers,
Packit 7cfc04
certain blocking interfaces can fail with the error
Packit 7cfc04
.BR EINTR
Packit 7cfc04
after the process is stopped by one of the stop signals
Packit 7cfc04
and then resumed via
Packit 7cfc04
.BR SIGCONT .
Packit 7cfc04
This behavior is not sanctioned by POSIX.1, and doesn't occur
Packit 7cfc04
on other systems.
Packit 7cfc04
.PP
Packit 7cfc04
The Linux interfaces that display this behavior are:
Packit 7cfc04
.IP * 2
Packit 7cfc04
"Input" socket interfaces, when a timeout
Packit 7cfc04
.RB ( SO_RCVTIMEO )
Packit 7cfc04
has been set on the socket using
Packit 7cfc04
.BR setsockopt (2):
Packit 7cfc04
.BR accept (2),
Packit 7cfc04
.BR recv (2),
Packit 7cfc04
.BR recvfrom (2),
Packit 7cfc04
.BR recvmmsg (2)
Packit 7cfc04
(also with a non-NULL
Packit 7cfc04
.IR timeout
Packit 7cfc04
argument),
Packit 7cfc04
and
Packit 7cfc04
.BR recvmsg (2).
Packit 7cfc04
.IP *
Packit 7cfc04
"Output" socket interfaces, when a timeout
Packit 7cfc04
.RB ( SO_RCVTIMEO )
Packit 7cfc04
has been set on the socket using
Packit 7cfc04
.BR setsockopt (2):
Packit 7cfc04
.BR connect (2),
Packit 7cfc04
.BR send (2),
Packit 7cfc04
.BR sendto (2),
Packit 7cfc04
and
Packit 7cfc04
.\" FIXME What about sendmmsg()?
Packit 7cfc04
.BR sendmsg (2),
Packit 7cfc04
if a send timeout
Packit 7cfc04
.RB ( SO_SNDTIMEO )
Packit 7cfc04
has been set.
Packit 7cfc04
.IP * 2
Packit 7cfc04
.BR epoll_wait (2),
Packit 7cfc04
.BR epoll_pwait (2).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR semop (2),
Packit 7cfc04
.BR semtimedop (2).
Packit 7cfc04
.IP *
Packit 7cfc04
.BR sigtimedwait (2),
Packit 7cfc04
.BR sigwaitinfo (2).
Packit 7cfc04
.IP *
Packit 7cfc04
Linux 3.7 and earlier:
Packit 7cfc04
.BR read (2)
Packit 7cfc04
from an
Packit 7cfc04
.BR inotify (7)
Packit 7cfc04
file descriptor
Packit 7cfc04
.\" commit 1ca39ab9d21ac93f94b9e3eb364ea9a5cf2aba06
Packit 7cfc04
.IP *
Packit 7cfc04
Linux 2.6.21 and earlier:
Packit 7cfc04
.BR futex (2)
Packit 7cfc04
.BR FUTEX_WAIT ,
Packit 7cfc04
.BR sem_timedwait (3),
Packit 7cfc04
.BR sem_wait (3).
Packit 7cfc04
.IP *
Packit 7cfc04
Linux 2.6.8 and earlier:
Packit 7cfc04
.BR msgrcv (2),
Packit 7cfc04
.BR msgsnd (2).
Packit 7cfc04
.IP *
Packit 7cfc04
Linux 2.4 and earlier:
Packit 7cfc04
.BR nanosleep (2).
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1, except as noted.
Packit 7cfc04
.\" It must be a *very* long time since this was true:
Packit 7cfc04
.\" .SH BUGS
Packit 7cfc04
.\" .B SIGIO
Packit 7cfc04
.\" and
Packit 7cfc04
.\" .B SIGLOST
Packit 7cfc04
.\" have the same value.
Packit 7cfc04
.\" The latter is commented out in the kernel source, but
Packit 7cfc04
.\" the build process of some software still thinks that
Packit 7cfc04
.\" signal 29 is
Packit 7cfc04
.\" .BR SIGLOST .
Packit 7cfc04
.SH NOTES
Packit 7cfc04
For a discussion of async-signal-safe functions, see
Packit 7cfc04
.BR signal-safety (7).
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR kill (1),
Packit 7cfc04
.BR getrlimit (2),
Packit 7cfc04
.BR kill (2),
Packit 7cfc04
.BR restart_syscall (2),
Packit 7cfc04
.BR rt_sigqueueinfo (2),
Packit 7cfc04
.BR setitimer (2),
Packit 7cfc04
.BR setrlimit (2),
Packit 7cfc04
.BR sgetmask (2),
Packit 7cfc04
.BR sigaction (2),
Packit 7cfc04
.BR sigaltstack (2),
Packit 7cfc04
.BR signal (2),
Packit 7cfc04
.BR signalfd (2),
Packit 7cfc04
.BR sigpending (2),
Packit 7cfc04
.BR sigprocmask (2),
Packit 7cfc04
.BR sigreturn (2),
Packit 7cfc04
.BR sigsuspend (2),
Packit 7cfc04
.BR sigwaitinfo (2),
Packit 7cfc04
.BR abort (3),
Packit 7cfc04
.BR bsd_signal (3),
Packit 7cfc04
.BR killpg (3),
Packit 7cfc04
.BR longjmp (3),
Packit 7cfc04
.BR pthread_sigqueue (3),
Packit 7cfc04
.BR raise (3),
Packit 7cfc04
.BR sigqueue (3),
Packit 7cfc04
.BR sigset (3),
Packit 7cfc04
.BR sigsetops (3),
Packit 7cfc04
.BR sigvec (3),
Packit 7cfc04
.BR sigwait (3),
Packit 7cfc04
.BR strsignal (3),
Packit 7cfc04
.BR sysv_signal (3),
Packit 7cfc04
.BR core (5),
Packit 7cfc04
.BR proc (5),
Packit 7cfc04
.BR nptl (7),
Packit 7cfc04
.BR pthreads (7),
Packit 7cfc04
.BR sigevent (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.