OSDN Git Service

ad25e676c75dee552a12c9a70a0e9fdaf7d5df92
[linuxjm/LDP_man-pages.git] / original / 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 2009-09-15 "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 .SH "RETURN VALUE"
100 On success (at least one signal was sent), zero is returned.
101 On error, \-1 is returned, and
102 .I errno
103 is set appropriately.
104 .SH ERRORS
105 .TP
106 .B EINVAL
107 An invalid signal was specified.
108 .TP
109 .B EPERM
110 The process does not have permission to send the signal
111 to any of the target processes.
112 .TP
113 .B ESRCH
114 The pid or process group does not exist.
115 Note that an existing process might be a zombie,
116 a process which already committed termination, but
117 has not yet been
118 .BR wait (2)ed
119 for.
120 .SH "CONFORMING TO"
121 SVr4, 4.3BSD, POSIX.1-2001.
122 .SH NOTES
123 The only signals that can be sent to process ID 1, the
124 .I init
125 process, are those for which
126 .I init
127 has explicitly installed signal handlers.
128 This is done to assure the
129 system is not brought down accidentally.
130 .LP
131 POSIX.1-2001 requires that \fIkill(\-1,sig)\fP send \fIsig\fP
132 to all processes that the calling process may send signals to,
133 except possibly for some implementation-defined system processes.
134 Linux allows a process to signal itself, but on Linux the call
135 \fIkill(\-1,sig)\fP does not signal the calling process.
136 .LP
137 POSIX.1-2001 requires that if a process sends a signal to itself,
138 and the sending thread does not have the signal blocked,
139 and no other thread
140 has it unblocked or is waiting for it in
141 .BR sigwait (3),
142 at least one
143 unblocked signal must be delivered to the sending thread before the
144 .BR kill ()
145 returns.
146 .SS "Linux Notes"
147 Across different kernel versions, Linux has enforced different rules
148 for the permissions required for an unprivileged process
149 to send a signal to another process.
150 .\" In the 0.* kernels things chopped and changed quite
151 .\" a bit - MTK, 24 Jul 02
152 In kernels 1.0 to 1.2.2, a signal could be sent if the
153 effective user ID of the sender matched that of the receiver,
154 or the real user ID of the sender matched that of the receiver.
155 From kernel 1.2.3 until 1.3.77, a signal could be sent if the
156 effective user ID of the sender matched either the real or effective
157 user ID of the receiver.
158 The current rules, which conform to POSIX.1-2001, were adopted
159 in kernel 1.3.78.
160 .SH BUGS
161 In 2.6 kernels up to and including 2.6.7,
162 there was a bug that meant that when sending signals to a process group,
163 .BR kill ()
164 failed with the error
165 .B EPERM
166 if the caller did have permission to send the signal to \fIany\fP (rather
167 than \fIall\fP) of the members of the process group.
168 Notwithstanding this error return, the signal was still delivered
169 to all of the processes for which the caller had permission to signal.
170 .SH "SEE ALSO"
171 .BR _exit (2),
172 .BR killpg (2),
173 .BR signal (2),
174 .BR sigqueue (2),
175 .BR tkill (2),
176 .BR exit (3),
177 .BR capabilities (7),
178 .BR credentials (7),
179 .BR signal (7)