kill Command

Purpose

Sends a signal to running processes.

Syntax

To Send Signal to Processes

kill-s SignalName | SignalNumber } ] ProcessID ...

kill- SignalName |  - SignalNumber ] ProcessID ...

To List Signal Names

kill -l [ ExitStatus ]

Description

The kill command sends a signal (by default, the SIGTERM signal) to a running process. This default action normally stops processes. If you want to stop a process, specify the process ID (PID) in the ProcessID variable. The shell reports the PID of each process that is running in the background (unless you start more than one process in a pipeline, in which case the shell reports the number of the last process). You can also use the ps command to find the process ID number of commands.

A root user can stop any process with the kill command. If you are not a root user, you must have initiated the process that you want to stop.

SignalName is recognized in a case-independent fashion, without the SIG prefix.

If the specified SignalNumber is 0, the kill command checks the validity of the specified PID.

Flags

Item Description
-s{SignalName | SignalNumber} Specifies the signal as a signal number or a signal name, such as -9 or KILL for the SIGKILL signal.
-SignalName Specifies a signal name, such as HUP.
-SignalNumber Specifies a signal number.

Note: To specify the negative PID with the default signal in this syntax, you must specify - - as a signal. Otherwise the first operand is interpreted as a SignalNumber.

ProcessID Specifies a decimal integer that represents a process or process group to be signaled. If PID is a positive value, the kill command sends the process whose process ID is equal to the PID. If the PID value is 0, the kill command sends the signal to all processes that have a process group ID equal to the process group ID of the sender. The signal is not sent to processes with a PID of 0 or 1. If the PID is -1, the kill command sends the signal to all processes owned by the effective user of the sender. The signal is not sent to processes with a PID of 0 or 1. If it is a negative number but not -1, the kill command sends the signal to all processes that have a process group ID equal to the absolute value of the PID.
-l Lists all signal names that are supported by the implementation
-lExitStatus Lists signal names that are stripped of the common SIG prefix. If ExitStatus is a decimal integer value, the signal name corresponding to that signal is displayed. If ExitStatus is a value of the exit status corresponding to a process that was terminated by a signal, the signal name corresponding to the signal that terminated the process is displayed.

Exit Status

This command returns the following exit values:

Item Description
0 At least one matching process was found for each ProcessID operand, and the specified signal was successfully processed for at least one matching process.
>0 An error occurred.

Examples

  1. To stop a given process, enter the following command:
    kill 1095
    This stops process 1095 by sending it the default SIGTERM signal. Note that process 1095 might not actually stop if it has made special arrangements to ignore or override the SIGTERM signal.
  2. To stop several processes that ignore the default signal, enter the following command:
    kill -kill 2098 1569
    This sends signal 9, the SIGKILL signal, to processes 2098 and 1569. The SIGKILL signal is a special signal that normally cannot be ignored or overridden.
  3. To stop all of your processes and log yourself off, enter the following command:
    kill -kill 0
    This sends signal 9, the SIGKILL signal, to all processes that have a process group ID equal to the senders process group ID. Because the shell cannot ignore the SIGKILL signal, this command also stops the login shell and logs you off.
  4. To stop all processes that you own, enter the following command:
    kill -9 -1
    This command sends signal 9, the SIGKILL signal, to all processes that are owned by the effective user, even those processes that are started at other workstations and that belong to other process groups. If a listing that you requested is being printed, it is also stopped.
  5. To send a different signal code to a process, enter the following command:
    kill  -USR1  1103
    The name of the kill command is misleading because many signals, including SIGUSR1, do not stop processes. The action that is taken on SIGUSR1 is defined by the particular application you are running.

    Note: To send signal 15, the SIGTERM signal with this form of the kill command, you must explicitly specify -15 or TERM.

Files

Item Description
/usr/include/sys/signal.h Specifies signal names.