Processes and jobs
killall
Send a signal (TERM by default) to all processes running a program with the given name.
killall [-SIGNAL | -s SIGNAL] [OPTION...] NAME...
killall signals every process whose name equals the one you give: killall firefox stops
every Firefox process you own. Unlike pkill, the name is matched whole, not as a pattern,
so killall ssh does not touch sshd. Regular expressions are available with -r, but only
on request. It also has a few conveniences pkill lacks: -i asks before each kill, -w waits
until the processes are actually gone, and -o/-y select by age (-o 2h, older than two
hours).
On Linux, killall comes from psmisc and is safe to type. On Solaris and some older System V
Unixes, a command with the same name kills all processes on the system, as part of
shutdown; that is why some administrators avoid the name entirely in scripts meant to be
portable and use pkill -x instead.
Signals are given as -HUP, -9, -s KILL or --signal KILL. -v reports each process
signaled, and the exit status is 0 if every name matched something and 1 otherwise.
Examples
Stop every process with a given name
sleep 300 & sleep 600 &
killall -v sleep
Killed sleep(1311) with signal 15 Killed sleep(1312) with signal 15
Both sleep processes receive TERM (signal 15). Without -v the command is silent on
success.
Nothing to kill
killall nginx
nginx: no process found
no process found on standard error and exit status 1. Add -q to suppress the message
when "already stopped" is an acceptable outcome, and || true if the script runs with
set -e.
Whole names only
sleep 300 &
killall slee; echo "exit status: $?"
killall -v sleep
slee: no process found exit status: 1 Killed sleep(1315) with signal 15
slee is not the name of any process, so nothing is killed; pkill slee would have matched
sleep. This is the main reason to choose killall when you know the exact program name.
Send a different signal
sleep 300 & sleep 301 &
killall -v -HUP sleep
Killed sleep(1318) with signal 1 Killed sleep(1319) with signal 1
-HUP, -1, -s HUP and --signal HUP are equivalent; -v shows signal 1 went out.
sleep has no handler, so HUP ends it; a daemon with a HUP handler would reload
instead.
Wait until the processes have exited
#!/bin/bash
trap 'echo "cleaning up..."; sleep 1; echo "done"; exit 0' TERM
while :; do sleep 0.1; done
chmod +x slowstop.sh
./slowstop.sh &
sleep 0.3
killall -w slowstop.sh
echo "killall returned"
cleaning up... done killall returned
The script takes a second to clean up after TERM. -w makes killall wait until every
signaled process has exited, so the next command (a restart, say) does not start too early.
Without -w it would return at once.
Confirm each kill
sleep 300 & sleep 600 &
printf 'y\nn\n' | killall -i sleep
pgrep -a sleep
Kill sleep(1330) ? (y/N) Kill sleep(1331) ? (y/N) 1331 sleep 600
-i asks Kill sleep(PID) ? (y/N) for each process. The answers come from the pipe here
(so the prompts run together on one line): y for the first, n for the second, and only
sleep 600 remains.
Kill only processes older or younger than a given age
sleep 300 &
killall -v -o 1h sleep; echo "older than 1h: exit $?"
killall -v -y 1m sleep
sleep: no process found older than 1h: exit 1 Killed sleep(1335) with signal 15
-o matches processes started more than the given time ago, -y less. Units are s, m,
h, d, w, M (months) and y. The sleep started a moment ago, so it is not older than
an hour but is younger than a minute.
Match names with a regular expression
sleep 300 &
python3 -c 'import time; time.sleep(300)' &
sleep 0.2
killall -v -r '^(sleep|python3)$'
python3(1): Operation not permitted Killed sleep(1338) with signal 15 Killed python3(1339) with signal 15
-r treats each name as an extended regular expression. Anchor it, or -r py would also
match any other name containing py. The sandbox's own runner is a root-owned python3
process (PID 1); killall may not signal it, says so, and carries on with the others.
Kill everything a user is running
sleep 300 & sleep 301 &
killall -v -u dev sleep
Killed sleep(1342) with signal 15 Killed sleep(1343) with signal 15
-u USER restricts the match to that user's processes. As root, killall -u alice
without a name signals all of alice's processes, which ends her sessions.
List the signal names killall knows
killall -l
HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS
The signal names in number order, without the SIG prefix: HUP is 1, INT 2 and so on.
Use them with -s or as -NAME.
Common pitfalls
Typing
killallon Solaris or another System V Unix. There it kills every process on the machine. For scripts that might run anywhere,pkill -x nameis the safer spelling.Long names. The kernel keeps only 15 characters of a process name; when psmisc cannot read the full name it falls back to matching those 15 characters, so
killall my-service-workercan hitmy-service-work-other.-eskips such uncertain matches.Scripts started through an interpreter are named after their file only when run through the
#!line (./worker.sh). Started asbash worker.shorpython3 worker.py, their name isbashorpython3, andkillall python3hits every Python program you run.Expecting
killallto have finished the job when it returns. Without-wit only sends the signal; processes that handleTERMmay take time to exit.
GNU vs BSD and macOS
The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).
macOS and FreeBSD have their own
killall, also safe (it kills by name), with a different option set:-sthere means "show what would be done" rather than "signal". Usekillall -SIGNAL nameor-HUPstyle, which both versions accept.
Options worth knowing
A selection, described in our own words. For the full list, see killall(1) or killall --help.
| Option | What it does |
|---|---|
-v | Report each process that was signaled. |
-q | Do not complain when no process matches. |
-s SIGNAL | Send SIGNAL (name or number) instead of TERM. |
--signal SIGNAL | Long form of -s. |
-l | List the known signal names. |
-i | Ask for confirmation before each kill. |
-w | Wait until all signaled processes have exited. |
-e | Require an exact match for names longer than 15 characters. |
-I | Match process names case-insensitively. |
-r | Treat each name as an extended regular expression. |
-u USER | Kill only processes owned by USER. |
-o TIME | Match only processes older than TIME (e.g. 30m, 2h, 1d). |
-y TIME | Match only processes younger than TIME. |
-g | Signal the whole process group of each matching process. |
-n PID | Match only processes in the same namespaces as PID. |
-9 | Send KILL, which cannot be caught or ignored. |
-KILL | Send KILL by name. |
-HUP | Send HUP, usually a request to reload configuration. |
-TERM | Send TERM, the default. |
-INT | Send INT, the same as pressing Ctrl-C. |
-USR1 | Send USR1, whose meaning each program defines. |
Related
pkillSend a signal (TERM by default) to every process whose name or command line matches a pattern.killSend a signal to processes by PID or job number; by default TERM, which asks a process to exit.pgrepPrint the PIDs of processes whose name (or full command line) matches a pattern, with filters by user, parent and age.psPrint a snapshot of running processes, with the columns, filters and sort order you choose.pstreeDisplay running processes as a tree, showing which process started which.