Logo

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 or pkill 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:
    pgrep -l process_name
    This lists matching PIDs and names, letting you confirm.

Recommended Resource

If you’re aiming to expand your system knowledge along with your coding fundamentals, consider this course from DesignGurus.io:

CONTRIBUTOR
TechGrind