This site is currently on indefinite hiatus. For fresh, new Linux & productivity content, head on over to nathanrhale.com/linux/ and subscribe to the Linux-only feed.

Optimizing Performance

How to Kill a Running Process in Ubuntu (or any Linux distro)

February 12th, 2009 | 15 Comments

This guest post was written by Blair Mathis from LaptopLogic.com. Go there to check out newest laptop models and read latest news about Dell laptops.

So, you’ve been running Ubuntu for awhile and you’re happy with it. Everything is running smoothly. You think to yourself, this is going better than I expected. And then, out of nowhere, Firefox (or some other mischievous app) crashes. You try to reopen it, only to find this warning: “Application X is already running. Please close all versions of the application and try again.” You instinctively hit ctrl+alt+delete, only to remember that you’re not in Microsoftland anymore. How exactly do you kill a running process in Ubuntu?

Upon first glance, killing a process in Ubuntu may seem frightening. Rest assured that it is not. There are a few different methods for killing a process–in fact, you can even set up a ctrl/alt/delete sequence–but by far the easiest is to simply open the terminal and type one simple line. It literally takes less than ten seconds.


Step 1: Open the Terminal by navigating to Applications > Accessories > Terminal. Type: ps aux and press enter.

A long series of processes will appear in your Terminal.

process1

click for full size image

Step 2: Scroll through the processes and look for the application you want to kill. If you’re logged in as a user, scroll down past the ‘root’ processes and into the processes running under your username. Look at the end of the lines for the name of the applications. For example, if you need to kill Firefox, look for ‘usr/lib/firefox’ at the end of a line.


Step 3: Once you find that process, look at the very front of the line. You will see something like “username 23873 6.8…..” It’s the number right after the username you need–in this case, 23873. That is the process number.

process2

click for full size image


Step 4: Now, to simply kill that process, type: sudo kill -9 process number (replaced ‘process number’ with the actual number) and then press enter.

process3


The process will be shut down. Close the Terminal and restart the application.

How do you effectively kill a running process on your *Nix platform?

Share and Enjoy:
  • Digg
  • del.icio.us
  • Furl
  • NewsVine
  • Slashdot
  • StumbleUpon
  • Technorati
  • Facebook
  • TwitThis
  • YahooMyWeb

15 Responses to “How to Kill a Running Process in Ubuntu (or any Linux distro)”

  1. In Ubuntu, for most applications, you can open the system monitor under the system tab, go to the processes tab, highlight the one you want and click the kill button.

  2. I like to do a combination of step 1 and 2 if you know what program you are searching for. Say you want to kill firefox, you can use the grep command to just display the lines that have firefox in them. Ex:

    ps aux | grep firefox

    by using the | (pipe) you can reroute the output of a command into another command, so instead of displaying ps aux to the screen you are routing it to grep and then grep searches for lines containing firefox and displays those.

  3. I usually go with the much quicker:

    ‘killall firefox’

    and that usually kills what I need kills.

  4. another way which could be easier if the crashed program window is still visible is to run xkill. All you have to do is click the window that crashed and it will stop.

  5. I use top. (BTW, it often helps to have a tall terminal window–I run 80×50.) I like it because it updates automatically every 1 sec to show what is using the most CPU. The key commands to user are:
    h — to get help
    k — to kill a process (it will ask you for the PID after pressing ‘k’)
    — to sort the various columns (which helps to bring a process buried in the list to the visible part of the list)
    q — to quit

  6. Since this is Ubuntu, why not:
    System -> Administration -> System Monitor
    right-click the offending process -> kill?

    Your solution is pretty much distro-agnostic and can work even without X or over ssh, but if you’re on the GNOME desktop isn’t this easier?

  7. -9? It’s for murdering a renegade process, not for killing a running one :)

  8. As this asumes that you run X, then I can guess that it’s a graphical program that has crashed. Most often the easiest way to kill the process is:
    alt+f2 and enter xkill

    You’ll get a skull-shaped pointer and just klick on the window and the process behind it will be killed.

    Another way is to start the GNOME-system-monitor and select processes there. It’s like ps aux, but graphical. Right-click on the process you want to kill and select “kill process”.

  9. killall firefox or killall -9 firefox can be used. On the other hand on KDE after a few attempts to close the window that is not responding, you gey a dialog offering to kill it.

  10. I find it easier to grep for the application you’re looking for rather than search through the whole output of ps aux. Example: ps aux | grep firefox

    Also, if you want to kill all instances of Firefox (or any other application you happen to know the ‘proper’ name of, use killall. Example: killall firefox

    Also, using -9 isn’t recommended (I can’t remember why). It’s better to try kill without it and if that fails, use -9.

    Also (this is the last one I promise), there is xkill. I have it in my quick links on my taskbar - if a GUI application is playing up, just click the xkill application and then use the mouse to click on the rouge application. Poof - gone!

    Hope these help somebody,
    Damien

  11. I’ve always used:

    killall firefox

    or done it from htop (find the process, hit f6 or some such to kill).

    It’s not foolproof, but it works most of the time.

  12. pkill works fine in kubuntu …

  13. You know what would be super cool and awsome? If you would somehow get the message across in the headline that this is for linux in general and not just a specific distribution.

    Thanks!

  14. @factotum218 - edited the headline to make things more clear. Thanks!

  15. sudo killall -9 firefox

Leave a Reply