Killing+Processes


 * Faster, @#$$%^&*! Kill! Kill!**

Sometimes the process you started hangs and nothing happens in the shell. If you started the process in the foreground (i.e., you executed some command) and it hangs simply use Ctrl-c to kill it. Sometimes it's not that easy though. You may have started an analysis in the background, but for some reason you want to terminate it, now. If you know what the process is that hangs you need to look up it's process ID to kill it.

For example, if my file manager called thunar does not respond and seems to hang I do the following: code format="bash" ps aux | grep thunar code ps aux gives me a snapshot of all processes running at the moment. The output of this is piped into grep where I filter the output so that I only receive the processes that I am interested in; here, the processes related to the file manager thunar.

The output looks like this: code format="bash" 1000     4316  1.2  0.4  59060 13656 ?        S    20:52   0:00 thunar 1000     4328  0.0  0.0   3300   752 pts/3    S+   20:52   0:00 grep thunar code I get two lines. The first line is the process I am interested in; it's the file manager. The second line represents my grep pattern matching search. To kill the process I need it's process ID, wich is in the second column of the report I just generated (here, 4316).

SIDETRACK If you want a cleaner output you can filter the above output once more using an inverse grep search to get rid of the line that reports the grep command you issued: code format="bash" ps aux | grep thunar | grep -v grep code This results in the following report: code 1000     4316  0.2  0.4  59140 13704 ?        S    20:52   0:00 thunar code Neat, eh? END OF SIDETRACK

Now the process can be killed: code format="bash" kill 4316 code Sometimes the default kill signal (sigterm) gets intercepted and ignored by the process and the process does not get killed. Should this be the case you can issue a signal that cannot be ignored by the process to be killed (sigkill). code format="bash" kill -9 4316 code

If your shell is unresponsive, but you have an idea which process hung it up, you can open a second shell and log into the system (you can log in to multiple shells on the same machine at the same time!) and kill the offending process from there.

Ideally, you issue kill commands as a non-privileged user. If you're a super user you can kill any(!) process, including those that are integral to the operation of your operating system. An unwise kill command may bring down your computer, instantly. Think before you type!