How to kill a Linux process: Do you know when a program crashes on Windows and you have to open the task manager to force it to close? Here, this kind of thing does not only happen on the Microsoft home operating system: it also happens on operating systems generally considered more stable, such as macOS and Linux, and it is precisely these that I want to talk to you about today.
To be more precise, it is Linux that I want to talk to you about, and I want to do it to show you some of the best techniques to “kill”, that is to forcefully terminate the processes that no longer respond. There are various ways to do it and, since only now are you taking the first steps in this extraordinary operating system, I suggest you try them all.
I will use Ubuntu, one of the most popular Linux distros in the world (to be exact Ubuntu 16.04 LTS), but the indications in the tutorial are valid for many other versions of the penguin operating system. Courage, don’t wait any longer: take five minutes of free time and find out how to kill a Linux process by following the instructions below. I assure you it will be a breeze!
If you are used to Windows and its task manager, you will find the System Monitor interface very familiar , an application included as standard in Ubuntu (and other Linux distro) that allows you to view all the processes running on your computer and to ” kill “those who no longer respond.
To use System Monitor, go to the Linux Dash (on Ubuntu just click on the Search icon on the computer located in the left sidebar), look for System Monitor in the screen that opens and click on the utility icon that appears in the search results.
In the window that opens, locate the process related to the program you want to “kill”, select it with the mouse and click first on the End process button (located at the bottom left) and then on the End process button in the confirmation window that appears in the center the screen.
If the selected process does not close despite pressing the “End process” button, right click on its name and select the Kill item from the menu that appears. This way you should be able to force the selected process (and therefore the program) to close.
Another very simple way to kill a Linux process is to invoke the xkill command in the terminal. Using the xkill command, the mouse pointer changes to a small “x” and allows you to “kill” a program by simply clicking on its window.
Come on, try it now! Open the Linux terminal (if you don’t know where it is, look for it in the Dash), type the xkill command in the window that opens and press the Enter key on the PC keyboard.
At this point, the mouse pointer should have turned into an “x” and the word Select the window whose client you wish to kill with button 1 should appear in the terminal . Then click on the window of the program you want to end and the related process should be instantly “killed”.
To conclude, I want to show you some commands that allow you to kill Linux processes from the terminal. These are not comfortable or intuitive solutions such as those analyzed above, but it is always good to know them (even if only to deepen your confidence with the Linux terminal).
In some cases, in order for the commands to be executed correctly, the sudo prefix must be prefixed to the latter and the administrator password must be entered.
Through the kill command it is possible to terminate a process by simply indicating its ID, that is the identification code.
- To find out the identification code of a process, you need to open the terminal and type the command ps aux | grep name where instead of “name” you must enter the name of the program to be terminated. For example, to find all LibreOffice-related processes, you need to type ps aux | grep libreoffice .
- To end the process you must type the kill ID command , where instead of “ID” you must type the identification code of the process to “kill” (eg kill 4818 to end the process with ID 4818).
With the pkill command you can “kill” all processes that have a specific term in their name, without knowing their numerical ID.
For example, typing pkill firefox automatically terminates all processes that contain “firefox” in their name.
If you want to find out which processes contain a certain term in their name, type the command pgrep -l term , where instead of “term” you have to type the term that must be present in the name of the process.
If you know the exact name of a process and you want to “kill” it without tracing its numeric ID, use the killall name command , where instead of “name” you have to type the exact name of the process to be terminated (eg killall firefox to conclude the “firefox” process).
To find out what processes are running on your computer, type the command ps -ef . If, on the other hand, you want to find out what processes are carried out by a particular user on the computer, use the command ps -ef | grep name , where instead of “name” you have to type the name of the user being searched.
Finally, I point out that by using the top command you can view which processes are using the most resources (CPU and RAM memory) on your computer.
If you notice that your computer is running too slow, you can use the “top” command to locate the processes responsible for slowing down your PC and the “killall” command to end it.