Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

kill - terminate or signal processes

&pagelevel(4)&pagelevel

The kill command sends the specified signal to a set of processes indicated by a process number (PID). The ps command can be used to find the process number of any process to which you want to send a signal.


Syntax


Format 1:kill[ -signal] pid ...
Format 2:kill -s signal pid ...
Format 3:kill -signal -pgid ...
Format 4:kill -l [exit-status]



Send signals to processes
Format 1:kill[ -signal] pid ...


-signal

Signal to be sent to the processes. This signal can be given in the form of a number or a symbolic name. The symbolic signal name is the name as it appears in the header file <sys/signal.h>, without the SIG prefix. A list of these names can be printed with the -l option.

Any signal defined in the header file <sys/signal.h> may be specified. The signals with the signal numbers and symbolic names below are significant on command level:

1 - SIGHUP

Halt if the user hangs up

2 - SIGINT

Interrupt via CTRL+C

3 - SIGQUIT

Quit

9 - SIGKILL

Kill, terminate process unconditionally

15 - SIGTERM

Software termination, terminate process gracefully

The symbolic name 0 which represents the signal value zero is also recognized.

signal not specified:
kill sends the signal SIGTERM (15) to the specified processes. This will normally kill processes that do not catch or ignore the signal.

pid

Number (ID) of the process to which a signal is to be sent. Users can only send signals to their own processes. The POSIX administrator can send signals to all processes.

Current process IDs can be listed with the ps command.

A pid value of 0 has a special meaning: the signal is sent to all processes in your process group.

Send signals to processes
Format 2:kill -s signal pid ...


-s signal

Signal to be sent to the processes. This signal can be given in the form of a number or a symbolic name. The symbolic signal name is the name as it appears in the header file <sys/signal.h>, without the SIG prefix. A list of these names can be printed with the -l option.

Send signals to process groups
Format 3:kill -signal -pgid ...


-signal

Signal to be sent to the processes of a process group. This signal can be given in the form of a number or a symbolic name. The symbolic signal name is the name as it appears in the header file <sys/signal.h>, without the SIG prefix. A list of these names can be printed with the -l option.

-pgid

The signal is sent to all processes with process group ID pgid.

Users can only send signals to their own processes.

The POSIX administrator can send signals to all processes.

If you specify a value of 1 for pgid, the designated signal will be sent to every process whose real user ID matches the effective user ID of the kill command. As privileged user you send the signal to all processes, with the exception of a number of system processes.

List symbolic signal names
Format 4:kill -l [exit-status]


-l

A list of all symbolic signal names is printed.

exit-status

Signal number or exit status of a process which is terminated by a signal.

Error

no such process

You specified an invalid value for pid.


no such process group

You specified an invalid value for pgid.

File

<sys/signal.h>

Header file in which the symbolic names of signals are defined.

Locale

The following environment variables affect the execution of dd:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization 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 internationalization 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 and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other.

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 catalogs for the processing of LC_MESSAGES.

Example 1

The signal SIGKILL (9) is used to terminate process number 312:

$ kill -9 312

Example 2

The following example outputs 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

In order to prevent the possibility that either a signal number or a process group may be specified in the presence of a start argument which contains a negative number and thereby cause an ambiguity, ISO POSIX-2 DIS requires that the former case is always assumed. Therefore if the default signal is to be sent to a process group (e.g. 123), the application must use a command which resembles the following:

kill -TERM -123

kill -- -123

See also

ps, trap
kill(), signal() [4]