]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/kill.2
Added/updated glibc feature test macro requirements
[thirdparty/man-pages.git] / man2 / kill.2
CommitLineData
fea681da
MK
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.
c13182ef 13.\"
fea681da
MK
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.
c13182ef 21.\"
fea681da
MK
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>
305a0578 36.\" Modified 2002-07-24 by Michael Kerrisk <mtk-manpages@gmx.net>
fea681da
MK
37.\" Added note on historical rules enforced when an unprivileged process
38.\" sends a signal.
305a0578 39.\" Modified 2004-06-16 by Michael Kerrisk <mtk-manpages@gmx.net>
fea681da
MK
40.\" Added note on CAP_KILL
41.\" Modified 2004-06-24 by aeb
7f325695 42.\" Modified, 2004-11-30, after idea from emmanuel.colbus@ensimag.imag.fr
fea681da 43.\"
cc4615cc 44.TH KILL 2 2007-07-26 "Linux" "Linux Programmer's Manual"
fea681da
MK
45.SH NAME
46kill \- 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
cc4615cc
MK
55.sp
56.in -4n
57Feature 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
fea681da
MK
63.SH DESCRIPTION
64The
e511ffb6 65.BR kill ()
fea681da
MK
66system call
67can be used to send any signal to any process group or process.
68.PP
69If \fIpid\fP is positive, then signal \fIsig\fP is sent to \fIpid\fP.
70.PP
71If \fIpid\fP equals 0, then \fIsig\fP is sent to every process in the
72process group of the current process.
73.PP
30e6794a 74If \fIpid\fP equals \-1, then \fIsig\fP is sent to every process
cbc84c6e 75for which the calling process has permission to send signals,
7c1bc63f 76except for process 1 (\fIinit\fP), but see below.
fea681da
MK
77.PP
78If \fIpid\fP is less than \-1, then \fIsig\fP is sent to every process
79in the process group \fI\-pid\fP.
80.PP
81If \fIsig\fP is 0, then no signal is sent, but error checking is still
82performed.
83
84For a process to have permission to send a signal
85it must either be privileged (under Linux: have the
86.B CAP_KILL
87capability), or the real or effective
88user ID of the sending process must equal the real or
89saved set-user-ID of the target process.
8bd58774
MK
90In the case of
91.B SIGCONT
92it suffices when the sending and receiving
fea681da
MK
93processes belong to the same session.
94.SH "RETURN VALUE"
95On success (at least one signal was sent), zero is returned.
96On error, \-1 is returned, and
97.I errno
98is set appropriately.
99.SH ERRORS
100.TP
101.B EINVAL
102An invalid signal was specified.
103.TP
104.B EPERM
105The process does not have permission to send the signal
106to any of the target processes.
107.TP
108.B ESRCH
109The pid or process group does not exist.
110Note that an existing process might be a zombie,
111a process which already committed termination, but
60a90ecd
MK
112has not yet been
113.BR wait (2)ed
114for.
a1d5f77c
MK
115.SH "CONFORMING TO"
116SVr4, 4.3BSD, POSIX.1-2001
fea681da 117.SH NOTES
37d4cd1c 118The only signals that can be sent process ID 1, the
7f325695
MK
119.I init
120process, are those for which
121.I init
122has explicitly installed signal handlers.
123This is done to assure the
fea681da
MK
124system is not brought down accidentally.
125.LP
97c1eac8 126POSIX.1-2001 requires that \fIkill(\-1,sig)\fP send \fIsig\fP
fea681da
MK
127to all processes that the current process may send signals to,
128except possibly for some implementation-defined system processes.
129Linux allows a process to signal itself, but on Linux the call
8c383102 130\fIkill(\-1,sig)\fP does not signal the current process.
fea681da 131.LP
97c1eac8 132POSIX.1-2001 requires that if a process sends a signal to itself,
c13182ef 133and the sending thread does not have the signal blocked,
cbea10b3 134and no other thread
988db661 135has it unblocked or is waiting for it in
d9c1ae64
MK
136.BR sigwait (3),
137at least one
fea681da 138unblocked signal must be delivered to the sending thread before the
d9c1ae64 139.BR kill ().
4fb31341 140.SS "Linux Notes"
fea681da
MK
141Across different kernel versions, Linux has enforced different rules
142for the permissions required for an unprivileged process
143to send a signal to another process.
144.\" In the 0.* kernels things chopped and changed quite
145.\" a bit - MTK, 24 Jul 02
146In kernels 1.0 to 1.2.2, a signal could be sent if the
147effective user ID of the sender matched that of the receiver,
148or the real user ID of the sender matched that of the receiver.
149From kernel 1.2.3 until 1.3.77, a signal could be sent if the
150effective user ID of the sender matched either the real or effective
151user ID of the receiver.
97c1eac8 152The current rules, which conform to POSIX.1-2001, were adopted
fea681da 153in kernel 1.3.78.
cc171723
MK
154.SH BUGS
155In 2.6 kernels up to and including 2.6.7,
156there was a bug that meant that when sending signals to a process group,
157.BR kill ()
158failed with the error
159.B EPERM
160if the caller did have permission to send the signal to \fIany\fP (rather
161than \fIall\fP) of the members of the process group.
162Notwithstanding this error return, the signal was still delivered
163to all of the processes for which the caller had permission to signal.
fea681da
MK
164.SH "SEE ALSO"
165.BR _exit (2),
166.BR killpg (2),
167.BR signal (2),
042d7c1b 168.BR sigqueue (2),
fea681da
MK
169.BR tkill (2),
170.BR exit (3),
171.BR capabilities (7),
53a1443c 172.BR credentials (7),
fea681da 173.BR signal (7)