pkill Command Guide for Killing Processes by Pattern
pkill sends a signal to every process whose name or command line matches a pattern you give it — no need to look up PIDs first.
What is pkill, and Why Use It?
The pkill command finds processes matching a pattern and signals them. It is the pattern-based sibling of kill: instead of telling it a process ID, you tell it what to look for — a name, a user, or part of a command line — and it kills every match. It is what you reach for when a program has spawned a family of workers, or when the exact name is all you know.
Why Learn pkill?
- No PID hunting:
pgrepgives you the IDs;pkillskips that step entirely and acts on the pattern directly. - Kills whole process families: when a program forks children (web servers, test runners), one pattern stops all of them.
- Scriptable: patterns make kill logic readable in scripts — “kill anything named
httpd” reads like English. - Pairs with
pgrep: the two share the same pattern syntax, so knowing one teaches you the other.
pkillis the sharp end of a two-step process: find with a pattern, kill with the same pattern. It is why “the app is stuck” has a one-line answer.
1. Basic Usage: Kill by Name
# Kill every process named exactly "firefox"
pkill firefox
- By default
pkillmatches the process name exactly and sendsSIGTERM(15) — the polite “please exit” signal. - If nothing matches,
pkillexits with status 1; if it killed something, status 0.
Check what would be killed first with pgrep:
pgrep -a firefox # show the matches before killing them
2. Match Patterns, Not Just Names
# Kill anything whose name STARTS with "chrome"
pkill chrome
# Kill processes whose name contains "test"
pkill -f test
- Plain
pkill namematches the process name only. -fmatches against the full command line, sopkill -f "python worker"hits the whole invocation, arguments included.
| Flag | What It Matches |
|---|---|
| (none) | Process name, exactly |
-f | Full command line |
-u user | Processes owned by user |
-t tty | Processes on terminal tty |
-P pid | Children of process pid |
-g pgrp | Processes in process group pgrp |
3. Choose the Signal
# Ask politely (default): SIGTERM
pkill firefox
# Insist: SIGKILL — the process cannot ignore it
pkill -9 firefox
# Suspend instead of kill: SIGSTOP
pkill -STOP -f "heavy-job"
-9(SIGKILL) is the nuclear option: the kernel kills the process instantly, with no chance to clean up.- Try the default
SIGTERMfirst; only escalate to-9when a process refuses to die. Seekillfor the full signal table.
# Send SIGHUP — many daemons reload their config on this
pkill -HUP nginx
4. Narrow the Hunt
# Kill only processes owned by user "bob"
pkill -u bob -f myscript
# Kill only your own processes
pkill -u "$(id -un)" stuck-helper
# Kill only children of a specific process
pkill -P 4321
- Combining flags keeps
pkillsurgical: pattern and owner and parent, all in one call.
5. Interactive and Dry-Run Modes
# Ask before each kill
pkill -i -f python
# Show what matches without killing (pgrep is the dry-run tool)
pgrep -af python
-ipromptskill (y/n)?for every match — useful when a pattern might catch too much.pgrep -alists the matches with their full command lines; this is the safe rehearsal for anypkillyou are unsure about.
Common Pitfalls
pkillwith no pattern kills nothing but looks like it did. Always check withpgrep -afirst when unsure.-fmatches command lines, so patterns are risky:pkill -f vimcan matchvim notes.txtand any shell command containing “vim” — including your own script.- You can kill your own shell: a broad
-fpattern can match the script runningpkillitself. Test withpgrepfirst. -9skips cleanup: databases and daemons may leave lock files or corrupted state.SIGTERMfirst, always.- Patterns are regexes, not glob names:
pkill firefox*does not mean “firefox and friends” the way a shell glob does — anchor it:pkill '^firefox$'. - Exit codes matter in scripts:
pkillreturns 1 when nothing matched; don’t let that abort a script unexpectedly.
Related Pages
| Page | Relationship |
|---|---|
pgrep | Finds the processes pkill would kill — the safe rehearsal. |
kill | The PID-based cousin; same signals, manual targeting. |
killall | Kills by exact name; pkill adds pattern matching. |
ps | Shows the processes before you match them. |
top | Live view; spot what needs killing. |
pkill Cheatsheet
| Command | What It Does |
|---|---|
pkill name | Kill processes named name (SIGTERM). |
pkill -9 name | Force-kill with SIGKILL. |
pkill -f pattern | Match the full command line. |
pkill -u user pat | Kill only user’s matches. |
pkill -P pid | Kill children of pid. |
pkill -HUP daemon | Signal a daemon to reload config. |
pkill -i pat | Ask before each kill. |
pgrep -af pat | Preview the matches first. |