The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

kill - terminate or signal processes

 SYNOPSIS



kill -s signal_name pid...

kill -l [exit_status]

kill [-signal_name] pid...  (Obsolescent)

kill [-signal_number] pid...  (Obsolescent)

 DESCRIPTION

The kill utility will send a signal to the process or processes specified by each pid operand.

For each pid operand, the kill utility will perform actions equivalent to the XSH specification kill() function called with the following arguments:

  1. The value of the pid operand will be used as the pid argument.

  2. The sig argument is the value specified by the -s option, -signal_number option, or the -signal_name option, or by SIGTERM, if none of these options is specified.

 OPTIONS

The kill utility supports the XBD specification, Utility Syntax Guidelines  , except that in the obsolescent form, the -signal_number and -signal_name options are usually more than a single character.

The following options are supported:

-l
(The letter ell.) Write all values of signal_name supported by the implementation, if no operand is given. If an exit_status operand is given and it is a value of the "?" shell special parameter (see Special Parameters and wait) corresponding to a process that was terminated by a signal, the signal_name corresponding to the signal that terminated the process will be written. If an exit_status operand is given and it is the unsigned decimal integer value of a signal number, the signal_name (the XSH specification-defined symbolic constant name without the SIG prefix) corresponding to that signal will be written. Otherwise, the results are unspecified.
-s signal_name
Specify the signal to send, using one of the symbolic names defined in the XSH specification <signal.h> description. Values of signal_name will be recognised in a case-independent fashion, without the SIG prefix. In addition, the symbolic name 0 will be recognised, representing the signal value zero. The corresponding signal will be sent instead of SIGTERM.
-signal_name
Equivalent to -s signal_name.
-signal_number
Specify a non-negative decimal integer, signal_number, representing the signal to be used instead of SIGTERM, as the sig argument in the effective call to kill(). The correspondence between integer values and the sig value used is shown in the following table.
signal_number sig Value
0 0
1 SIGHUP
2 SIGINT
3 SIGQUIT
6 SIGABRT
9 SIGKILL
14 SIGALRM
15 SIGTERM
The effects of specifying any signal_number other than those listed in the table are undefined.

In the obsolescent versions, if the first argument is a negative integer, it will be interpreted as a -signal_number option, not as a negative pid operand specifying a process group.

 OPERANDS

The following operands are supported:
pid
One of the following:
  1. A decimal integer specifying a process or process group to be signalled. The process or processes selected by positive, negative and zero values of the pid operand will be as described for the XSH specification kill() function. If process number 0 is specified, all processes in the process group are signalled. For the effects of negative pid numbers, see the XSH specification under kill(). If the first pid operand is negative, it should be preceded by -- to keep it from being interpreted as an option.
  2. A job control job ID (see the XBD specification, Glossary  ) that identifies a background process group to be signalled. The job control job ID notation is applicable only for invocations of kill in the current shell execution environment; see Shell Execution Environment .
    Note:
    The job control job ID type of pid is available on systems supporting both the job control option and the User Portability Utilities Option, which applies to all XSI-conformant systems.

exit_status
A decimal integer specifying a signal number or the exit status of a process terminated by a signal.

 STDIN

Not used.

 INPUT FILES

None.

 ENVIRONMENT VARIABLES

The following environment variables affect the execution of kill:
LANG
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
LC_ALL
If set to a non-empty string value, override the values of all the other internationalisation variables.
LC_CTYPE
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).
LC_MESSAGES
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH
Determine the location of message catalogues for the processing of LC_MESSAGES .

 ASYNCHRONOUS EVENTS

Default.

 STDOUT

When the -l option is not specified, the standard output will not be used.

When the -l option is specified, the symbolic name of each signal will be written in the following format:

"%s%c", <signal_name>,
<separator>
where the <signal_name> is in upper-case, without the SIG prefix, and the <separator> will be either a newline character or a space character. For the last signal written, <separator> will be a newline character.

When both the -l option and exit_status operand are specified, the symbolic name of the corresponding signal will be written in the following format:

"%s\n", <signal_name>

 STDERR

Used only for diagnostic messages.

 OUTPUT FILES

None.

 EXTENDED DESCRIPTION

None.

 EXIT STATUS

The following exit values are returned:
0
At least one matching process was found for each pid operand, and the specified signal was successfully processed for at least one matching process.
>0
An error occurred.

 CONSEQUENCES OF ERRORS

Default.

 APPLICATION USAGE

Process numbers can be found by using ps.

The job control job ID notation is not required to work as expected when kill is operating in its own utility execution environment. In either of the following examples:


nohup kill %1 &
system("kill %1");

the kill operates in a different environment and will not share the shell's understanding of job numbers.

 EXAMPLES

Any of the commands:

kill -9 100 -165
kill -s kill 100 -165
kill -s KILL 100 -165

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.

The XSH specification and this specification do not require specific signal numbers for any signal_names. Even the -signal_number 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 kill -l 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:


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

To avoid an ambiguity of an initial negative number argument specifying either a signal number or a process group, the ISO/IEC 9945-2:1993 standard mandates that it always be considered the former. Therefore, to send the default signal to a process group (say 123), an application should use a command similar to one of the following:


kill -TERM -123
kill -- -123

 FUTURE DIRECTIONS

The obsolescent forms may be withdrawn in a future issue. Applications should use the -s option.

 SEE ALSO

ps, wait, the XSH specification description of kill(), <signal.h>.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]