Linux Process Management: Command Line
Previously I wrote about using GUI tools for Linux process management (Get To Know Linux: Process Management.) Both the GNOME and the KDE tools are outstanding, user-friendly solutions to an issue that can often become troublesome. But what if you are running a headless server? Or what happens if that runaway process is X Windows itself? What do you do? You open up a terminal window and issue a command. In this article you are going to learn just that, killing rogue processes by command line.
Although you might think this a system of process management that should be avoided by the new user, you should consider that there may be times when knowing this process can really save your skin. So, although you may tend to shy away from the command line tools, this would be one of those that is good to know in a pinch.
The first thing you have to understand is the commands you will be using. There are two commands that are useful: kill and killall. The kill command is used in conjunction with a process ID (PID) and the killall command is used in conjunction with command names. Your first reaction is most likely "How do I get the PID of an application?" Well, that will take another command.
Learn By Example
Let's use Firefox as an example. Say, for some reason, Firefox has frozen and you can not get it to respond. Open up a terminal and issue the command killall firefox if that doesn't kill Firefox then Firefox was started with a different command. To find out what that command is you could employ the ps command like so:
ps aux|grep firefox
The output would look something like:
[jlwallen ~]$ ps aux|grep firefox
jlwallen 10199 3.8 28.8 417396 223764 ? RNsl Feb23 77:22 /usr/lib/mozilla/firefox-bin -a firefox
jlwallen 13434 0.0 0.0 3796 688 pts/0 RN+ 20:14 0:00 grep firefox
You see the line that includes firefox-bin? That is most like what you need to kill. So issue the command killall firefox-bin and the frozen Firefox will go away.
If you look up at the command output again you can see the output includes the PID of each command. The PID associated with firefox-bin would be 10199. You could issue the command kill 10199 and Firefox would close as well.
What if X Windows freezes and you know the culprit was, say, Evolution? You can't get to a terminal window so what do you do? You have to go to a different virtual console. To do this you will hit the key combination Ctrl-Alt-F* (Where * is a number 1-9. This number will differ depending upon which virtual console X is running.) Once you are in a virtual consol you will have to log in as your user and then issue the kill command. You can then go back to the virtual console running X and, hopefully, it will be back under your control.
It's not as user-friendly as either the GNOME or KDE tools, but this method is a very valuable method of process control. Some day you will need to have this method in your tool belt and, when you do, you'll be glad you have it.Advertisement