OSDN Git Service

e07f29ddb094dba29e73d08ef376f0c4c8c1fc38
[linuxjm/LDP_man-pages.git] / original / man2 / kill.2
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 2013-09-17 "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 .ad l
62 .BR kill ():
63 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
64 .ad b
65 .SH DESCRIPTION
66 The
67 .BR kill ()
68 system call
69 can be used to send any signal to any process group or process.
70 .PP
71 If \fIpid\fP is positive, then signal \fIsig\fP is sent to the
72 process with the ID specified by \fIpid\fP.
73 .PP
74 If \fIpid\fP equals 0, then \fIsig\fP is sent to every process in the
75 process group of the calling process.
76 .PP
77 If \fIpid\fP equals \-1, then \fIsig\fP is sent to every process
78 for which the calling process has permission to send signals,
79 except for process 1 (\fIinit\fP), but see below.
80 .PP
81 If \fIpid\fP is less than \-1, then \fIsig\fP is sent to every process
82 in the process group whose ID is \fI\-pid\fP.
83 .PP
84 If \fIsig\fP is 0, then no signal is sent, but error checking is still
85 performed;
86 this can be used to check for the existence of a process ID or
87 process group ID.
88
89 For a process to have permission to send a signal
90 it must either be privileged (under Linux: have the
91 .B CAP_KILL
92 capability), or the real or effective
93 user ID of the sending process must equal the real or
94 saved set-user-ID of the target process.
95 In the case of
96 .B SIGCONT
97 it suffices when the sending and receiving
98 processes belong to the same session.
99 (Historically, the rules were different; see NOTES.)
100 .SH RETURN VALUE
101 On success (at least one signal was sent), zero is returned.
102 On error, \-1 is returned, and
103 .I errno
104 is set appropriately.
105 .SH ERRORS
106 .TP
107 .B EINVAL
108 An invalid signal was specified.
109 .TP
110 .B EPERM
111 The process does not have permission to send the signal
112 to any of the target processes.
113 .TP
114 .B ESRCH
115 The pid or process group does not exist.
116 Note that an existing process might be a zombie,
117 a process which already committed termination, but
118 has not yet been
119 .BR wait (2)ed
120 for.
121 .SH CONFORMING TO
122 SVr4, 4.3BSD, POSIX.1-2001.
123 .SH NOTES
124 The only signals that can be sent to process ID 1, the
125 .I init
126 process, are those for which
127 .I init
128 has explicitly installed signal handlers.
129 This is done to assure the
130 system is not brought down accidentally.
131 .LP
132 POSIX.1-2001 requires that \fIkill(\-1,sig)\fP send \fIsig\fP
133 to all processes that the calling process may send signals to,
134 except possibly for some implementation-defined system processes.
135 Linux allows a process to signal itself, but on Linux the call
136 \fIkill(\-1,sig)\fP does not signal the calling process.
137 .LP
138 POSIX.1-2001 requires that if a process sends a signal to itself,
139 and the sending thread does not have the signal blocked,
140 and no other thread
141 has it unblocked or is waiting for it in
142 .BR sigwait (3),
143 at least one
144 unblocked signal must be delivered to the sending thread before the
145 .BR kill ()
146 returns.
147 .SS Linux notes
148 Across different kernel versions, Linux has enforced different rules
149 for the permissions required for an unprivileged process
150 to send a signal to another process.
151 .\" In the 0.* kernels things chopped and changed quite
152 .\" a bit - MTK, 24 Jul 02
153 In kernels 1.0 to 1.2.2, a signal could be sent if the
154 effective user ID of the sender matched effective user ID of the target,
155 or the real user ID of the sender matched the real user ID of the target.
156 From kernel 1.2.3 until 1.3.77, a signal could be sent if the
157 effective user ID of the sender matched either the real or effective
158 user ID of the target.
159 The current rules, which conform to POSIX.1-2001, were adopted
160 in kernel 1.3.78.
161 .SH BUGS
162 In 2.6 kernels up to and including 2.6.7,
163 there was a bug that meant that when sending signals to a process group,
164 .BR kill ()
165 failed with the error
166 .B EPERM
167 if the caller did not have permission to send the signal to \fIany\fP (rather
168 than \fIall\fP) of the members of the process group.
169 Notwithstanding this error return, the signal was still delivered
170 to all of the processes for which the caller had permission to signal.
171 .SH SEE ALSO
172 .BR _exit (2),
173 .BR killpg (2),
174 .BR signal (2),
175 .BR tkill (2),
176 .BR exit (3),
177 .BR sigqueue (3),
178 .BR capabilities (7),
179 .BR credentials (7),
180 .BR signal (7)
181 .SH COLOPHON
182 This page is part of release 3.67 of the Linux
183 .I man-pages
184 project.
185 A description of the project,
186 information about reporting bugs,
187 and the latest version of this page,
188 can be found at
189 \%http://www.kernel.org/doc/man\-pages/.