Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Kill a Process in Linux: 2 Ways

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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 ps or pgrep (covered below).

Step-by-Step

Method 1: Using kill with a PID

  1. 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, use pgrep process-name to get just the PID(s).
  2. 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.
  3. Check if it exited – Run ps -p PID again. If nothing shows, the process is gone. If it's still there, it ignored the TERM signal.
  4. Force kill if needed – If the process didn't stop, use kill -9 PID (or kill -KILL). This sends the KILL signal, which forcibly terminates the process immediately, without cleanup.

Method 2: Using pkill by Name

  1. Find the exact process name – Run ps aux | grep process-name to see the full command line. The name might be different from the application's display name (e.g., Chrome's process is chrome).
  2. Send the TERM signal by name – Run pkill process-name (e.g., pkill chrome). This sends SIGTERM to all processes matching that name.
  3. Verify termination – Run pgrep process-name – if no PID is returned, the process is stopped.
  4. Force kill if needed – Use pkill -9 process-name to 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 pkill too broadly – pkill matches substrings by default. For example, pkill java will kill any process with “java” in its name, including javac or openjdk. Use pkill -x for an exact match (e.g., pkill -x java).
  • Forgetting sudo – If you get “Operation not permitted,” the process is owned by another user. Prefix with sudo (e.g., sudo kill 1234).
  • Using kill -9 too early – Force-killing prevents the process from saving data or releasing resources. Always try plain kill first.

Tips

  • List all running processes – Use ps aux to see every process with its PID, user, and command. This helps you find the exact name.
  • Use pgrep to test – Before killing, run pgrep -a process-name to see the PID and full command line. This confirms you're targeting the right process.
  • Kill multiple processes at once – kill accepts multiple PIDs: kill 1234 5678. pkill kills all matches in one go.
  • Use killall for exact name – killall process-name kills all processes with that exact name (similar to pkill -x).
  • Check signal numbers – kill -l lists 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.