| 1 |
.\" Copyright 1992, Drew Eckhardt <[email protected]> |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH kill 2 2026-02-11 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
kill \- send signal to a process |
| 9 |
.SH LIBRARY |
| 10 |
Standard C library |
| 11 |
.RI ( libc ,\~ \-lc ) |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.B #include <signal.h> |
| 15 |
.P |
| 16 |
.BI "int kill(pid_t " pid ", int " sig ); |
| 17 |
.fi |
| 18 |
.P |
| 19 |
.RS -4 |
| 20 |
Feature Test Macro Requirements for glibc (see |
| 21 |
.BR feature_test_macros (7)): |
| 22 |
.RE |
| 23 |
.P |
| 24 |
.BR kill (): |
| 25 |
.nf |
| 26 |
_POSIX_C_SOURCE |
| 27 |
.fi |
| 28 |
.SH DESCRIPTION |
| 29 |
The |
| 30 |
.BR kill () |
| 31 |
system call |
| 32 |
can be used to send any signal to any process group or process. |
| 33 |
.P |
| 34 |
If |
| 35 |
.I pid |
| 36 |
is positive, |
| 37 |
then signal |
| 38 |
.I sig |
| 39 |
is sent to |
| 40 |
the process with the ID specified by |
| 41 |
.IR pid . |
| 42 |
.P |
| 43 |
If |
| 44 |
.I pid |
| 45 |
equals 0, |
| 46 |
then |
| 47 |
.I sig |
| 48 |
is sent to |
| 49 |
every process in |
| 50 |
the process group of the calling process. |
| 51 |
.P |
| 52 |
If |
| 53 |
.I pid |
| 54 |
equals \-1, |
| 55 |
then |
| 56 |
.I sig |
| 57 |
is sent to |
| 58 |
every process for which |
| 59 |
the calling process has permission to send signals, |
| 60 |
except for process 1 |
| 61 |
.RI ( init ), |
| 62 |
but see below. |
| 63 |
.P |
| 64 |
If |
| 65 |
.I pid |
| 66 |
is less than \-1, |
| 67 |
then |
| 68 |
.I sig |
| 69 |
is sent to |
| 70 |
every process in |
| 71 |
the process group whose ID is |
| 72 |
.IR \-pid . |
| 73 |
.P |
| 74 |
If |
| 75 |
.I sig |
| 76 |
is 0, |
| 77 |
then no signal is sent, |
| 78 |
but existence and permission checks are still performed; |
| 79 |
this can be used to |
| 80 |
check for the existence of |
| 81 |
a process ID or process group ID that the caller is permitted to signal. |
| 82 |
.P |
| 83 |
For a process to have permission to send a signal, |
| 84 |
it must either be privileged (under Linux: have the |
| 85 |
.B CAP_KILL |
| 86 |
capability in the user namespace of the target process), |
| 87 |
or the real or effective user ID of the sending process must equal |
| 88 |
the real or saved set-user-ID of the target process. |
| 89 |
In the case of |
| 90 |
.BR SIGCONT , |
| 91 |
it suffices when the sending and receiving |
| 92 |
processes belong to the same session. |
| 93 |
(Historically, |
| 94 |
the rules were different; |
| 95 |
see HISTORY.) |
| 96 |
.SH RETURN VALUE |
| 97 |
On success, zero is returned. |
| 98 |
If signals were sent to a process group, |
| 99 |
success means that at least one signal was delivered. |
| 100 |
On error, \-1 is returned, and |
| 101 |
.I errno |
| 102 |
is set to indicate the error. |
| 103 |
.SH ERRORS |
| 104 |
.TP |
| 105 |
.B EINVAL |
| 106 |
An invalid signal was specified. |
| 107 |
.TP |
| 108 |
.B EPERM |
| 109 |
The calling process does not have permission to send the signal |
| 110 |
to any of the target processes. |
| 111 |
.TP |
| 112 |
.B ESRCH |
| 113 |
The target process or process group does not exist. |
| 114 |
Note that an existing process might be a zombie, |
| 115 |
a process that has terminated execution, but |
| 116 |
has not yet been |
| 117 |
.BR wait (2)ed |
| 118 |
for. |
| 119 |
.SH STANDARDS |
| 120 |
POSIX.1-2024. |
| 121 |
.SH HISTORY |
| 122 |
4.3BSD, |
| 123 |
SVr4, |
| 124 |
POSIX.1-1988. |
| 125 |
.SS Linux notes |
| 126 |
Across different kernel versions, Linux has enforced different rules |
| 127 |
for the permissions required for an unprivileged process |
| 128 |
to send a signal to another process. |
| 129 |
.\" In the 0.* kernels things chopped and changed quite |
| 130 |
.\" a bit - MTK, 24 Jul 02 |
| 131 |
In Linux 1.0 to 1.2.2, a signal could be sent if the |
| 132 |
effective user ID of the sender matched effective user ID of the target, |
| 133 |
or the real user ID of the sender matched the real user ID of the target. |
| 134 |
From Linux 1.2.3 until 1.3.77, a signal could be sent if the |
| 135 |
effective user ID of the sender matched either the real or effective |
| 136 |
user ID of the target. |
| 137 |
The current rules, which conform to POSIX.1, were adopted |
| 138 |
in Linux 1.3.78. |
| 139 |
.SH NOTES |
| 140 |
The only signals that can be sent to process ID 1, the |
| 141 |
.I init |
| 142 |
process, are those for which |
| 143 |
.I init |
| 144 |
has explicitly installed signal handlers. |
| 145 |
This is done to assure the |
| 146 |
system is not brought down accidentally. |
| 147 |
.P |
| 148 |
POSIX.1 requires that |
| 149 |
.I kill(\-1,sig) |
| 150 |
send |
| 151 |
.I sig |
| 152 |
to all processes that the calling process may send signals to, |
| 153 |
except possibly for some implementation-defined system processes. |
| 154 |
Linux allows a process to signal itself, |
| 155 |
but on Linux the call |
| 156 |
.I kill(\-1,sig) |
| 157 |
does not signal the calling process. |
| 158 |
.P |
| 159 |
POSIX.1 requires that if a process sends a signal to itself, |
| 160 |
and the sending thread does not have the signal blocked, |
| 161 |
and no other thread |
| 162 |
has it unblocked or is waiting for it in |
| 163 |
.BR sigwait (3), |
| 164 |
at least one |
| 165 |
unblocked signal must be delivered to the sending thread before the |
| 166 |
.BR kill () |
| 167 |
returns. |
| 168 |
.SH BUGS |
| 169 |
In Linux 2.6 up to and including Linux 2.6.7, |
| 170 |
there was a bug that meant that when sending signals to a process group, |
| 171 |
.BR kill () |
| 172 |
failed with the error |
| 173 |
.B EPERM |
| 174 |
if the caller did not have permission to send the signal to |
| 175 |
.I any |
| 176 |
(rather than |
| 177 |
.IR all ) |
| 178 |
of the members of the process group. |
| 179 |
Notwithstanding this error return, the signal was still delivered |
| 180 |
to all of the processes for which the caller had permission to signal. |
| 181 |
.SH SEE ALSO |
| 182 |
.BR kill (1), |
| 183 |
.BR _exit (2), |
| 184 |
.BR pidfd_send_signal (2), |
| 185 |
.BR signal (2), |
| 186 |
.BR tkill (2), |
| 187 |
.BR exit (3), |
| 188 |
.BR killpg (3), |
| 189 |
.BR sigqueue (3), |
| 190 |
.BR capabilities (7), |
| 191 |
.BR credentials (7), |
| 192 |
.BR signal (7) |