Sunday, May 23, 2010

6 Different Ways To Kill Unresponsive Programs in Linux

Most Windows users know about the utility of the Ctrl + Alt + Del keys when dealing with an unresponsive application. A program is said to be unresponsive when it doesn't respond to any user interaction and neither does it perform its intended actions. There are plenty of jokes surrounding the whole Ctrl + Alt + Del combination that brings up the task manager in Windows and allows you to end unresponsive applications. Things seldom go this far in the Linux world, however claiming that such Linux unresponsiveness doesn't occur would be a plain lie.
The good thing about Linux is that you almost never have to hit the reset button due to unresponsive or hung applications. There are so many ways you can gain back control that you never have to resort to such extreme measures. In this article, we take a look at some of the ways you can deal with unresponsive applications on your Linux box.

Dealing with Linux Unresponsiveness – Using System Monitor

First and foremost you can use the familiar System Monitor tool. It looks a lot like the Windows Task manager, only it is better. Not only does it provide you with lots of information about the current state of the computer system, you can use the Processes tab to look for any misbehaving applications and choose to Kill or Stop the process. Both of these operations are very different in the Linux world: stop suspends the execution of the process and kill would close it completely.

kill unresponsive program

Using the 'kill' command

So far so good, however there are times when you cannot use the GUI altogether. Starting the System Monitor is out of question in such situations. In these situations, you can leverage the power of Linux command line to your advantage. You can enter these commands in a terminal if it is available or you can switch to a virtual terminal using Ctrl + Alt + F1 and logging in using the text mode.
Each running process has a unique process ID under Linux. If you know the process ID of the miscreant you can straightaway issue:
kill <processID>
to kill the misbehaving process. This should hopefully restore some sanity to your computer and you can switch back to the GUI using Ctrl + Alt + F7.

Using the 'pkill' and 'pgrep' commands

If on the other hand you don't know the process ID then you can either kill the process by its name or you can analyze all the running processes to diagnose the problem (using something like the top command).

You can use the pkill command to kill using process name. As an example the following command would kill Firefox:
pkill firefox
Notice how you didn't have to know or specify the process ID. Alternatively, you can use the pgrep command to get the process ID of any running process on the system. The process ID can then be used to kill or send other signals to the process.

Using the 'xkill' command

When using the GUI you can also use the xkill command which makes your mouse pointer all mighty and powerful After issuing the xkill command you can click on the application you want to kill and it will be gone and killed for you in a click!

Using the 'killall' command

Last but not the least, there is the killall command. Terrifying as it may seem, it doesn't kill all the processes running on the computer. Instead it is used to kill multiple instances of the same program. eg killall firefox will kill all windows and Firefox profiles that might be currently executing.

There are a lot more to these commands than what can be covered in a short write-up. 'pkill' for instance, lets you search for a process not only by its name but by the user who owns the process, the time it was started or lists all the processes that do not match a certain criteria. In addition, these commands can be used to send other signals to the processes as well. By default, SIGTERM is sent which may be ignored by some processes in which case you can use the kill -9 <processID> to send a KILL signal. You can learn about all the options by reading the manuals for the respective commands.


The battle for the FIH Hockey World Cup Drag n' drop

No comments:

Post a Comment