Kill a Process in Linux: 2 Ways
In this article
To kill a process in Linux, you can use the kill command with a process ID (PID) or the pkill command with a process name. Both send a termination signal, with kill targeting a specific PID and pkill matching by name or other attributes. This guide shows both methods and includes tips for stubborn processes.
What You'll Need
- A Linux terminal (command line) – open with Ctrl+Alt+T or via your app launcher.
- Basic permissions: you can kill your own processes. To kill processes owned by other users, you'll need
sudo. - The process name or PID you want to terminate – find it with
psorpgrep(covered below).
Step-by-Step
Method 1: Using kill with a PID
- Identify the PID – Open a terminal and run
ps aux | grep process-name(replace process-name with the actual name, e.g.,firefox). Look for the number in the second column (PID). Alternatively, usepgrep process-nameto get just the PID(s). - Send the default TERM signal – Run
kill PID(e.g.,kill 1234). This asks the process to terminate gracefully, allowing it to save data and clean up. - Check if it exited – Run
ps -p PIDagain. If nothing shows, the process is gone. If it's still there, it ignored the TERM signal. - Force kill if needed – If the process didn't stop, use
kill -9 PID(orkill -KILL). This sends the KILL signal, which forcibly terminates the process immediately, without cleanup.
Method 2: Using pkill by Name
- Find the exact process name – Run
ps aux | grep process-nameto see the full command line. The name might be different from the application's display name (e.g., Chrome's process ischrome). - Send the TERM signal by name – Run
pkill process-name(e.g.,pkill chrome). This sends SIGTERM to all processes matching that name. - Verify termination – Run
pgrep process-name– if no PID is returned, the process is stopped. - Force kill if needed – Use
pkill -9 process-nameto send SIGKILL to all matching processes.
Note: Menu labels and command options can vary slightly between Linux distributions and versions, but these commands are standard across most systems.
Common Mistakes
- Killing the wrong PID – Always double-check the PID before running
kill. A wrong PID could terminate an unrelated system process. - Using
pkilltoo broadly –pkillmatches substrings by default. For example,pkill javawill kill any process with “java” in its name, includingjavacoropenjdk. Usepkill -xfor an exact match (e.g.,pkill -x java). - Forgetting
sudo– If you get “Operation not permitted,” the process is owned by another user. Prefix withsudo(e.g.,sudo kill 1234). - Using
kill -9too early – Force-killing prevents the process from saving data or releasing resources. Always try plainkillfirst.
Tips
- List all running processes – Use
ps auxto see every process with its PID, user, and command. This helps you find the exact name. - Use
pgrepto test – Before killing, runpgrep -a process-nameto see the PID and full command line. This confirms you're targeting the right process. - Kill multiple processes at once –
killaccepts multiple PIDs:kill 1234 5678.pkillkills all matches in one go. - Use
killallfor exact name –killall process-namekills all processes with that exact name (similar topkill -x). - Check signal numbers –
kill -llists all signal names. SIGTERM (15) is the default; SIGKILL (9) is the last resort.
Troubleshooting
If the process does not die after kill -9: This is extremely rare but can happen if the process is in an uninterruptible sleep (e.g., waiting on I/O). In that case, you may need to reboot the system, but first try sudo kill -9 to ensure you have permission.
If you get “No such process”: The process already exited, or the PID is wrong. Re-check with ps or pgrep.
If you get “Operation not permitted”: You lack permission. Use sudo or switch to the user who owns the process (e.g., su - username).
If pkill kills more than intended: Use pkill -x for an exact match, or use kill with specific PIDs.
If the system becomes unresponsive after killing a critical process: Restart the service or reboot. For system services, use systemctl restart service-name (e.g., systemctl restart network).
Frequently Asked Questions
What is the difference between kill and pkill?
kill requires a PID and sends a signal to that specific process. pkill matches by name or other attributes and sends a signal to all matching processes.
What does kill -9 do?
It sends the SIGKILL signal, which forcibly terminates the process immediately. The process cannot catch or ignore this signal, so it dies without cleanup.
Can I kill a process without knowing its PID?
Yes, use pkill with the process name, or use killall for an exact name match.
How do I find the PID of a process?
Use ps aux | grep name or pgrep name. The PID is the number in the second column of ps output.
Is it safe to kill a process?
It's safe for user applications, but be careful with system processes. Killing a critical system process can crash your system or cause instability. Always try graceful termination first.
What if I accidentally kill the wrong process?
If it's a system service, restart it with systemctl restart service-name. If it's an application, relaunch it. For critical system processes, a reboot may be necessary.