244 lines
6.7 KiB
HTML
244 lines
6.7 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of KILL</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>KILL</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-10-10<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
kill - send signal to a process
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/signal.h">signal.h</A>></B>
|
|
|
|
<B>int kill(pid_t </B><I>pid</I><B>, int </B><I>sig</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
|
|
<B>kill</B>():
|
|
|
|
_POSIX_C_SOURCE
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>kill</B>()
|
|
|
|
system call
|
|
can be used to send any signal to any process group or process.
|
|
<P>
|
|
|
|
If <I>pid</I> is positive, then signal <I>sig</I> is sent to the
|
|
process with the ID specified by <I>pid</I>.
|
|
<P>
|
|
|
|
If <I>pid</I> equals 0, then <I>sig</I> is sent to every process in the
|
|
process group of the calling process.
|
|
<P>
|
|
|
|
If <I>pid</I> equals -1, then <I>sig</I> is sent to every process
|
|
for which the calling process has permission to send signals,
|
|
except for process 1 (<I>init</I>), but see below.
|
|
<P>
|
|
|
|
If <I>pid</I> is less than -1, then <I>sig</I> is sent to every process
|
|
in the process group whose ID is <I>-pid</I>.
|
|
<P>
|
|
|
|
If <I>sig</I> 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.
|
|
<P>
|
|
|
|
For a process to have permission to send a signal,
|
|
it must either be privileged (under Linux: have the
|
|
<B>CAP_KILL</B>
|
|
|
|
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
|
|
<B>SIGCONT</B>,
|
|
|
|
it suffices when the sending and receiving
|
|
processes belong to the same session.
|
|
(Historically, the rules were different; see NOTES.)
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success (at least one signal was sent), zero is returned.
|
|
On error, -1 is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
An invalid signal was specified.
|
|
<DT id="2"><B>EPERM</B>
|
|
|
|
<DD>
|
|
The calling process does not have permission to send the signal
|
|
to any of the target processes.
|
|
<DT id="3"><B>ESRCH</B>
|
|
|
|
<DD>
|
|
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
|
|
<B><A HREF="/cgi-bin/man/man2html?2+wait">wait</A></B>(2)ed
|
|
|
|
for.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The only signals that can be sent to process ID 1, the
|
|
<I>init</I>
|
|
|
|
process, are those for which
|
|
<I>init</I>
|
|
|
|
has explicitly installed signal handlers.
|
|
This is done to assure the
|
|
system is not brought down accidentally.
|
|
<P>
|
|
|
|
POSIX.1 requires that <I>kill(-1,sig)</I> send <I>sig</I>
|
|
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
|
|
<I>kill(-1,sig)</I> does not signal the calling process.
|
|
<P>
|
|
|
|
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
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sigwait">sigwait</A></B>(3),
|
|
|
|
at least one
|
|
unblocked signal must be delivered to the sending thread before the
|
|
<B>kill</B>()
|
|
|
|
returns.
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Linux notes</H3>
|
|
|
|
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.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
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,
|
|
<B>kill</B>()
|
|
|
|
failed with the error
|
|
<B>EPERM</B>
|
|
|
|
if the caller did not have permission to send the signal to <I>any</I> (rather
|
|
than <I>all</I>) 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.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+kill">kill</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+_exit">_exit</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+pidfd_send_signal">pidfd_send_signal</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+signal">signal</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+tkill">tkill</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+exit">exit</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+killpg">killpg</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+sigqueue">sigqueue</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+credentials">credentials</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="9"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="10"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="11"><A HREF="#lbAI">Linux notes</A><DD>
|
|
</DL>
|
|
<DT id="12"><A HREF="#lbAJ">BUGS</A><DD>
|
|
<DT id="13"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="14"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:33 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|