Skip to content

Killing misbehaving programs and processes

Beginner's Linux

It’s time for another quick Beginner’s Linux!

I’d love to say it doesn’t happen on Linux, but very rarely it does. I can say it happens less often than on Windows, though. What am I talking about? Programs and processes misbehaving – locking up, stopping working and generally causing a problem.

The problem on Windows is that if this happens, there’s no sure fire way to just nuke the offending app from your running processes. Yes, you can use Task Manager and close the process, but if that doesn’t work, well… (bad memories here).

On Linux, if this situation does occur, you have a couple of wonderful programs called kill and killall that are invaluable for killing things when they go wrong (saves many a restart of the whole system).

This is going to be quite a quick tutorial, partly because the subject matter doesn’t take that much time to cover and partly because I’m starting to get quite a lot of work I have to do, which means I’m going have to be a bit brief. Anyway, onto the tutorial…

Your first port of call is to try running kill normally on the offending process. In this example, we’ll presume that Firefox has stopped behaving.

First of all, you need to get the process ID number of the process. In this case, we’re looking for firefox-bin. So we need to launch a terminal (it’s that time again) and do the following:

$ ps aux | grep -i firefox-bin

First, let’s look at what this is doing. ps aux gets us a list of processes, then we are taking the output of that and running it through grep (it’s a way of finding every line containing something). We ask grep to be case-insensitive with -i and we ask it to display all lines containing firefox-bin.

You will probably get multiple lines here. Pick out the one without any reference to run-mozilla.sh (and not the one saying grep) and look to the left. The process ID number is the number there. With any other program, the name of the process is generally the name of the program (without the -bin). There are some exceptions, unfortunately.

Armed with this information, we can now kill Firefox. If you do this now and you’re running Firefox reading this, Firefox will close without warning!

Now simply run kill and tell it the process ID we found out (replace nnnn with the number we discovered earlier.

$ kill nnnn

Bang! The offending program should be dead beyond recognition now and your problem will hopefully be alleviated. Of course, on some occasions nothing happens when you try and kill something.

Basically, kill isn’t actually killing the process at this stage. It’s asking it nicely – “x, I would very much appreciate it if you would close down… like now.”. When a program is being particularly stubborn, this won’t work.

In these cases, you set kill from stun, to … sorry. Instead of asking nicely, we simply forcibly remove it from running on the machine. A word of warning – killing things in this way doesn’t give them a chance to clean up what they’re doing and you may end up with corrupted files and memory leaks in really bad cases. Use this as a last resort only.

$ kill -9 nnnn

The -9 is the difference here and does the job in 99.5% of cases.

But throughout all of this, there’s an easier way. So why have I shown you the hard way first? Because I thought it might be worth having a basic understanding of processes first. Plus, the method I’m about to show you sometimes kills more than you want it to.

killall allows you to specify a process name (e.g. firefox-bin or konqueror) instead of an ID. The difference is it will perform the killing on any process with that name, not just the specific one that might be going wrong.

It’s the same deal here:

$ killall name-of-process

And for those heavy-duty situations:

$ killall -9 name-of-process

That’s it!

Easy, simple and a heck of a lot better than getting stressed with Windows Task Manager which doesn’t give you (correct me if I’m wrong) an option to actually wipe the process off the face of the earth, short of hitting the power real fast, which of course would kill everything and probably damage your hard drive.

Wow, that was easy wasn’t it?

And as with all my tutorials, if you’ve got any suggestions, had a few problems or you genuinely found this useful, I’d love it if you’d drop a comment on this post, it makes writing these so worthwhile!

Like this post?

If you would like to support the time and effort I have put into my tutorials and writing, please consider making a donation.

4 Comments

  1. Chris wrote:

    In Ubuntu, we open the Task Manager, right click the process, and press “Kill Process”. Or we can just click the “X” in Firefox a few times and a Force Quit dialog will open up. Just click “Force Quit” and Firefox instantly closes.

    Who needs Terminal?! 😀

    Saturday, October 7, 2006 at 15:58 | Permalink |
  2. Peter wrote:

    Ha – fair point! 😀

    Maybe I should always mention the graphical methods first :P. Ah well, now you know how to do it in the terminal as well just in case the entire of Gnome packs up and you hit Ctrl-Alt-F1 and have to kill something that way.

    There’s always a use for the terminal :D.

    (Graphical vs command line debate? :P)

    Saturday, October 7, 2006 at 16:59 | Permalink |
  3. Shivi wrote:

    thanks, that was helpful.

    Friday, February 8, 2008 at 00:47 | Permalink |
  4. James wrote:

    Advantages / points of using the $ top command?

    Friday, June 20, 2014 at 17:34 | Permalink |

One Trackback/Pingback

  1. […] Killing misbehaving programs and processes […]

Post a Comment

On some sites, you must be logged in to post a comment. This is not the case on this site.
Your email address is not made public or shared. Required fields are marked with *.
*
*
*

Posting a comment signifies you accept the privacy policy.
Please note — your comment will not appear straight away, as all comments are held for approval.