Read in 3 minutes

last updated 

How to Kill a Process in Linux

Have you ever faced the situation where you launched an application and suddenly while you are using the application it becomes unresponsive and unexpectedly crashes? You try to start the application again, but nothing happens because the original application process never truly shut down completely.

Well, it has happened to all of us at some point, hasn’t it? The solution is to terminate or kill the application process. But how?

Luckily, there are several utilities in Linux that allows you to kill errant processes.

In this tutorial, we will show you how to use kill and killall commands to terminate a process in Linux. The main difference between these two tools is that killall terminates running processes based on name, while the kill terminates processes based on Process ID number (PID).

Regular users can kill their own processes, but not those that belong to other users, while the root user can kill all processes.

System Kill Signals

kill and killall can send a given signal to specified processes or process groups. When used without a signal both tools will send -15 (-TERM).

The most commonly used signals are:

  • 1 (-HUP): to restart a process.
  • 9 (-KILL): to kill a process.
  • 15 (-TERM): to gracefully stop a process.

Signals can be specified in three different ways:

  • using number (e.g., -1)
  • with the “SIG” prefix (e.g., -SIGHUP)
  • without the “SIG” prefix (e.g., -HUP).

Use the -l option to list all available signals:

kill -l  # or killall -l

The steps outlined below will work on all Linux distributions.

Terminating Processes Using the kill Command

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

Let’s say our Firefox browser has become unresponsive and you need to kill the Firefox process. To find the process PID use the pidof command:

pidof firefox

The command above will print all Firefox processes:

2551 2514 1963 1856 1771

Once you know the Firefox processes PIDs to terminate all of them type:

kill -9 2551 2514 1963 1856 1771

Terminating Processes Using the killall Command

The killall command terminates all programs that match a specified name.

Using the same scenario as before, we can kill the Firefox process by typing:

killall -9 firefox

killall accepts several options such as specifying processes running as user, using regular expression and killing processes based on the creation time. You can get a list of all options by typing killall (without any arguments).

For example if we want to terminate all processes running as a user sara we would run the following command:

killall -u sara

Conclusion

Terminating unresponsive programs using the kill and killall commands is an easy task. You only need to know the process name or PID.

If you have feedback, leave a comment below.