This guide shows you how to terminate a running process by its name in Linux, which is faster and more reliable than hunting for its PID. You’ll use commands like pkill, killall, and pgrep to find and stop processes without needing to know their numeric IDs. No special tools are required—everything you need is already in a standard Linux terminal.
What You’ll Need
- A Linux system with a terminal (any distribution works).
- Basic permission to run commands—you’ll need
sudofor processes owned by other users or system services. - Knowledge of the exact process name you want to kill (use
ps aux | grepto find it if unsure).
Step-by-Step
- Identify the process name. Run
ps aux | grep -i <name>to list processes whose command line contains that name. For example,ps aux | grep -i firefoxshows all Firefox-related processes. Note the exact name in the output—it’s usually the first field after the user. - Check the process name with pgrep. Use
pgrep -l <name>to list PIDs and names that match. This confirms the exact string you’ll use. For instance,pgrep -l firefoxmight output1234 firefoxand5678 firefox-esr. - Kill a single process by name. Run
pkill <name>to send the default SIGTERM signal to all processes with that name. Example:pkill firefox. This asks the process to exit gracefully, allowing it to save data. - Kill all matching processes. If multiple processes share the name (like
chromeornode),pkillalready targets all of them. For a more explicit approach, usekillall <name>—it also kills every process with that exact name. - Force kill if the process ignores the request. If the process doesn’t exit after a few seconds, send SIGKILL with
pkill -9 <name>orkillall -9 <name>. This forcibly terminates it, but unsaved data will be lost. - Kill only processes owned by you. By default,
pkillandkillallaffect only your own processes. To kill another user’s process, you need root:sudo pkill <name>. - Use exact name matching to avoid accidents. Add
-xtopkillorkillallto match the process name exactly, not partially. For example,pkill -x firefoxwon’t killfirefox-esrorfirefox-bin. - Verify the process is gone. Run
pgrep -l <name>again. If it returns nothing, the process has been terminated successfully.
Common Mistakes
- Using a partial name without -x.
pkill firewill kill any process whose name contains “fire”, includingfirefoxandfirewalld. Always use-xfor exact matches. - Forgetting that pkill matches command lines, not just names. By default,
pkillmatches against the full command line. A process likepython script.pywill be killed bypkill pythonbut also bypkill script.pyif you’re not careful. - Killing the wrong user’s process. Without
sudo, you can’t kill processes owned by other users, but withsudoyou might accidentally kill a system service. Double-check the PID withpgrepfirst. - Using -9 immediately. SIGKILL doesn’t allow the process to clean up files or release resources. Always try SIGTERM first.
Tips
- Use
pkill -ifor case-insensitive matching. This is handy when you’re not sure about capitalization, e.g.,pkill -i -x chrome. - Preview with
pgrepbefore killing. Runpgrep -a <name>to see the full command lines of matching processes, so you know exactly what you’re about to kill. - Kill by pattern with
pkill -f. This matches against the entire command line, useful for scripts likepkill -f 'python server.py'. - Use
killall -rfor regular expression matching. For example,killall -r '^java'kills all processes starting with “java”. - Check the signal list. Run
kill -lto see all available signals. SIGTERM (15) is the default, SIGKILL (9) is the hard stop.
Troubleshooting
“pkill: no process found” — The name doesn’t match any running process. Check the spelling and use ps aux | grep -i <name> to see the actual process names. Remember that some processes have a different name than the executable (e.g., chromium vs chrome).
Permission denied. You’re trying to kill a process owned by another user or a system process. Use sudo before the command, but be cautious—killing system processes can destabilize your system.
Process keeps respawning. Some services are managed by systemd or a supervisor that restarts them automatically. Stop the service first with systemctl stop <service> or use systemctl --user stop for user services.
Process still running after pkill. It may be ignoring SIGTERM. Wait a few seconds, then use pkill -9. If it still persists, check if it’s a zombie (shown as Z in ps status)—zombies can’t be killed and will be cleaned up by their parent.
Accidentally killed the wrong process. If you terminated a critical system process, restart it with systemctl start <service> or reboot the system. For user applications, just relaunch them.
Frequently Asked Questions
What is the difference between pkill and killall? Both kill processes by name. pkill is more flexible—it supports partial matches, regular expressions, and matching against command lines. killall is simpler and by default requires an exact name match.
Can I kill a process without knowing its exact name? Yes, use pkill -f to match against the full command line. For example, pkill -f 'python.*server' kills any Python process running a server script.
How do I kill all processes of a specific user? Use pkill -u <username> to kill all processes owned by that user. Be careful—this will log them out and close their sessions.
What does SIGTERM vs SIGKILL mean? SIGTERM (signal 15) is a polite request to terminate, allowing the process to save data and clean up. SIGKILL (signal 9) forces immediate termination, which can cause data loss but guarantees the process dies.
Is it safe to kill a process by name if multiple instances are running? Yes, but be aware that pkill and killall will terminate all instances. If you only want to kill one, use pgrep to find its PID and then kill <PID>.
Can I undo a kill? No, once a process is terminated, it cannot be resumed. You can only restart it if it’s a service or you have the command to launch it again.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Gmail Gemini Privacy: Data Access & Limit Settings
- Fix Outlook Inbox Corruption with DISM in Windows
- How to Set Up Apple Pay on iPhone
- How to Choose a Refurbished iPhone With Years of Support
- Turn Off Message Notifications on Mac
- Spotting Outside Windows: Step-by-Step Guide