Linux Kill Process: Stop Processes by PID or Name

By 

Updated on

5 min read

Linux kill process commands

When a Linux app freezes or a background command stops responding, closing the window is not always enough. The process can keep running, hold files open, or block you from starting the program again.

Linux gives you several ways to stop it manually. Use kill when you know the process ID (PID), killall when you know the exact process name, and pkill when you want to match a name, user, or command pattern.

This guide explains how to kill a process in Linux by PID or name, how signals work, and when to use SIGTERM or SIGKILL.

Regular users can terminate only their own processes. The root user, or a user running commands with sudo, can terminate processes system-wide. The commands shown here work on any Linux distribution.

Quick Reference

For a printable quick reference, see the kill cheatsheet .

CommandDescription
kill PIDSend SIGTERM to a process by PID
kill -9 PIDForce kill a process by PID
killall nameSend SIGTERM to all processes with an exact name
killall -u user nameKill matching processes owned by a user
pkill nameKill processes that match a name pattern
pkill -u user nameKill matching processes owned by a user
xkillClick a graphical window to close it

Understanding Kill Signals

kill, killall, and pkill send a given signal to specified processes or process groups. If no signal is specified, they default to 15 (TERM) for a graceful shutdown.

Common signals include:

  • 1 (HUP) - Reload configuration for daemons that support it.
  • 9 (KILL) - Force immediate termination. Use it as a last resort.
  • 15 (TERM) - Gracefully stop a process. This is the default signal.

Signals can be specified in three different ways:

  • Using a number, such as -1
  • With the SIG prefix, such as -SIGHUP
  • Without the SIG prefix, such as -HUP

Use the -l option to list all available signals:

Terminal
kill -l  # or killall -l
Terminal output of kill -l showing the list of available signals

Using the kill Command

To terminate a process with the kill command, you first need to find its PID. You can do this using different commands, such as top, ps , pidof, and pgrep .

For example, use ps to search for a running Firefox process:

Terminal
ps aux | grep firefox

If Firefox has become unresponsive, find its process IDs with the pidof command:

Terminal
pidof firefox

The command prints all matching Firefox PIDs:

output
2551 2514 1963 1856 1771

Start with the default TERM signal so the process has a chance to exit cleanly:

Terminal
kill 2551 2514 1963 1856 1771

If the process ignores TERM, send the KILL signal:

Terminal
kill -9 2551 2514 1963 1856 1771

SIGKILL cannot be caught or ignored, so it stops the process immediately. Use it only when the normal kill PID command does not work.

Using the killall Command

The killall command terminates all processes matching a given name. This is useful when a program has multiple running instances and you do not want to copy several PIDs.

Using the same scenario as before, send SIGTERM to all Firefox processes:

Terminal
killall firefox

If Firefox still does not close, force it to stop:

Terminal
killall -9 firefox

killall accepts several options, such as sending signals to processes owned by a specific user, matching process names against regular expressions, and filtering by process age. You can get a list of all options by typing killall --help in your terminal.

For example, to terminate Firefox processes owned by the user zoe, run:

Terminal
sudo killall -u zoe firefox

Using the pkill Command

pkill terminates processes that match the pattern given on the command line:

Terminal
pkill firefox

The process name does not have to be an exact match. Partial matches work too, which makes pkill flexible but also easier to misuse.

Before using a broad pattern, preview the matches with pgrep :

Terminal
pgrep -a firefox

To kill only Firefox processes owned by the user zoe, run:

Terminal
pkill -u zoe firefox

If the process does not stop, add -9:

Terminal
pkill -9 -u zoe firefox

Using xkill for GUI Applications

If a graphical application becomes unresponsive, you can use xkill to terminate it by clicking on its window:

Terminal
xkill

After running the command, your cursor changes to an “X”. Click on the window you want to close, and the application will be terminated.

Info
xkill works only on X11 sessions. On Wayland, which is now the default on recent Ubuntu and Fedora releases, it cannot close native Wayland windows. Use pkill, killall, or the desktop system monitor instead.

Troubleshooting

Process will not die with -9
If a process does not terminate even with SIGKILL (-9), it may be a zombie process. Zombie processes are already dead but still appear in the process table because their parent has not read their exit status.

To find zombie processes:

Terminal
ps aux | awk '$8 ~ /Z/'

You cannot kill a zombie directly. Instead, kill its parent process or restart the system.

Permission denied
If you get a “Permission denied” error, the process belongs to another user. Use sudo to terminate it:

Terminal
sudo kill PID

If the process still does not stop, use sudo kill -9 PID.

Conclusion

To kill a process in Linux, use kill PID when you know the process ID, killall name for an exact process name, or pkill pattern when you need flexible matching. Start with the default SIGTERM signal, then use SIGKILL only when the process refuses to exit.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page