Killing misbehaving programs and processes

Note: This is a straight up rip of the tutorial of the same name from the Beginner’s Linux series on my personal blog (on my personal site), but it’s content is eminently suitable for FOSSwire readers, so I’ve re-posted it here. Enjoy!

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 (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!

Avatar for peter Peter Upfold -

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Killing misbehaving programs and processes

  1. Fabien (guest)

    # Posted on 28 February 2007 at 03:37 PM


    Do you know if a gui for an app killer exist on Linux. Granted, the command lines are powerful, but it is slow to type 'ps aux | grep', then 'kill' that I do miss windows task manager on my LInux system


  2. Peter (guest)

    # Posted on 01 March 2007 at 01:35 AM

    Yes, I believe there is!

    If you use GNOME, head to the GNOME System Monitor (probably under Applications > System or Applications > Utilities).

    If you're a KDE user, press Alt-F2 and type <strong>ksysguard</strong> and press enter.

    Hope this helps!

  3. Tom (guest)

    # Posted on 01 March 2007 at 08:13 AM

    Commandline killing doesn't have to be slow:

    Using Yakuake, I simply hit F12 and enter 'killall ' after which I hit F12 again, hiding Yakuake: done.

  4. mistah X (guest)

    # Posted on 10 September 2007 at 12:09 PM

    Fabien, I bet you like this interface

Home » Articles » Killing misbehaving programs and processes