How to find and kill a process using a Linux terminal

Each program running at the end of the server can generate one or more processes. A single server can have multiple users that execute many commands that will execute processes. These processes can trigger both foreground and background. If the program is running in the foreground, it may occupy the terminal on which it was originally launched, and other applications cannot even be launched while other processes are still not running in the foreground. Taking into account that other processes can also be executed in the background, in this case, the terminal in which we launched our program can add additional new commands while the program is still running. Demons are also a type of process that continues to run continuously. They listen to requests on specific ports. They are usually initialized at system startup and just wait in the background and remain in standby mode until their service is needed.

Sometimes during operation, our system stops responding, the process can also take up a lot of system space and even stop. So, we need to find and kill such a process in Linux to continue. There are many ways to kill the process on Linux, which will be discussed in this guide. A process can be forcibly destroyed by these commands.

I used Ubuntu when implementing this article. However, teams can work on any Linux distribution.

Finding a Linux process

Step 1: First of all, open the terminal by clicking on Ubuntu Launcher and find the terminal.

Find a Linux terminal

Step 2: Now click on Terminal and wait for the terminal to open.

Launch a Linux terminal application

How to find and kill a process using a Linux terminal

Step 3: After opening the terminal you will have the following screen:

The shell window is open

Here, in the next steps, two keys are important:

  1. PID is the process identifier. Each individual process has its own 5-digit number assigned to the process itself. Numbers can be repeated when they reach the maximum limit, but are always unique to a process in the system.

Step 4: top – The command is used as the main command for viewing all currently running processes using the resources of a computer device. So, we execute the top command in the terminal, and the results

Use the top Linux command to locate the process

on top is the application itself. It can be used to display a list of all processes and has a new layout when it runs. Here is an example of this,

  • hour – Used to display Help window. The help window has all the commands; they provide information that is very useful.
  • Space – When you click on the space bar, we get an immediate update of the process table. We will not wait for any time interval.
  • e – add files to display in the layout or delete to delete certain specific fields in order to stop their display.
  • Q – used to exit top application, and also used for an additionally open window
  • L – used to switch the display of information about the average load and uptime.
  • m – used to switch the display of memory information.
  • P (Shift + p) – used to sort processes by processor usage.
  • s – Used to change the delay between updates.

Step 5: There is another team to see a list of all currently running processes, we use “ps –A | Smaller” command.

Linux ps command

A list of all currently running processes appears. This process shows all running processes that are associated with them. IDP “Process Identifiers.” You can also browse this list to find out the name of the process, which also corresponds to the program that you really want to kill. The programs that run last are displayed at the end of the list that you want to remove from the list. In our example, we used Firefox as a process that interests us to be killed.

Processes and their PID

When you’re done, click “Q“To exit this window.

Kill process by ID

Once we get the PID, we can use the kill command to kill the process from the information we got from the ps –A command.

Step 1: To do this, we use the command “sudo kill PID”. Where PID is the identifier of the process we want to kill.

Linux kill command

If we want to kill a specific process, we see the corresponding PID, and then use it to kill this running process. For instance. we want to kill the firefox process, so first we find its PID.

Process list

How to find and kill a process using a Linux terminal

So here is the Firefox 999 PID. We use “sudo kill PIDKill the Firefox process.

Kill the firefox process

Then we check all running processes as soon as we kill the process of interest to us, using “ps –A | less “team”. The result shows that we have no Firefox process (PID: 9999) in the list.

Check if the process has been killed

Kill a process by name

Killing a program using the name of its process only works for all executable files (that is, all executable programs) that must be open at run time. All of these programs running in the background cannot be destroyed using the process name.

Now we will destroy the process of interest to us, using the name of this process. If we want to kill a specific process, we see the corresponding PID, and then use it to kill this running process. For instance. we want to kill the firefox process, so first we find its PID. Kill Linux process by name

How to find and kill a process using a Linux terminal

So here is the name of the Firefox process, and we use “Pkill firefoxThe team to kill this process.

Using the pkill Command

Then we check all running processes as soon as we kill the process of interest to us, using “ps –A | less “team”. The result shows that we have no firefox process in the list.

Check if the pkill command killed the process

Conclusion

Thanks for reading this article. We saw how we can find and then kill a process using its identifier or process name.

How to find and kill a process using a Linux terminal

Sidebar