Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Processes and Signals

Linux kill command

Reference for the Linux kill command: send TERM, HUP, KILL, STOP or CONT to a PID, list signal names, test existence with signal 0 and handle process groups.

Despite its name, kill does not necessarily kill: it sends a signal to a process or process group. A signal is a small message from the kernel or another process, such as "please terminate" (SIGTERM, the default), "reload" (SIGHUP), "stop" (SIGSTOP) or "this is the end" (SIGKILL). The receiving program may catch most signals and react, ignore them, or let the default action happen. Only SIGKILL and SIGSTOP cannot be caught or ignored.

In Bash kill is a builtin, and there is also /bin/kill. They accept almost the same options; the builtin can also address shell jobs with %1.

Terminal
kill [-SIGNAL] PID...
kill -l

Try it

Bash Terminate, stop and continue

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash A program that handles signals

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
kill [-s SIGNAL | -SIGNAL | -NUMBER] PID|%JOB...
kill -l [SIGNAL|EXIT_STATUS]
Argument Description
PID A process ID.
0 The current process group (the caller's).
-1 Every process you may signal (root: all but init). Dangerous.
-PID (negative) The whole process group with that ID; write it kill -TERM -- -1234.
%N Bash job number N (builtin only).
-s NAME, -NAME, -N The signal, by name (with or without SIG) or number.
-l List the signal names; with a number, translate it to a name.

Frequently used signals:

Name No. Meaning
HUP 1 Terminal hangup; daemons take it as "reload configuration".
INT 2 Interrupt (what Ctrl-C sends).
QUIT 3 Quit with core dump (Ctrl-).
KILL 9 Immediate kill; cannot be caught.
USR1, USR2 10, 12 Application-defined.
TERM 15 Polite termination request (the default).
CONT / STOP 18 / 19 Resume / suspend (STOP cannot be caught).
TSTP 20 Terminal stop (Ctrl-Z); can be caught.

Numbers above 15 vary between architectures; use names in scripts.

Returns: 0 if the signal was sent to every target; 1 if any failed (no such process, or Operation not permitted).

Usage notes

  • Try TERM first, KILL last. SIGKILL gives the program no chance to flush files, remove temp files or release locks. A common sequence is TERM, wait a few seconds, then KILL.
  • Signal 0 performs only the existence and permission check, a safe is it alive? test. Exit status 1 means gone or not yours.
  • Exit status of a killed process is 128 plus the signal number, so wait reports 143 for TERM and 137 for KILL. This is why $? after the TERM example above is 143 for a plain sleep.
  • Permissions: you can signal only your own processes (same real or effective user) unless you are root.
  • Zombies and D state. A zombie is already dead; kill its parent. A process in uninterruptible sleep (D) ignores even KILL until its I/O finishes.
  • Process groups: a negative PID signals a whole pipeline or job and its children. Without it, only the parent receives the signal and children may live on.
  • PID reuse: a PID can be reassigned after a process exits. Do not keep stale PIDs in files for long; prefer pkill style matching in scripts or check with kill -0 right before.
  • Never kill -9 -1 or kill 1 unless you mean to end your own session.