]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/kill.2
fuse.4: ffix
[thirdparty/man-pages.git] / man2 / kill.2
CommitLineData
fea681da
MK
1.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
c13182ef 12.\"
fea681da
MK
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" Modified by Michael Haardt <michael@moria.de>
26.\" Modified by Thomas Koenig <ig25@rz.uni-karlsruhe.de>
27.\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
28.\" Modified 1993-07-25 by Rik Faith <faith@cs.unc.edu>
29.\" Modified 1995-11-01 by Michael Haardt
30.\" <michael@cantor.informatik.rwth-aachen.de>
31.\" Modified 1996-04-14 by Andries Brouwer <aeb@cwi.nl>
32.\" [added some polishing contributed by Mike Battersby <mib@deakin.edu.au>]
33.\" Modified 1996-07-21 by Andries Brouwer <aeb@cwi.nl>
34.\" Modified 1997-01-17 by Andries Brouwer <aeb@cwi.nl>
35.\" Modified 2001-12-18 by Andries Brouwer <aeb@cwi.nl>
c11b1abf 36.\" Modified 2002-07-24 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
37.\" Added note on historical rules enforced when an unprivileged process
38.\" sends a signal.
c11b1abf 39.\" Modified 2004-06-16 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
40.\" Added note on CAP_KILL
41.\" Modified 2004-06-24 by aeb
7f325695 42.\" Modified, 2004-11-30, after idea from emmanuel.colbus@ensimag.imag.fr
fea681da 43.\"
3df541c0 44.TH KILL 2 2016-07-17 "Linux" "Linux Programmer's Manual"
fea681da
MK
45.SH NAME
46kill \- send signal to a process
47.SH SYNOPSIS
48.nf
49.B #include <sys/types.h>
50.br
51.B #include <signal.h>
52.sp
53.BI "int kill(pid_t " pid ", int " sig );
54.fi
cc4615cc
MK
55.sp
56.in -4n
57Feature Test Macro Requirements for glibc (see
58.BR feature_test_macros (7)):
59.in
60.sp
0f200f07 61.ad l
cc4615cc 62.BR kill ():
cff459de 63_POSIX_C_SOURCE
0f200f07 64.ad b
fea681da
MK
65.SH DESCRIPTION
66The
e511ffb6 67.BR kill ()
fea681da
MK
68system call
69can be used to send any signal to any process group or process.
70.PP
0527ad7f
MK
71If \fIpid\fP is positive, then signal \fIsig\fP is sent to the
72process with the ID specified by \fIpid\fP.
fea681da
MK
73.PP
74If \fIpid\fP equals 0, then \fIsig\fP is sent to every process in the
a1ffe9f5 75process group of the calling process.
fea681da 76.PP
30e6794a 77If \fIpid\fP equals \-1, then \fIsig\fP is sent to every process
cbc84c6e 78for which the calling process has permission to send signals,
7c1bc63f 79except for process 1 (\fIinit\fP), but see below.
fea681da
MK
80.PP
81If \fIpid\fP is less than \-1, then \fIsig\fP is sent to every process
0527ad7f 82in the process group whose ID is \fI\-pid\fP.
fea681da 83.PP
a9562222
MK
84If \fIsig\fP is 0, then no signal is sent,
85but existence and permission checks are still performed;
0527ad7f 86this can be used to check for the existence of a process ID or
a9562222 87process group ID that the caller is permitted to signal.
fea681da 88
7de07913 89For a process to have permission to send a signal,
fea681da
MK
90it must either be privileged (under Linux: have the
91.B CAP_KILL
1b1ebece 92capability in the user namespace of the target process),
a3547072
MK
93or the real or effective user ID of the sending process must equal
94the real or saved set-user-ID of the target process.
8bd58774 95In the case of
097ccd1a 96.BR SIGCONT ,
8bd58774 97it suffices when the sending and receiving
fea681da 98processes belong to the same session.
9e3859ed 99(Historically, the rules were different; see NOTES.)
47297adb 100.SH RETURN VALUE
fea681da
MK
101On success (at least one signal was sent), zero is returned.
102On error, \-1 is returned, and
103.I errno
104is set appropriately.
105.SH ERRORS
106.TP
107.B EINVAL
108An invalid signal was specified.
109.TP
110.B EPERM
111The process does not have permission to send the signal
112to any of the target processes.
113.TP
114.B ESRCH
0a58b1ae 115The process or process group does not exist.
fea681da 116Note that an existing process might be a zombie,
67453c5a 117a process that has terminated execution, but
60a90ecd
MK
118has not yet been
119.BR wait (2)ed
120for.
47297adb 121.SH CONFORMING TO
80f75fab 122POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
fea681da 123.SH NOTES
f92154be 124The only signals that can be sent to process ID 1, the
7f325695
MK
125.I init
126process, are those for which
127.I init
128has explicitly installed signal handlers.
129This is done to assure the
fea681da
MK
130system is not brought down accidentally.
131.LP
80f75fab 132POSIX.1 requires that \fIkill(\-1,sig)\fP send \fIsig\fP
a1ffe9f5 133to all processes that the calling process may send signals to,
fea681da
MK
134except possibly for some implementation-defined system processes.
135Linux allows a process to signal itself, but on Linux the call
a1ffe9f5 136\fIkill(\-1,sig)\fP does not signal the calling process.
fea681da 137.LP
80f75fab 138POSIX.1 requires that if a process sends a signal to itself,
c13182ef 139and the sending thread does not have the signal blocked,
cbea10b3 140and no other thread
988db661 141has it unblocked or is waiting for it in
d9c1ae64
MK
142.BR sigwait (3),
143at least one
fea681da 144unblocked signal must be delivered to the sending thread before the
3392d76d
MK
145.BR kill ()
146returns.
73d8cece 147.SS Linux notes
fea681da
MK
148Across different kernel versions, Linux has enforced different rules
149for the permissions required for an unprivileged process
150to send a signal to another process.
151.\" In the 0.* kernels things chopped and changed quite
152.\" a bit - MTK, 24 Jul 02
153In kernels 1.0 to 1.2.2, a signal could be sent if the
9e3859ed
MK
154effective user ID of the sender matched effective user ID of the target,
155or the real user ID of the sender matched the real user ID of the target.
fea681da
MK
156From kernel 1.2.3 until 1.3.77, a signal could be sent if the
157effective user ID of the sender matched either the real or effective
9e3859ed 158user ID of the target.
80f75fab 159The current rules, which conform to POSIX.1, were adopted
fea681da 160in kernel 1.3.78.
cc171723
MK
161.SH BUGS
162In 2.6 kernels up to and including 2.6.7,
163there was a bug that meant that when sending signals to a process group,
164.BR kill ()
165failed with the error
166.B EPERM
b57b23a5 167if the caller did not have permission to send the signal to \fIany\fP (rather
cc171723
MK
168than \fIall\fP) of the members of the process group.
169Notwithstanding this error return, the signal was still delivered
170to all of the processes for which the caller had permission to signal.
47297adb 171.SH SEE ALSO
0c28210e 172.BR kill (1),
fea681da 173.BR _exit (2),
fea681da
MK
174.BR signal (2),
175.BR tkill (2),
176.BR exit (3),
498aad50 177.BR killpg (3),
485ab701 178.BR sigqueue (3),
fea681da 179.BR capabilities (7),
53a1443c 180.BR credentials (7),
fea681da 181.BR signal (7)