]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/kill.2
Even when the CONFORMING TO section is just a list of standards,
[thirdparty/man-pages.git] / man2 / kill.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
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 2008-04-18 "Linux" "Linux Programmer's Manual"
45 .SH NAME
46 kill \- 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
55 .sp
56 .in -4n
57 Feature Test Macro Requirements for glibc (see
58 .BR feature_test_macros (7)):
59 .in
60 .sp
61 .BR kill ():
62 _POSIX_C_SOURCE || _XOPEN_SOURCE
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, but error checking is still
83 performed;
84 this can be used to check for the existence of a process ID or
85 process group ID.
86
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), or the real or effective
91 user ID of the sending process must equal the real or
92 saved set-user-ID of the target process.
93 In the case of
94 .B SIGCONT
95 it suffices when the sending and receiving
96 processes belong to the same session.
97 .SH "RETURN VALUE"
98 On success (at least one signal was sent), zero is returned.
99 On error, \-1 is returned, and
100 .I errno
101 is set appropriately.
102 .SH ERRORS
103 .TP
104 .B EINVAL
105 An invalid signal was specified.
106 .TP
107 .B EPERM
108 The process does not have permission to send the signal
109 to any of the target processes.
110 .TP
111 .B ESRCH
112 The pid or process group does not exist.
113 Note that an existing process might be a zombie,
114 a process which already committed termination, but
115 has not yet been
116 .BR wait (2)ed
117 for.
118 .SH "CONFORMING TO"
119 SVr4, 4.3BSD, POSIX.1-2001.
120 .SH NOTES
121 The only signals that can be sent to process ID 1, the
122 .I init
123 process, are those for which
124 .I init
125 has explicitly installed signal handlers.
126 This is done to assure the
127 system is not brought down accidentally.
128 .LP
129 POSIX.1-2001 requires that \fIkill(\-1,sig)\fP send \fIsig\fP
130 to all processes that the calling process may send signals to,
131 except possibly for some implementation-defined system processes.
132 Linux allows a process to signal itself, but on Linux the call
133 \fIkill(\-1,sig)\fP does not signal the calling process.
134 .LP
135 POSIX.1-2001 requires that if a process sends a signal to itself,
136 and the sending thread does not have the signal blocked,
137 and no other thread
138 has it unblocked or is waiting for it in
139 .BR sigwait (3),
140 at least one
141 unblocked signal must be delivered to the sending thread before the
142 .BR kill ().
143 .SS "Linux Notes"
144 Across different kernel versions, Linux has enforced different rules
145 for the permissions required for an unprivileged process
146 to send a signal to another process.
147 .\" In the 0.* kernels things chopped and changed quite
148 .\" a bit - MTK, 24 Jul 02
149 In kernels 1.0 to 1.2.2, a signal could be sent if the
150 effective user ID of the sender matched that of the receiver,
151 or the real user ID of the sender matched that of the receiver.
152 From kernel 1.2.3 until 1.3.77, a signal could be sent if the
153 effective user ID of the sender matched either the real or effective
154 user ID of the receiver.
155 The current rules, which conform to POSIX.1-2001, were adopted
156 in kernel 1.3.78.
157 .SH BUGS
158 In 2.6 kernels up to and including 2.6.7,
159 there was a bug that meant that when sending signals to a process group,
160 .BR kill ()
161 failed with the error
162 .B EPERM
163 if the caller did have permission to send the signal to \fIany\fP (rather
164 than \fIall\fP) of the members of the process group.
165 Notwithstanding this error return, the signal was still delivered
166 to all of the processes for which the caller had permission to signal.
167 .SH "SEE ALSO"
168 .BR _exit (2),
169 .BR killpg (2),
170 .BR signal (2),
171 .BR sigqueue (2),
172 .BR tkill (2),
173 .BR exit (3),
174 .BR capabilities (7),
175 .BR credentials (7),
176 .BR signal (7)