System and processes
The pkill command
Sends a signal to processes by name, without looking up their PID first.
Most useful options
-fMatches the pattern against the full command line, not just the program name-xRequires the name (or the full line, with -f) to match the pattern exactly-SEÑALSignal to send, by number or name (-9, -HUP, -TERM). Without it, SIGTERM-iIgnores uppercase and lowercase when matching the pattern-u <usuario>Only processes whose effective user is this one-nSelects only the most recently started of the matching processes-oSelects only the oldest of the matching processesCopy-ready examples
$ pgrep -l -x sshdlists which processes match before sending anything. Always do this before killing.Example output
634 sshd
$ pkill -HUP syslogdsends SIGHUP to the daemon, which many programs use to reread their configuration.$ pkill -x sshdterminates every process named exactly sshd. Destructive: check with the first example before.$ pkill -f "python3 servidor.py"terminates the processes whose command line contains that text. Destructive: review with pgrep -a -f first.$ pkill -n -x -u miguel firefoxterminates only the newest firefox instance owned by user miguel. Destructive, though it affects a single instance.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| pkill: no matching criteria specified | pkill was run without a pattern or any other criterion, for example plain pkill. | Give the process name: pkill -x name. Before killing, check with pgrep -l. |
| bash: pkill: command not found | The pkill program comes in the procps package, which is missing from minimal images and containers. | Install procps with your distribution's package manager, for example sudo apt install procps on Debian or Ubuntu. |
Typical mistakes
- A short pattern kills too much: pkill py can hit python3 and other processes. Use -x or the full name.
- Linux only compares the first 15 characters of the process name; for longer names use -f.
- With no matches it prints nothing and exits with code 1: in a script, check the exit code.
Differences from similar commands
- kill: Needs the exact PID. pkill searches by name or pattern and can reach several processes at once.
- killall: Also signals by name, but requires the exact name unless you use -r. pkill accepts patterns and filters such as -u or -n.
- pgrep: Uses the same criteria but only lists the PIDs. pkill sends them a signal.
FAQ
Do I need sudo to kill another user's process?
Yes. Your own processes do not need it; those of another user, including root, require sudo or equivalent privileges.
Which signal does it send if I give none?
SIGTERM (15), which gives the program the chance to close its files. SIGKILL (-9) cannot be ignored, so use it only if SIGTERM is not enough.
Why doesn't pkill kill a process that shows up in ps?
Most often the name is longer than 15 characters (use -f) or it belongs to another user. Check with pgrep -l -u user.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course