In GNU/Linux, because almost all the major desktop environments come with some sort of a system monitor, killing or terminating a hung up process is pretty easy. However, you can also use few built in command-line based tools for achieving the same task, and once you get used to it, most of the time, it’s actually extremely easy too!.
Also, even if you’re someone new, then having a basic understanding or learning few of these commands will not only come in handy, but most importantly, according to my personal experience, even after knowing few basic but important commands, have always improved my confidences in the OS itself as well.
So, even if you don’t think these commands might not be that useful to you, I humbly suggest that you at least try it out a bit, just for the sake of that ‘mental boost’ ;-).
Before we begin …
‘Official name’ vs ‘Process name’ vs ‘Process ID’
Though an application can have few names, but, usually its official name is also the name of its process. But, take ‘LibreOffice Writer’ (word processor) for instance. This is its official name, but the real process that executes it is called ‘soffice.bin’. So if we want to terminate ‘LibreOfffice Writer’, then ‘soffice.bin’ is the process name that we need.
And also, when you run a program, the operating system assigns a number to it and is called the process ID. This is not a fixed value and changes according to how many other processes are there etc (a process called ‘A’ might get the ID of ‘2000’, but if you close it and open it again, then it might not get same number because that it might already be taken by another process).
So before we can kill a process, we have to know its process’s real name or the ‘ID’ (you can do it without the ID, but it is necessary sometimes). Anyhow …
Let’s kill a process now shall we ? 🙂 …
There are few tools available in GNU/Linux for that, but for the sake of simplicity, I’ll focus on 2 tools. For terminating processes I’ll use a built in command called ‘killall’ and for searching and finding running processes and their IDs names, I’ll use another one called ‘pgrep’.
When you know the actual process name, it’s pretty darn easy! …
If you know the exact process name of an app, then you can use it in the below format.
For example, if I want to kill the process ‘firefox’, then I’ll use the below command.
For killing two or more processes at once …
killall process1 process2 process3
If you want to kill a process that was started with administrative privileges (sudo), then you’ll have to use it in the below format.
sudo killall process-name
Replace ‘process-name’ with your process and, well, that’s pretty much it!.
When you don’t know the actual process name …
2. Now let’s take something a bit tricky. If I wanted to terminate ‘Totem’ and if used the below command, then it will not work.
It’s simply because the process name of ‘Totem’ is called ‘totem’ (without the capital ‘T’). So in those situations, we can use the ‘killall’ command with the ‘-I’ argument, which makes it ignore the case sensitivity while searching and killing process. So after adding that you can kill ‘Totem’ without worrying about case sensitivity of letters.
killall -I Totem
killall -I ToTEm
Other ways of finding (hopefully) process names …
Sometimes you’ll have to guess, search and find process name, before you can kill them. I mean, how can someone guess that ‘soffice.bin’ is the actual name of the ‘LibreOffice’ ? :).
So for searching for running processes and their names/IDs we can use the ‘pgrep’ command (mentioned in the beginning) in the below format.
pgrep -lf process-name
The ‘-lf’ arguments are used for searching, again, make sure to replace ‘process-name’.
For instance, when I’m in doubt, first I search for the program’s process name by using simple letters and if that doesn’t work, then I also search using a part of its name as well. To find the actual process name of ‘Totem’, I can search using ‘pgrep’ using something like the below names.
pgrep -lf totem
pgrep -lf tem
As soon as I put that, ‘prgep’ gave a result that included ‘Totem’. The number before the name is its process ID (shown in the above screenshot). After that, I can use the ‘pkill’ for killing it.
Or, in other cases, finding the actual process name can be even more tricky, such as with of ‘LibreOffice Writer’. Those occasions, I can search for it using keywords like ‘libre’, ‘libreoffice’, ‘writer’ or ‘office’ etc that ‘describe’ the application (don’t put spaces into names, if you need spaces then use ‘-‘, otherwise it’ll give errors).
pgrep -lf libre
pgrep -lf libreoffice
pgrep -lf writer
pgrep -lf office
And in all of those occasions ‘pgrep’ was able to match those keywords to a process named ‘soffice.bin’. Though that doesn’t prove its it process name, but as you can see from the screenshot, it shows the directory path of that process, and it’s goes something like ‘/usr//lib/libreoffice …’ which we can use as a guess and can also guess that other one named ‘oosplash’ might be the ‘splash’ screen of LibreOffice.
Please remember that, if you’ve opened ‘Impress‘ and ‘Writer‘, then killing the ‘soffice.bin’ process will terminate both those applications as ‘soffice.bin’ is the parent process that handles them both!!.
Or let’s say that I opened the ‘Calculator’ tool in Ubuntu and I have no idea what its process name is called. Then I’ll search for something like ‘calc’ (again, only using a part of the program’s official name).
pgrep -lf cal
As you can see, it was able to find two process. But by having a look at the names I think you can guess which is what. In this example it’s actually ‘gcalctool’ and how do I know that? again, by simply using some common sense (gets better with use), because Ubuntu’s Unity desktop uses a lot of Gnome’s tool. Thus, ‘g’ might stand for ‘Gnome’ and ‘calctool’ should be ‘calculating tool’ (=Gnome’s calculator) etc.
After that, as usual, I can use the below command to kill it.
Dealing with multiple instances of the same program …
When used, ‘killall’ also terminates multiple instances of the same process too. Let’s say that you have opened a video and an audio file in ‘mplayer’, so two processes named ‘mplayer’ are running simultaneously. For killing them both, I’ll use the below command.
Again, make sure to replace ‘mplayer’ with your own process name.
Killing only the processes we need?
This is also bloody easy actually (easier than using most desktop system monitors). I’m using the above ‘mplayer’ example for this, and assuming that I want to Kill the video playback …
Because both processes are called ‘mplayer’, first I gotta figure out which one is playing the audio and which one is playing the video file and this time we will have to use the ID of the ‘mplayer’ process rather than its name, because otherwise it’ll terminate both those processes at once.
For that, I use the above mentioned ‘pgrep’ command as shown below.
pgrep -lf mplayer
This, as you can see from the below screenshot, gave me an output in which, both processes of ‘mplayer’ were listed, including the names of the files that they’re playing. So if I wanted to kill the video playback (‘Just Be.avi’), then I’ll use another process terminator called ‘kill’ instead of ‘killall’ because it doesn’t support using process IDs.
So, for that, I’ll put the below command in my Terminal window.
‘3263’ is the process ID of ‘mplayer’ that’s playing the audio file. Make sure to replace the ID for the process that you want to terminate accordingly.
Another benefit of ‘kill’ rather than using ‘killall’ is that, ‘killall’ only lets you enter program name that’s 15 characters or less. Though you still can terminate them using the ‘-e’ attribute (typing the first 15 characters of the process name after that), but in those occasions, it’s far easier to use ‘pgrep -lf’ to get the ID of that process and terminate it.
For example, if I try to terminate ‘gnome-system-monitor’ process using ‘killall’ then it’ll give me the following error.
‘no process found’
This is either because the process actually doesn’t exist or it’s too long (more than 15 characters) and ‘killall’ can’t find it (as with this case).
So one way to terminate it is to (still using ‘killall) type the first 15 characters of ‘gnome-system-monitor’ (=’gnome-system-mo’), exactly as it is, with the ‘-e’ argument as shown below, and it should do the trick.
killall -e gnome-system-mo
Or, you can use the below commands to find its ID (again, you can have to use ‘-‘ mark for spaces) first and then simply get rid of using ‘kill’ as well.
pgrep -lf system-monitor
Well, this is pretty much what most people would want to know about killing/terminating applications using the command-line is GNU/Linux. There are few other tools that we can use, but, for keeping this as simple as possible, I’ve only used 3 tools (primarily 2). Hope this was helpful, at least for some. Good luck.