How to Kill Processes in Linux \ Ubuntu?

If you are looking for different ways of killing processes or know what killing a process (kill Process) is, you are in the right spot. This article will explain everything you need to know about killing processes in Linux in detail. 

No matter if you are a Linux System Administrator, a Novice Linux User, or running and managing your own VPS Server on Linux. There might come a certain situation where you must kill a process manually. 

Looking for Affordable VPS Hosting Without Compromise? Check out Dracula Servers!

What is Killing a Process in Linux & Ubuntu?

There are many instances where the processes running in the Linux installation fail to exit on their own. It may be because the process has become unresponsive, the process encountered an error during the execution, or maybe just consuming a little too much of the system’s resources, and you need to use those resources elsewhere. 

In such cases, forcing the process to stop its execution and remove it from the working memory is known as killing processes in Linux. This action of stopping a process’ execution can be generous in that you let the process run its exit code and wrap up everything, or it can be forcefully terminated when you tell the kernel to stop a program instantly. 

Before you learn how to kill a process, you must know how it works.

How Does Killing a Process Work in Linux?

Every running program in the Linux Operating System (in every OS) has a unique PID, which stands for Process ID. This PID number is used to track the state and actions of the processes. The commands and tools kill a specific process by sending a signal to the OS along with the PID of the process to stop. 

However, caution must always be taken while trying to terminate or kill a process forcefully. Because if you accidentally exit a sensitive process (Kernel Processes), then you might end up damaging your Linux Installations.

How to Kill a Specific Process in Linux\Ubuntu?

Now that you are fully aware of what killing processes mean and how the killing process works, let’s move on to the steps for killing a specific process in Linux.

Step 1: Find the PID of the Process to Kill

The first step to killing a specific process is to know its Process ID (PID). There are various methods and commands through which you can easily find the process ID of the process that you want to kill. Let’s go through some of the most commonly used methods.

1. The top Command

The first command is the top command, which shows an overview of all the processes currently in your Linux Operating System. To this command, simply open up a new terminal and type “top,” and hit “Enter to get the following result:

In addition to the PID, the top command also shows the user and the amount of CPU and Memory consumed by the process.

2. The ps Command

The next command that provides a little more readable output of the processes running in the Linux System is the “ps” command. Unlike the top command, the ps command also shows the system “All” processes, including kernel and system processes. To display the details of all processes, simply use the following command:

ps -ef

Running this command will show you the following output:

Output of the ps -ef Command

Suppose that you want to kill the spotify process. Then you can see all of the processes associated with spotify. Killing the very first process will terminate all instances of spotify, which in this case is PID 6123.

3. The pidof Command

One of the easiest commands to find the Process ID of a certain application is to use the “pidof” command. To use this command, simply follow the below-given syntax:

pidof {appname}

To find the PID of spotify, use the command:

pidof spotify

You will get similar results to:

Output of pidof spotify Command

The most recent process of the application will be on the left, and the oldest on the right. 

Step 2: Kill the Process Using a Kill Command

Once you have found the PID of the process you want to kill, the next step is to simply use any of the available commands to kill a process. Let’s go through some most used Kill commands.

1. The Kill Command

The first and the most widely used command is the “Kill” command. The syntax of the kill command is given as follows:

kill {signal} {PID}

The kill commands tell the OS to terminate the Processes referred by the PID by using the Signal specific. Some common Signals are as follows:

  • The -9 Signal: To forcefully terminal a Process (Kill Signal)
  • The -15 Signal: To terminate the Process (Allows the program to run the exit code and stop its processing)
  • The -1 Signal: To hang up the process
  • The -17, -19, and -23 Signals: To stop the process (Stop Signal)

Let’s kill Spotify’s PID(from the previous section) using the -15 signal. To do that, type the following command:

kill -15 6847

Rerun the “pidof spotify” command to ensure that the process has stopped its processing. You will get the following result:

After killing Spotify using the kill -15 command

You have successfully terminated the spotify processes.

2. The killall Command

Instead of killing processes using the PID and having to either kill the parent PID or all child processes manually, you can use the Killall command. This command will kill all of the processes of a certain application. 

The syntax of the killall command is given as follows:

killall {appname}

To kill the processes of Firefox, use the following command:

killall firefox

An example of this command in action is displayed in the image below:

You can clearly see that Firefox was running a lot of processes. However, after using the killall command, all of the processes were terminated.

3. The pKill Command

The pKill Command is similar to the killall command and terminates the processes associated with an application. To use this command, follow the following syntax:

pkill {appName}

For example, if you want to kill the Firefox browser using the pkill command, then type the following command:

pkill fire

Here is the output of the pKill command in action:

You have successfully terminated all the processes associated with Firefox. 

Dracula VPS Hosting Service

Dracula Servers offers high-performance server hosting at entry-level prices. The plans include Linux VPS, Sneaker Servers, Dedicated Servers & turnkey solutions. If you’re looking for quality self-managed servers with high amounts of RAM and storage, look no further.Check the plans for yourself by clicking Here!

Wrap up

To kill a process in Linux, you need to find the Process ID (PID) of the process and then use the available kill commands. There are different commands that can help you find the PID of all processes. Similarly, there are various kill commands that you can use, all having a little difference in their working.

Moreover, an application can have multiple processes associated with it. In such cases, it is better to use killall or the pkill command.

Read more guides about Linux and Ubuntu at Dracula Servers Tutorials!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments