[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 3

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 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

-s{SignalName | SignalNumber} Specifies the signal as a signal number or a signal name, such as SIGKILL -9 or SIGTERM -15.
-SignalName Specifies a signal name, such as SIGHUP. This is obsolete syntax.
-SignalNumber Specifies a signal number. This is obsolete syntax.

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 representing 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 having 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 supported by the implementation
-lExitStatus Lists signal names stripped of the common SIG prefix. If ExitStatus is an 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:

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:

    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:

    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:

    kill -kill 0

    This sends signal 9, the SIGKILL signal, to all processes having a process group ID equal to the senders process group ID. Because the shell cannot ignore the SIGKILL signal, this also stops the login shell and logs you off.

  4. To stop all processes that you own, enter:

    kill -9 -1

    This sends signal 9, the SIGKILL signal, to all processes owned by the effective user, even those started at other work stations 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:

    kill  -USR1  1103

    The name of the kill command is misleading because many signals, including SIGUSR1, do not stop processes. The action 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 SIGTERM.

Files

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

Related Information

The csh command, ksh command, ps command, sh command.

The kill subroutine, sigaction subroutine.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]