In GNU/Linux, because almost all the
come with some sort of , killing or . 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 … 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 …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’.If you know the exact process name of an app, then you can use it in the below format.killall For example, if I want to kill the process ‘firefox’, then I’ll use the below command.killall For killing two or more processes at once …killall
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 Replace ‘process-name’ with your process and, well, that’s pretty much it!.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.killall 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 killall -I … etc.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 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 pgrep -lf 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 pgrep -lf pgrep -lf pgrep -lfAnd 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 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.killall 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.killall Again, make sure to replace ‘mplayer’ with your own process name.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 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.kill ‘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 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 kill 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.Related Posts
An RHCE, ‘Linux’ user with 14+ years of experience. Extreme lover of Linux and FOSS. He is passionate to test every Linux distribution & compare with the previous release to write in-depth articles to help the FOSS community.Hi Gayan,I’ve always got Htop running so if I need to kill anything I just swap to
Htop, scroll down to what needs killing, and hit F9 to kill it. CheersAlan This site uses Akismet to reduce spam. .Recent Posts
ContactAbout HecticGeekWelcome to HecticGeek, it is an independent blog founded back in 2010. We cover in-depth Linux OS, product review with other all technology-related software and tools. Our mission is to provide valuable and trustful technology-related content to our users.