Section (1) kill
Name
kill — terminate a process
Synopsis
kill
[ −
signal | −s
signal | −p
] [ −q
value ] [−a
] [−−
] pid | name...
kill
−l
[number] | −L
DESCRIPTION
The command kill sends the specified
signal
to the
specified processes or process groups.
If no signal is specified, the TERM signal is sent. The default action for this signal is to terminate the process. This signal should be used in preference to the KILL signal (number 9), since a process may install a handler for the TERM signal in order to perform clean-up steps before terminating in an orderly fashion. If a process does not terminate after a TERM signal has been sent, then the KILL signal may be used; be aware that the latter signal cannot be caught, and so does not give the target process the opportunity to perform any clean-up before terminating.
Most modern shells have a builtin kill command, with a
usage rather similar to that of the command described here.
The −−all
,
−−pid
, and
−−queue
options, and
the possibility to specify processes by command name, are
local extensions.
If signal
is 0,
then no actual signal is sent, but error checking is still
performed.
ARGUMENTS
The list of processes to be signaled can be a mixture of names and PIDs.
pid
-
Each
pid
can be one of four things:n
-
where
n
is larger than 0. The process with PIDn
is signaled. 0
-
All processes in the current process group are signaled.
- -1
-
All processes with a PID larger than 1 are signaled.
−n
-
where
n
is larger than 1. All processes in process groupn
are signaled. When an argument of the form _zsingle_quotesz_-n_zsingle_quotesz_ is given, and it is meant to denote a process group, either a signal must be specified first, or the argument must be preceded by a _zsingle_quotesz_--_zsingle_quotesz_ option, otherwise it will be taken as the signal to send.
name
-
All processes invoked using this
name
will be signaled.
OPTIONS
−s
,−−signal
signal
-
The signal to send. It may be given as a name or a number.
−l
,−−list
[number
]-
Print a list of signal names, or convert the given signal number to a name. The signals can be found in
/usr/include/linux/signal.h
−L
,−−table
-
Similar to
−l
, but it will print signal names and their corresponding numbers. −a
,−−all
-
Do not restrict the command-name-to-PID conversion to processes with the same UID as the present process.
−p
,−−pid
-
Only print the process ID (PID) of the named processes, do not send any signals.
−−verbose
-
Print PID(s) that will be signaled with kill along with the signal.
−q
,−−queue
value
-
Use sigqueue(3) rather than kill(2). The
value
argument is an integer that is sent along with the signal. If the receiving process has installed a handler for this signal using theSA_SIGINFO
flag to sigaction(2), then it can obtain this data via the si_sigval field of the siginfo_t structure.
NOTES
Although it is possible to specify the TID (thread ID, see
gettid(2)) of one of the
threads in a multithreaded process as the argument of
kill, the
signal is nevertheless directed to the process (i.e., the
entire thread group). In other words, it is not possible to
send a signal to an explicitly selected thread in a
multithreaded process. The signal will be delivered to an
arbitrarily selected thread in the target process that is not
blocking the signal. For more details, see signal(7) and the
description of CLONE_THREAD
in
clone(2).
RETURN CODES
kill has the following return codes:
0
-
success
1
-
failure
64
-
partial success (when more than one process specified)
AVAILABILITY
The kill command is part of the util-linux package and is available from Linux Kernel Archive
Copyright 1994 Salvatore Valente (svalentemit.edu) Copyright 1992 Rickard E. Faith (faithcs.unc.edu) May be distributed under the GNU General Public License |
Section (2) kill
Name
kill — send signal to a process
Synopsis
#include <sys/types.h> #include <signal.h>
int
kill( |
pid_t pid, |
int sig) ; |
![]() |
Note | ||
---|---|---|---|
|
DESCRIPTION
The kill
() system call can
be used to send any signal to any process group or
process.
If pid
is
positive, then signal sig
is sent to the process with
the ID specified by pid
.
If pid
equals 0,
then sig
is sent to
every process in the process group of the calling
process.
If pid
equals
−1, then sig
is
sent to every process for which the calling process has
permission to send signals, except for process 1 (init
), but see below.
If pid
is less
than −1, then sig
is sent to every process in
the process group whose ID is −pid
.
If sig
is 0, then
no signal is sent, but existence and permission checks are
still performed; this can be used to check for the existence
of a process ID or process group ID that the caller is
permitted to signal.
For a process to have permission to send a signal, it must
either be privileged (under Linux: have the CAP_KILL
capability in the user namespace
of the target process), or the real or effective user ID of
the sending process must equal the real or saved set-user-ID
of the target process. In the case of SIGCONT
, it suffices when the sending and
receiving processes belong to the same session.
(Historically, the rules were different; see NOTES.)
RETURN VALUE
On success (at least one signal was sent), zero is
returned. On error, −1 is returned, and errno
is set appropriately.
ERRORS
- EINVAL
-
An invalid signal was specified.
- EPERM
-
The calling process does not have permission to send the signal to any of the target processes.
- ESRCH
-
The target process or process group does not exist. Note that an existing process might be a zombie, a process that has terminated execution, but has not yet been wait(2)ed for.
NOTES
The only signals that can be sent to process ID 1, the
init
process, are
those for which init
has explicitly installed
signal handlers. This is done to assure the system is not
brought down accidentally.
POSIX.1 requires that kill(−1,sig)
send
sig
to all processes
that the calling process may send signals to, except possibly
for some implementation-defined system processes. Linux
allows a process to signal itself, but on Linux the call
kill(−1,sig)
does not signal the calling process.
POSIX.1 requires that if a process sends a signal to
itself, and the sending thread does not have the signal
blocked, and no other thread has it unblocked or is waiting
for it in sigwait(3), at least one
unblocked signal must be delivered to the sending thread
before the kill
() returns.
Linux notes
Across different kernel versions, Linux has enforced different rules for the permissions required for an unprivileged process to send a signal to another process. In kernels 1.0 to 1.2.2, a signal could be sent if the effective user ID of the sender matched effective user ID of the target, or the real user ID of the sender matched the real user ID of the target. From kernel 1.2.3 until 1.3.77, a signal could be sent if the effective user ID of the sender matched either the real or effective user ID of the target. The current rules, which conform to POSIX.1, were adopted in kernel 1.3.78.
BUGS
In 2.6 kernels up to and including 2.6.7, there was a bug
that meant that when sending signals to a process group,
kill
() failed with the error
EPERM if the caller did not
have permission to send the signal to any
(rather than all
) of the members of the
process group. Notwithstanding this error return, the signal
was still delivered to all of the processes for which the
caller had permission to signal.
SEE ALSO
kill(1), _exit(2), pidfd_send_signal(2), signal(2), tkill(2), exit(3), killpg(3), sigqueue(3), capabilities(7), credentials(7), signal(7)
COLOPHON
This page is part of release 5.04 of the Linux man-pages
project. A
description of the project, information about reporting bugs,
and the latest version of this page, can be found at
https://www.kernel.org/doc/man−pages/.
Copyright (c) 1992 Drew Eckhardt (drewcs.colorado.edu), March 28, 1992 %%%LICENSE_START(VERBATIM) Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Since the Linux kernel and libraries are constantly changing, this manual page may be incorrect or out-of-date. The author(s) assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. The author(s) may not have taken the same level of care in the production of this manual, which is licensed free of charge, as they might when working professionally. Formatted or processed versions of this manual, if unaccompanied by the source, must acknowledge the copyright and authors of this work. %%%LICENSE_END Modified by Michael Haardt <michaelmoria.de> Modified by Thomas Koenig <ig25rz.uni-karlsruhe.de> Modified 1993-07-23 by Rik Faith <faithcs.unc.edu> Modified 1993-07-25 by Rik Faith <faithcs.unc.edu> Modified 1995-11-01 by Michael Haardt <michaelcantor.informatik.rwth-aachen.de> Modified 1996-04-14 by Andries Brouwer <aebcwi.nl> [added some polishing contributed by Mike Battersby <mibdeakin.edu.au>] Modified 1996-07-21 by Andries Brouwer <aebcwi.nl> Modified 1997-01-17 by Andries Brouwer <aebcwi.nl> Modified 2001-12-18 by Andries Brouwer <aebcwi.nl> Modified 2002-07-24 by Michael Kerrisk <mtk.manpagesgmail.com> Added note on historical rules enforced when an unprivileged process sends a signal. Modified 2004-06-16 by Michael Kerrisk <mtk.manpagesgmail.com> Added note on CAP_KILL Modified 2004-06-24 by aeb Modified, 2004-11-30, after idea from emmanuel.colbusensimag.imag.fr |