readv2: Note preadv2(..., RWF_NOWAIT) bug in BUGS section
[man-pages.git] / man2 / kill.2
blob23d9ce5339f0f00106ac9ecd6c5211963784fc1b
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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.
12 .\"
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.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
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>
36 .\" Modified 2002-07-24 by Michael Kerrisk <mtk.manpages@gmail.com>
37 .\"     Added note on historical rules enforced when an unprivileged process
38 .\"     sends a signal.
39 .\" Modified 2004-06-16 by Michael Kerrisk <mtk.manpages@gmail.com>
40 .\"     Added note on CAP_KILL
41 .\" Modified 2004-06-24 by aeb
42 .\" Modified, 2004-11-30, after idea from emmanuel.colbus@ensimag.imag.fr
43 .\"
44 .TH KILL 2 2021-03-22 "Linux" "Linux Programmer's Manual"
45 .SH NAME
46 kill \- send signal to a process
47 .SH SYNOPSIS
48 .nf
49 .B #include <signal.h>
50 .PP
51 .BI "int kill(pid_t " pid ", int " sig );
52 .fi
53 .PP
54 .RS -4
55 Feature Test Macro Requirements for glibc (see
56 .BR feature_test_macros (7)):
57 .RE
58 .PP
59 .BR kill ():
60 .nf
61     _POSIX_C_SOURCE
62 .fi
63 .SH DESCRIPTION
64 The
65 .BR kill ()
66 system call
67 can be used to send any signal to any process group or process.
68 .PP
69 If \fIpid\fP is positive, then signal \fIsig\fP is sent to the
70 process with the ID specified by \fIpid\fP.
71 .PP
72 If \fIpid\fP equals 0, then \fIsig\fP is sent to every process in the
73 process group of the calling process.
74 .PP
75 If \fIpid\fP equals \-1, then \fIsig\fP is sent to every process
76 for which the calling process has permission to send signals,
77 except for process 1 (\fIinit\fP), but see below.
78 .PP
79 If \fIpid\fP is less than \-1, then \fIsig\fP is sent to every process
80 in the process group whose ID is \fI\-pid\fP.
81 .PP
82 If \fIsig\fP is 0, then no signal is sent,
83 but existence and permission checks are still performed;
84 this can be used to check for the existence of a process ID or
85 process group ID that the caller is permitted to signal.
86 .PP
87 For a process to have permission to send a signal,
88 it must either be privileged (under Linux: have the
89 .B CAP_KILL
90 capability in the user namespace of the target process),
91 or the real or effective user ID of the sending process must equal
92 the real or saved set-user-ID of the target process.
93 In the case of
94 .BR SIGCONT ,
95 it suffices when the sending and receiving
96 processes belong to the same session.
97 (Historically, the rules were different; see NOTES.)
98 .SH RETURN VALUE
99 On success (at least one signal was sent), zero is returned.
100 On error, \-1 is returned, and
101 .I errno
102 is set to indicate the error.
103 .SH ERRORS
105 .B EINVAL
106 An invalid signal was specified.
108 .B EPERM
109 The calling process does not have permission to send the signal
110 to any of the target processes.
112 .B ESRCH
113 The target process or process group does not exist.
114 Note that an existing process might be a zombie,
115 a process that has terminated execution, but
116 has not yet been
117 .BR wait (2)ed
118 for.
119 .SH CONFORMING TO
120 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
121 .SH NOTES
122 The only signals that can be sent to process ID 1, the
123 .I init
124 process, are those for which
125 .I init
126 has explicitly installed signal handlers.
127 This is done to assure the
128 system is not brought down accidentally.
130 POSIX.1 requires that \fIkill(\-1,sig)\fP send \fIsig\fP
131 to all processes that the calling process may send signals to,
132 except possibly for some implementation-defined system processes.
133 Linux allows a process to signal itself, but on Linux the call
134 \fIkill(\-1,sig)\fP does not signal the calling process.
136 POSIX.1 requires that if a process sends a signal to itself,
137 and the sending thread does not have the signal blocked,
138 and no other thread
139 has it unblocked or is waiting for it in
140 .BR sigwait (3),
141 at least one
142 unblocked signal must be delivered to the sending thread before the
143 .BR kill ()
144 returns.
145 .SS Linux notes
146 Across different kernel versions, Linux has enforced different rules
147 for the permissions required for an unprivileged process
148 to send a signal to another process.
149 .\" In the 0.* kernels things chopped and changed quite
150 .\" a bit - MTK, 24 Jul 02
151 In kernels 1.0 to 1.2.2, a signal could be sent if the
152 effective user ID of the sender matched effective user ID of the target,
153 or the real user ID of the sender matched the real user ID of the target.
154 From kernel 1.2.3 until 1.3.77, a signal could be sent if the
155 effective user ID of the sender matched either the real or effective
156 user ID of the target.
157 The current rules, which conform to POSIX.1, were adopted
158 in kernel 1.3.78.
159 .SH BUGS
160 In 2.6 kernels up to and including 2.6.7,
161 there was a bug that meant that when sending signals to a process group,
162 .BR kill ()
163 failed with the error
164 .B EPERM
165 if the caller did not have permission to send the signal to \fIany\fP (rather
166 than \fIall\fP) of the members of the process group.
167 Notwithstanding this error return, the signal was still delivered
168 to all of the processes for which the caller had permission to signal.
169 .SH SEE ALSO
170 .BR kill (1),
171 .BR _exit (2),
172 .BR pidfd_send_signal (2),
173 .BR signal (2),
174 .BR tkill (2),
175 .BR exit (3),
176 .BR killpg (3),
177 .BR sigqueue (3),
178 .BR capabilities (7),
179 .BR credentials (7),
180 .BR signal (7)