]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/kill.2
Relocated LINUX NOTES as subsection under NOTES
[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@gmx.net>
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@gmx.net>
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 2004-06-24 "Linux 2.6.7" "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 .SH DESCRIPTION
56 The
57 .BR kill ()
58 system call
59 can be used to send any signal to any process group or process.
60 .PP
61 If \fIpid\fP is positive, then signal \fIsig\fP is sent to \fIpid\fP.
62 .PP
63 If \fIpid\fP equals 0, then \fIsig\fP is sent to every process in the
64 process group of the current process.
65 .PP
66 If \fIpid\fP equals \-1, then \fIsig\fP is sent to every process
67 for which the calling process has permission to send signals,
68 except for process 1 (init), but see below.
69 .PP
70 If \fIpid\fP is less than \-1, then \fIsig\fP is sent to every process
71 in the process group \fI\-pid\fP.
72 .PP
73 If \fIsig\fP is 0, then no signal is sent, but error checking is still
74 performed.
75
76 For a process to have permission to send a signal
77 it must either be privileged (under Linux: have the
78 .B CAP_KILL
79 capability), or the real or effective
80 user ID of the sending process must equal the real or
81 saved set-user-ID of the target process.
82 In the case of SIGCONT it suffices when the sending and receiving
83 processes belong to the same session.
84 .SH "RETURN VALUE"
85 On success (at least one signal was sent), zero is returned.
86 On error, \-1 is returned, and
87 .I errno
88 is set appropriately.
89 .SH ERRORS
90 .TP
91 .B EINVAL
92 An invalid signal was specified.
93 .TP
94 .B EPERM
95 The process does not have permission to send the signal
96 to any of the target processes.
97 .TP
98 .B ESRCH
99 The pid or process group does not exist.
100 Note that an existing process might be a zombie,
101 a process which already committed termination, but
102 has not yet been
103 .BR wait (2)ed
104 for.
105 .SH NOTES
106 The only signals that can be sent process ID 1, the
107 .I init
108 process, are those for which
109 .I init
110 has explicitly installed signal handlers.
111 This is done to assure the
112 system is not brought down accidentally.
113 .LP
114 POSIX.1-2001 requires that \fIkill(\-1,sig)\fP send \fIsig\fP
115 to all processes that the current process may send signals to,
116 except possibly for some implementation-defined system processes.
117 Linux allows a process to signal itself, but on Linux the call
118 \fIkill(\-1,sig)\fP does not signal the current process.
119 .LP
120 POSIX.1-2001 requires that if a process sends a signal to itself,
121 and the sending thread does not have the signal blocked,
122 and no other thread
123 has it unblocked or is waiting for it in
124 .BR sigwait (3),
125 at least one
126 unblocked signal must be delivered to the sending thread before the
127 .BR kill ().
128 .SS "Linux Notes"
129 Across different kernel versions, Linux has enforced different rules
130 for the permissions required for an unprivileged process
131 to send a signal to another process.
132 .\" In the 0.* kernels things chopped and changed quite
133 .\" a bit - MTK, 24 Jul 02
134 In kernels 1.0 to 1.2.2, a signal could be sent if the
135 effective user ID of the sender matched that of the receiver,
136 or the real user ID of the sender matched that of the receiver.
137 From kernel 1.2.3 until 1.3.77, a signal could be sent if the
138 effective user ID of the sender matched either the real or effective
139 user ID of the receiver.
140 The current rules, which conform to POSIX.1-2001, were adopted
141 in kernel 1.3.78.
142 .SH BUGS
143 In 2.6 kernels up to and including 2.6.7,
144 there was a bug that meant that when sending signals to a process group,
145 .BR kill ()
146 failed with the error
147 .B EPERM
148 if the caller did have permission to send the signal to \fIany\fP (rather
149 than \fIall\fP) of the members of the process group.
150 Notwithstanding this error return, the signal was still delivered
151 to all of the processes for which the caller had permission to signal.
152 .SH "CONFORMING TO"
153 SVr4, 4.3BSD, POSIX.1-2001
154 .SH "SEE ALSO"
155 .BR _exit (2),
156 .BR killpg (2),
157 .BR signal (2),
158 .BR sigqueue (2),
159 .BR tkill (2),
160 .BR exit (3),
161 .BR capabilities (7),
162 .BR signal (7)