How to Kill a Process by Name in Linux
Find matching process IDs with pgrep and terminate them safely.
Killing by name is convenient, but it can affect more than one process. The safe workflow is to search first, inspect the matches, then send SIGTERM and escalate only when necessary.
Step by step
1 Find matching processes
$ pgrep -af process-name Shows PIDs and command-line context so you can verify what will be affected.
2 Terminate by name
$ pkill -TERM process-name Sends SIGTERM to matching processes and gives applications a chance to shut down cleanly.
3 Target a specific user
$ pkill -u username process-name Limits the match to processes owned by the specified user.
4 Force only after verification
$ pkill -KILL process-name SIGKILL is a last resort because the process cannot clean up before termination.
Tips worth knowing
- Prefer a PID when you can uniquely identify the process.
- Do not use broad names such as `python` on a shared system without inspecting matches.
- For managed services, use `systemctl stop` instead of pkill.
Frequently asked questions
What is the difference between kill and pkill?
`kill` targets explicit PIDs; `pkill` selects processes by attributes such as name or user.
How do I kill all processes with a name?
Use `pkill name` only after checking the matches with `pgrep -af name`.
Is pkill -9 safe?
No. SIGKILL is deliberately forceful and should be a last resort after a normal termination request fails.
The commands behind it
Terminate processes politely or forcibly — and understand what -9 really does.
psSee what is running, find a process ID, and combine with grep to hunt down a program.
systemctlStart, stop, enable and inspect services — the control panel of modern Linux.
Concepts involved: Process · PID (Process ID)
More how-to guides
See how much space is left, and find out what is using it.
Extract a .tar.gz archiveUnpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.