How to Kill a Process in Ubuntu

  • Post author:WunderTech
  • Post published:April 20, 2023
  • Post last modified:May 10, 2024
  • Post category:Ubuntu
  • Reading time:10 mins read

Share what you're reading!

In this tutorial, we’ll look at how to kill a process in Ubuntu.

Depending on how you’re using your system, there are times when you might have to kill a process in Ubuntu. Fortunately, the steps that you can follow are fairly straightforward and you’ll be able to kill the process quickly and efficiently.

Please keep in mind that you can use the terminal or GUI, though I find it more powerful to use the terminal (which you can use in the GUI as well). We’ll look at both options below to learn how to kill a process in Ubuntu.

How to Kill a Process in Ubuntu

Before we actually kill a process in Ubuntu, we must find the ID of the process that we’d like to kill. The steps below will utilize the terminal, but we’ll look at how to kill a process in the GUI later.

Killing a Process in Ubuntu using the Terminal

1. Search for all running processes using one of the commands below.

Finding All Processes Running

ps -ef
listing all processes in Ubuntu.

Finding All process Running by a Specific User

ps -ef | grep [USERNAME]
displaying all processes running for a specific user.

2. Note down the PID and move on to the next section to kill the process.

Killing a Process in Ubuntu using the PID or Application Name

If you have the PID from the last step, you can kill the process by running the command below and substituting the PID.

sudo kill <PID>
how to kill a process in ubuntu.

The example above kills process 88, but you can kill multiple processes by adding PID values next to each other.

sudo kill <PID> <PID> <PID> ...

If you’d rather use the application name, you can kill a process using the pkill command.

sudo pkill <APPLICATION_NAME>
killing an application by name.

While this is the preferred approach for killing a process gracefully (SIGTERM), the command above may not actually kill the process. In situations like this, we have to forcibly kill the process.

Kill Command Options

You can add command-line parameters to the kill command to perform different actions. However, these are the main two options you’ll use when killing processes in Ubuntu.

  • KILL [9]: Forcibly kills a process.
  • TERM: [15]: Gracefully stops a process (shown above).

The generic kill command gracefully stops it (-15), but you can add it to the command if you’d like as well.

sudo kill -15 <PID>

Force Kill a Process in Ubuntu using the PID (SIGKILL)

As mentioned above, follow the steps above before forcibly killing a process. Only use these steps if the process above does not work.

We will utilize the SIGKILL command below to forcibly kill a process. This command (the -9 portion in specific) forces the application to close immediately without performing any cleanup operations.

sudo kill -9 <PID>

As mentioned above, you can kill multiple processes forcibly by adding multiple PID values next to each other.

sudo kill -9 <PID> <PID> <PID> ...

Killing all Processes Running for a Specific Application in Ubuntu

There are many times when an individual application will have multiple processes running. While the processes above using the PID can be used, sometimes it’s easier to kill all running processes for an application using the application name.

Using Chrome as an example, there are multiple processes running for Chrome that we’ll kill at once using the killall command.

displaying all chrome processes running.

The command below must use an application name, but assuming that it does, all running instances of that process will be killed.

sudo killall <APPLICATION_NAME>

Using the example above, as soon as the command was run, all Chrome processes were killed.

Killing a Process in Ubuntu using the GUI

If you are using the desktop version of Ubuntu, you can kill a process easily by using the System Monitor application.

1. Search for and open the System Monitor application in Ubuntu.

system monitor in ubuntu.

2. Find the process you’d like to kill, right-click it, then select End or Kill.

  • End: This option gracefully closes the application (SIGTERM / -15)
  • Kill: This option force closes the application (SIGKILL / -9)

You should use the END option first and only use the KILL option (force kill) if the application doesn’t end properly.

displaying the processes running in ubuntu GUI.

3. Confirm that you want to end or kill the process, and the process will close!

confirming that you want to kill a process.

Conclusion: How to Kill a Process in Ubuntu

As you can see above, there are many ways to kill a process in Ubuntu. Overall, you want to terminate (SIGTERM) the application first and should only kill it if necessary. Killing an application in Ubuntu can lead to lost data and is really a last resort.

However, there are times when killing is the only option, so I wanted to make that point clear in case you do have to use it. If this tutorial helped you, please check out some of our other Ubuntu tutorials!

Thanks for checking out the tutorial on how to kill a process in Ubuntu. If you have any questions on how to kill a process in Ubuntu, please leave them in the comments!