Files
oldlinux-files/Ref-docs/POSIX/susv3/utilities/kill.html
2024-02-19 00:21:47 -05:00

503 lines
18 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>kill</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="kill"></a> <a name="tag_04_72"></a><!-- kill -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_04_72_01"></a>NAME</h4>
<blockquote>kill - terminate or signal processes</blockquote>
<h4><a name="tag_04_72_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>kill -s</tt> <i>signal_name pid</i> <tt>...<br>
<br>
kill -l</tt> <b>[</b><i>exit_status</i><b>]</b><tt><br>
<br>
</tt></code></p>
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> kill</tt> <b>[</b><tt>-</tt><i>signal_name</i><b>]</b> <i>pid</i> <tt>...<br>
<br>
kill</tt> <b>[</b><tt>-</tt><i>signal_number</i><b>]</b> <i>pid</i> <tt>... <img src="../images/opt-end.gif" alt="[Option End]"
border="0"></tt></code></div>
<tt><br>
</tt></blockquote>
<h4><a name="tag_04_72_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>kill</i> utility shall send a signal to the process or processes specified by each <i>pid</i> operand.</p>
<p>For each <i>pid</i> operand, the <i>kill</i> utility shall perform actions equivalent to the <a href=
"../functions/kill.html"><i>kill</i>()</a> function defined in the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001
called with the following arguments:</p>
<ul>
<li>
<p>The value of the <i>pid</i> operand shall be used as the <i>pid</i> argument.</p>
</li>
<li>
<p>The <i>sig</i> argument is the value specified by the <b>-s</b> option, <b>-</b> <i>signal_number</i> option, or the <b>-</b>
<i>signal_name</i> option, or by SIGTERM, if none of these options is specified.</p>
</li>
</ul>
</blockquote>
<h4><a name="tag_04_72_04"></a>OPTIONS</h4>
<blockquote>
<p>The <i>kill</i> utility shall conform to the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>, <sup>[<a href=
"javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> &nbsp;except that
in the last two SYNOPSIS forms, the <b>-</b> <i>signal_number</i> and <b>-</b> <i>signal_name</i> options are usually more than a
single character. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
<p>The following options shall be supported:</p>
<dl compact>
<dt><b>-l</b></dt>
<dd>(The letter ell.) Write all values of <i>signal_name</i> supported by the implementation, if no operand is given. If an
<i>exit_status</i> operand is given and it is a value of the <tt>'?'</tt> shell special parameter (see <a href=
"xcu_chap02.html#tag_02_05_02"><i>Special Parameters</i></a> and <a href="wait.html"><i>wait</i>()</a> ) corresponding to a process
that was terminated by a signal, the <i>signal_name</i> corresponding to the signal that terminated the process shall be written.
If an <i>exit_status</i> operand is given and it is the unsigned decimal integer value of a signal number, the <i>signal_name</i>
(the symbolic constant name without the <b>SIG</b> prefix defined in the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001)
corresponding to that signal shall be written. Otherwise, the results are unspecified.</dd>
<dt><b>-s&nbsp;</b> <i>signal_name</i></dt>
<dd><br>
Specify the signal to send, using one of the symbolic names defined in the <a href=
"../basedefs/signal.h.html"><i>&lt;signal.h&gt;</i></a> header. Values of <i>signal_name</i> shall be recognized in a
case-independent fashion, without the <b>SIG</b> prefix. In addition, the symbolic name 0 shall be recognized, representing the
signal value zero. The corresponding signal shall be sent instead of SIGTERM.</dd>
<dt><b>-</b><i>signal_name</i></dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border=
"0"><br>
Equivalent to <b>-s</b> <i>signal_name</i>. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
<dt><b>-</b><i>signal_number</i></dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border=
"0"><br>
Specify a non-negative decimal integer, <i>signal_number</i>, representing the signal to be used instead of SIGTERM, as the
<i>sig</i> argument in the effective call to <a href="../functions/kill.html"><i>kill</i>()</a>. The correspondence between integer
values and the <i>sig</i> value used is shown in the following table.
<p>The effects of specifying any <i>signal_number</i> other than those listed in the table are undefined. <img src=
"../images/opt-end.gif" alt="[Option End]" border="0"></p>
</dd>
</dl>
<br>
<table border="1" cellpadding="3">
<tr valign="top">
<th align="center">
<p class="tent"><i>signal_number</i></p>
</th>
<th align="center">
<p class="tent"><b><i>sig</i> Value</b></p>
</th>
</tr>
<tr valign="top">
<td align="left">
<p class="tent"><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"
border="0"> 0</p>
</td>
<td align="left">
<p class="tent">0</p>
</td>
</tr>
<tr valign="top">
<td align="left">
<p class="tent">1</p>
</td>
<td align="left">
<p class="tent">SIGHUP</p>
</td>
</tr>
<tr valign="top">
<td align="left">
<p class="tent">2</p>
</td>
<td align="left">
<p class="tent">SIGINT</p>
</td>
</tr>
<tr valign="top">
<td align="left">
<p class="tent">3</p>
</td>
<td align="left">
<p class="tent">SIGQUIT</p>
</td>
</tr>
<tr valign="top">
<td align="left">
<p class="tent">6</p>
</td>
<td align="left">
<p class="tent">SIGABRT</p>
</td>
</tr>
<tr valign="top">
<td align="left">
<p class="tent">9</p>
</td>
<td align="left">
<p class="tent">SIGKILL</p>
</td>
</tr>
<tr valign="top">
<td align="left">
<p class="tent">14</p>
</td>
<td align="left">
<p class="tent">SIGALRM</p>
</td>
</tr>
<tr valign="top">
<td align="left">
<p class="tent">15</p>
</td>
<td align="left">
<p class="tent">SIGTERM</p>
</td>
</tr>
</table>
<p>If the first argument is a negative integer, it shall be interpreted as a <b>-</b> <i>signal_number</i> option, not as a
negative <i>pid</i> operand specifying a process group. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
</blockquote>
<h4><a name="tag_04_72_05"></a>OPERANDS</h4>
<blockquote>
<p>The following operands shall be supported:</p>
<dl compact>
<dt><i>pid</i></dt>
<dd>One of the following:
<ol>
<li>
<p>A decimal integer specifying a process or process group to be signaled. The process or processes selected by positive, negative,
and zero values of the <i>pid</i> operand shall be as described for the <a href="../functions/kill.html"><i>kill</i>()</a>
function. If process number 0 is specified, all processes in the current process group shall be signaled. For the effects of
negative <i>pid</i> numbers, see the <a href="../functions/kill.html"><i>kill</i>()</a> function defined in the System Interfaces
volume of IEEE&nbsp;Std&nbsp;1003.1-2001. If the first <i>pid</i> operand is negative, it should be preceded by <tt>"--"</tt> to
keep it from being interpreted as an option.</p>
</li>
<li>
<p>A job control job ID (see the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap03.html#tag_03_203">Section 3.203, Job Control Job ID</a>) that identifies a background process group to be
signaled. The job control job ID notation is applicable only for invocations of <i>kill</i> in the current shell execution
environment; see <a href="xcu_chap02.html#tag_02_12"><i>Shell Execution Environment</i></a> .</p>
</li>
</ol>
</dd>
<dt><i>exit_status</i></dt>
<dd>A decimal integer specifying a signal number or the exit status of a process terminated by a signal.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_72_06"></a>STDIN</h4>
<blockquote>
<p>Not used.</p>
</blockquote>
<h4><a name="tag_04_72_07"></a>INPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_72_08"></a>ENVIRONMENT VARIABLES</h4>
<blockquote>
<p>The following environment variables shall affect the execution of <i>kill</i>:</p>
<dl compact>
<dt><i>LANG</i></dt>
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
<dt><i>LC_ALL</i></dt>
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
<dt><i>LC_CTYPE</i></dt>
<dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
opposed to multi-byte characters in arguments).</dd>
<dt><i>LC_MESSAGES</i></dt>
<dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard
error.</dd>
<dt><i>NLSPATH</i></dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
"[Option End]" border="0"></dd>
</dl>
</blockquote>
<h4><a name="tag_04_72_09"></a>ASYNCHRONOUS EVENTS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<h4><a name="tag_04_72_10"></a>STDOUT</h4>
<blockquote>
<p>When the <b>-l</b> option is not specified, the standard output shall not be used.</p>
<p>When the <b>-l</b> option is specified, the symbolic name of each signal shall be written in the following format:</p>
<pre>
<tt>"%s%c", &lt;</tt><i>signal_name</i><tt>&gt;, &lt;</tt><i>separator</i><tt>&gt;
</tt>
</pre>
<p>where the &lt;<i>signal_name</i>&gt; is in uppercase, without the <b>SIG</b> prefix, and the &lt;<i>separator</i>&gt; shall be
either a &lt;newline&gt; or a &lt;space&gt;. For the last signal written, &lt;<i>separator</i>&gt; shall be a &lt;newline&gt;.</p>
<p>When both the <b>-l</b> option and <i>exit_status</i> operand are specified, the symbolic name of the corresponding signal shall
be written in the following format:</p>
<pre>
<tt>"%s\n", &lt;</tt><i>signal_name</i><tt>&gt;
</tt>
</pre>
</blockquote>
<h4><a name="tag_04_72_11"></a>STDERR</h4>
<blockquote>
<p>The standard error shall be used only for diagnostic messages.</p>
</blockquote>
<h4><a name="tag_04_72_12"></a>OUTPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_72_13"></a>EXTENDED DESCRIPTION</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_72_14"></a>EXIT STATUS</h4>
<blockquote>
<p>The following exit values shall be returned:</p>
<dl compact>
<dt>&nbsp;0</dt>
<dd>At least one matching process was found for each <i>pid</i> operand, and the specified signal was successfully processed for at
least one matching process.</dd>
<dt>&gt;0</dt>
<dd>An error occurred.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_72_15"></a>CONSEQUENCES OF ERRORS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_04_72_16"></a>APPLICATION USAGE</h4>
<blockquote>
<p>Process numbers can be found by using <a href="../utilities/ps.html"><i>ps</i></a>.</p>
<p>The job control job ID notation is not required to work as expected when <i>kill</i> is operating in its own utility execution
environment. In either of the following examples:</p>
<pre>
<tt>nohup kill %1 &amp;
system("kill %1");
</tt>
</pre>
<p>the <i>kill</i> operates in a different environment and does not share the shell's understanding of job numbers.</p>
</blockquote>
<h4><a name="tag_04_72_17"></a>EXAMPLES</h4>
<blockquote>
<p>Any of the commands:</p>
<pre>
<tt>kill -9 100 -165
kill -s kill 100 -165
kill -s KILL 100 -165
</tt>
</pre>
<p>sends the SIGKILL signal to the process whose process ID is 100 and to all processes whose process group ID is 165, assuming the
sending process has permission to send that signal to the specified processes, and that they exist.</p>
<p>The System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001 and this volume of IEEE&nbsp;Std&nbsp;1003.1-2001 do not require
specific signal numbers for any <i>signal_names</i>. Even the <b>-</b> <i>signal_number</i> option provides symbolic (although
numeric) names for signals. If a process is terminated by a signal, its exit status indicates the signal that killed it, but the
exact values are not specified. The <i>kill</i> <b>-l</b> option, however, can be used to map decimal signal numbers and exit
status values into the name of a signal. The following example reports the status of a terminated job:</p>
<pre>
<tt>job
stat=$?
if [ $stat -eq 0 ]
then
echo job completed successfully.
elif [ $stat -gt 128 ]
then
echo job terminated by signal SIG$(kill -l $stat).
else
echo job terminated with error code $stat.
fi
</tt>
</pre>
<p>To send the default signal to a process group (say 123), an application should use a command similar to one of the
following:</p>
<pre>
<tt>kill -TERM -123
kill -- -123
</tt>
</pre>
</blockquote>
<h4><a name="tag_04_72_18"></a>RATIONALE</h4>
<blockquote>
<p>The <b>-l</b> option originated from the C shell, and is also implemented in the KornShell. The C shell output can consist of
multiple output lines because the signal names do not always fit on a single line on some terminal screens. The KornShell output
also included the implementation-defined signal numbers and was considered by the standard developers to be too difficult for
scripts to parse conveniently. The specified output format is intended not only to accommodate the historical C shell output, but
also to permit an entirely vertical or entirely horizontal listing on systems for which this is appropriate.</p>
<p>An early proposal invented the name SIGNULL as a <i>signal_name</i> for signal 0 (used by the System Interfaces volume of
IEEE&nbsp;Std&nbsp;1003.1-2001 to test for the existence of a process without sending it a signal). Since the <i>signal_name</i> 0
can be used in this case unambiguously, SIGNULL has been removed.</p>
<p>An early proposal also required symbolic <i>signal_name</i>s to be recognized with or without the <b>SIG</b> prefix. Historical
versions of <i>kill</i> have not written the <b>SIG</b> prefix for the <b>-l</b> option and have not recognized the <b>SIG</b>
prefix on <i>signal_name</i>s. Since neither applications portability nor ease-of-use would be improved by requiring this
extension, it is no longer required.</p>
<p>To avoid an ambiguity of an initial negative number argument specifying either a signal number or a process group,
IEEE&nbsp;Std&nbsp;1003.1-2001 mandates that it is always considered the former by implementations that support the XSI option. It
also requires that conforming applications always use the <tt>"--"</tt> options terminator argument when specifying a process
group, unless an option is also specified.</p>
<p>The <b>-s</b> option was added in response to international interest in providing some form of <i>kill</i> that meets the
Utility Syntax Guidelines.</p>
<p>The job control job ID notation is not required to work as expected when <i>kill</i> is operating in its own utility execution
environment. In either of the following examples:</p>
<pre>
<tt>nohup kill %1 &amp;
system("kill %1");
</tt>
</pre>
<p>the <i>kill</i> operates in a different environment and does not understand how the shell has managed its job numbers.</p>
</blockquote>
<h4><a name="tag_04_72_19"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_72_20"></a>SEE ALSO</h4>
<blockquote>
<p><a href="xcu_chap02.html#tag_02"><i>Shell Command Language</i></a> , <a href="ps.html"><i>ps</i></a> , <a href=
"wait.html"><i>wait</i>()</a> , the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../functions/kill.html"><i>kill</i>()</a>, the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/signal.h.html"><i>&lt;signal.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_04_72_21"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 2.</p>
</blockquote>
<h4><a name="tag_04_72_22"></a>Issue 6</h4>
<blockquote>
<p>The obsolescent versions of the SYNOPSIS are turned into non-obsolescent features of the XSI option, corresponding to a similar
change in the <a href="../utilities/trap.html"><i>trap</i></a> special built-in.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>