Monday, August 24, 2009

Kill misbehaving apps fast

Although the Linux kernel is extremely stable, you do run into misbehaving apps that eat your CPU for lunch. The worst offenders tend to be web browsers with flash. The biggest one of them all for me, is Opera and the hulu.com site. If I dare to point Opera at hulu, it is game over for my CPU.

The normal GUI procedure for getting rid of a running process is to use System Monitor (Gnome) or KSysGuard (KDE). You then go down the list to the find the offending application and you click on the kill/end process button. The problem with the all-out GUI method is that usually when you need to kill a task/app, your machine is already straining under the load and you don't need or want another one starting up. Both the System Monitor and KSysGuard tends to consume a lot of CPU resources themselves and therefore are poor choices for getting rid of a task.

Method 1: Use the xkill utility

If you are using the latest Ubuntu or Debian GNU/Linux distribution, this should be installed already and ready for use. To execute xkill, open the run application dialog box by pressing ALT-F2. If you are using KDE you will open Krunner (also ALT-F2). Type xkill and click on the Run button. You will notice that your cursor now changes to a X instead of the usual mouse pointer. On some distros the pointer changes to a cool Joli Roger (Skull and Bones). You then move your mouse to the application window you want to zap and click with the left mouse button. Boom - it is gone and you have your CPU back. If you decide you don't want to kill anything, you click the right mouse button (On some distros you have too press 'Esc' to cancel).

Method 2: Use the pkill command

The ultimate in process destruction and fastest draw in wild wild west is pkill. Start pkill with Alt-F2 (Run Application) and supply the name of that application you want to kill. Warning: Pkill has a broad sword and will kill anything that matches your search string (application name). See example below where I show firefox the door.