The Open Group Base Specifications Issue 8
IEEE Std 1003.1-2024
Copyright © 2001-2024 The IEEE and The Open Group

NAME

kill — terminate or signal processes

SYNOPSIS

kill [-s signal_name] pid...

kill -l
[exit_status]

[XSI] [Option Start] kill [-signal_name] pid...

kill
[-signal_number] pid... [Option End]

DESCRIPTION

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

For each pid operand, the kill utility shall perform actions equivalent to the kill() function defined in the System Interfaces volume of POSIX.1-2024 called with the following arguments:

OPTIONS

The kill utility shall conform to XBD 12.2 Utility Syntax Guidelines, [XSI] [Option Start]  except that in the last two SYNOPSIS forms, the -signal_number and -signal_name options are usually more than a single character. [Option End]

The following options shall be 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 2.5.2 Special Parameters and wait) corresponding to a process that was terminated or stopped by a signal, the signal_name corresponding to the signal that terminated or stopped the process shall 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 symbolic constant name without the SIG prefix defined in the Base Definitions volume of POSIX.1-2024) corresponding to that signal shall be written. Otherwise, the results are unspecified.
-s signal_name

Specify the signal to send, using one of the symbolic names defined in the <signal.h> header. Values of signal_name shall be recognized in a case-independent fashion, without the SIG prefix. In addition, the symbolic name 0 shall be recognized, representing the signal value zero. The corresponding signal shall be sent instead of SIGTERM.
-signal_name
[XSI] [Option Start]
Equivalent to -s signal_name. [Option End]
-signal_number
[XSI] [Option Start]
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 list.

The effects of specifying any signal_number other than those listed below are undefined.

0
0
1
SIGHUP
2
SIGINT
3
SIGQUIT
6
SIGABRT
9
SIGKILL
14
SIGALRM
15
SIGTERM

If the first argument is a negative integer, it shall be interpreted as a -signal_number option, not as a negative pid operand specifying a process group. [Option End]

OPERANDS

The following operands shall be supported:

pid
One of the following:
  1. 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 pid operand shall be as described for the kill() function. If process number 0 is specified, all processes in the current process group shall be signaled. For the effects of negative pid numbers, see the kill() function defined in the System Interfaces volume of POSIX.1-2024. If the first pid operand is negative, it should be preceded by "--" to keep it from being interpreted as an option.

  2. A job ID (see XBD 3.182 Job ID) that identifies a process group in the case of a job-control background job, or a process ID in the case of a non-job-control background job (if supported), to be signaled. The job ID notation is applicable only for invocations of kill in the current shell execution environment; see 2.13 Shell Execution Environment.

    Note:
    The job ID type of pid is only available on systems supporting the User Portability Utilities option or supporting non-job-control background jobs.
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 shall affect the execution of kill:

LANG
Provide a default value for the internationalization variables that are unset or null. (See XBD 8.2 Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
LC_ALL
If set to a non-empty string value, override the values of all the other internationalization variables.
LC_CTYPE
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).
LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH
[XSI] [Option Start] Determine the location of messages objects and message catalogs. [Option End]

ASYNCHRONOUS EVENTS

Default.

STDOUT

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

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

"%s%c", <signal_name>, <separator>

where the <signal_name> is in uppercase, without the SIG prefix, and the <separator> shall be either a <newline> or a <space>. For the last signal written, <separator> shall be a <newline>.

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

"%s\n", <signal_name>

STDERR

The standard error shall be used only for diagnostic messages.

OUTPUT FILES

None.

EXTENDED DESCRIPTION

None.

EXIT STATUS

The following exit values shall be returned:

 0
The -l option was specified and the output specified in STDOUT was successfully written to standard output; or, the -l option was not specified, 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.


The following sections are informative.

APPLICATION USAGE

This utility is required to be intrinsic. See 1.7 Intrinsic Utilities for details.

Process numbers can be found by using ps.

The use of job ID notation is not dependent on job control being enabled. When job control has been disabled using set +m, kill can still be used to signal the process group associated with a job-control background job, or the process ID associated with a non-control background job (if supported), using

kill %<background job number>

See also the RATIONALE for jobs and wait.

The 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 does 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 System Interfaces volume of POSIX.1-2024 and this volume of POSIX.1-2024 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 send the default signal to a process group (say 123), an application should use a command similar to one of the following:

kill -s TERM -- -123
kill -- -123

RATIONALE

The -l 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.

An early proposal invented the name SIGNULL as a signal_name for signal 0 (used by the System Interfaces volume of POSIX.1-2024 to test for the existence of a process without sending it a signal). Since the signal_name 0 can be used in this case unambiguously, SIGNULL has been removed.

An early proposal also required symbolic signal_names to be recognized with or without the SIG prefix. Historical versions of kill have not written the SIG prefix for the -l option and have not recognized the SIG prefix on signal_names. Since neither applications portability nor ease-of-use would be improved by requiring this extension, it is no longer required.

To avoid an ambiguity of an initial negative number argument specifying either a signal number or a process group, POSIX.1-2024 mandates that it is always considered the former by implementations that support the XSI option. It also requires that conforming applications always use the "--" options terminator argument when specifying a process group.

The -s option was added in response to international interest in providing some form of kill that meets the Utility Syntax Guidelines.

The 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 does not understand how the shell has managed its job numbers.

FUTURE DIRECTIONS

None.

SEE ALSO

2. Shell Command Language, ps, wait

XBD 3.182 Job ID, 8. Environment Variables, 12.2 Utility Syntax Guidelines, <signal.h>

XSH kill

CHANGE HISTORY

First released in Issue 2.

Issue 6

The obsolescent versions of the SYNOPSIS are turned into non-obsolescent features of the XSI option, corresponding to a similar change in the trap special built-in.

Issue 7

SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.

Issue 8

Austin Group Defect 854 is applied, adding a note to the APPLICATION USAGE section that this utility is required to be intrinsic.

Austin Group Defect 1122 is applied, changing the description of NLSPATH .

Austin Group Defect 1254 is applied, clarifying the -l option with regard to an exit_status operand corresponding to a stopped process, changing "job control job ID" to "job ID", and adding a paragraph to the RATIONALE section.

Austin Group Defect 1260 is applied, changing the SYNOPSIS and EXAMPLES sections in relation to the -s option, and the RATIONALE section in relation to the use of "--" when specifying a process group.

Austin Group Defect 1504 is applied, changing the EXIT STATUS section.

End of informative text.

 

return to top of page

UNIX® is a registered Trademark of The Open Group.
POSIX™ is a Trademark of The IEEE.
Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved
[ Main Index | XBD | XSH | XCU | XRAT ]