How To Kill a Process in Linux
n this how-to we’ll look at various ways of using the terminal emulator to identify processes and how to kill them. A process can be an application or script running on your Linux machine. Sometimes a process can crash or become a memory hog and this is when we need to step in and “kill” the process. As ever, there are a multitude of tools that we can use to do this. We will use a variety of approaches and tools to identify and kill the processes.
All the commands in this how-to will work on most Linux machines. We’ve used a Ubuntu 20.04 install but you could run this how-to on a Raspberry Pi. All of the how-to is performed via the Terminal. You can open a terminal window on most Linux machines by pressing ctrl, alt and t.
How to Kill a Known Application in Linux
To begin, let’s open a software application and then, in the terminal, use the killall command to kill the application. We have used Inkscape, the free and open source vector graphics package as an example, but it doesn’t really matter what you use, just so long as you aren’t depending on it for anything at the current time.
Using the killall command kills all processes linked to the named application. Later we will look at using the kill command to kill a specific process.
1. Launch Inkscape, or another test application, from the system gui.
2. In the terminal, use the killall command to kill all Inkscape processes. You should see that Inkscape closes immediately when this command is issued.
killall inkscape
Identifying Different Processes in Linux
Often, software applications have numerous processes running and it can be useful to try and work out which one is likely causing the problem. For example, it could be one browser window rather than all of Chromium or Firefox.Then you can close the problematic process while leaving the rest of the app running. We can use the top tool in the terminal to look at, interact and then kill the rogue processes.
1. Launch the top tool in the terminal. When it’s launched, you will see the terminal populate with information regarding all the processes and their status. The second line of the top screen shows the total number of tasks, which are currently running and which are sleeping, stopped or zombie status. Below this you will see a list of processes and this information will refresh at a default of once every three seconds.
top
2. Press i to constrain the current processes list to those currently active. This can be very useful if you are only interested in current running processes and makes the list easier to read.
3. Press z to add color to the top interface to make it easier to read. Because this is a text based interface, adding color can help distinguish between labels and data.
4. Launch Inkscape or another non essential application.
5. Find the listing for Inkscape and note the PID. The PID is the number assigned to identify the process and they are listed in the first column of the top output. In our example the PID for inkscape was 4582 but it will be different each time Inkscape is running.
6. Press k and then type the PID number to kill the process.
7. Press ENTER and you should see a message “Send pid 4582 signal [15/sigterm]” which is confirming you want to kill this process. Press “enter” once more to confirm and kill the process.
8. Press q to close top and return to the terminal emulator. Often, you will want to look at top for a quick glimpse at the processes and then return to the terminal.
Read more: https://www.tomshardware.com/how-to/kill-process-linux