How can I kill a process by name instead of PID, on Linux?
You can kill a process by its name (rather than PID) using one of the following commands:
1. killall
killall process_name
killall
sends a signal to all processes running under the given name (process_name
).- If multiple processes share the same name, all of them are terminated.
Example:
killall firefox
This kills all running instances of Firefox.
2. pkill
pkill process_name
pkill
matches partial process names by default.- For an exact match, use
pkill -x process_name
(kills only processes whose name matches exactly). - For a more forceful kill, you can add
-9
(though use with caution):pkill -9 process_name
Important Notes
- Use with Care:
killall
orpkill
can kill multiple processes if they share or partially match the name. - Check Before Killing: If you want to see which processes match a name first:
This lists matching PIDs and names, letting you confirm.pgrep -l process_name
Recommended Resource
If you’re aiming to expand your system knowledge along with your coding fundamentals, consider this course from DesignGurus.io:
- Grokking Data Structures & Algorithms for Coding Interviews
By mastering data structures and algorithms, you’ll handle system tasks (like process management) and coding challenges more efficiently.
CONTRIBUTOR
TechGrind