Basics of Process Management

terminal-glossy.jpg

What do you do when you can’t make your process stop no matter how many times you click that little X in the corner?

Each of these different things happening on the computer is called a “process”, and your computer takes turns letting all of the processes run a little bit at a time. The computer works so fast that you usually don’t even notice.

But occasionally, a process stops responding to you. What do you do when you can’t make your process stop no matter how many times you click that little x in the corner? You try using the keyboard commands Esc and Ctrl + C. You even try Ctrl + Q, Ctrl + X, and Ctrl + Z; but they don’t work. What do you do next?

To discover the basics of how to manage processes in linux, watch and read the following tutorial.

If you can get into a terminal, you can kill any process

Well, if you can get into a terminal, you can kill any process. The command is called kill. The command name is easy enough to remember, but your problem is knowing what to kill. Each process has a different process identification number (PID) and you must use that number to kill it.

To see a list the processes currently running on your system, you can use the command ps. If I open a terminal program and type ps now, I will see this:

rosalyn@onizuka:~$ ps

  PID TTY          TIME CMD

14036 pts/2    00:00:00 bash

14040 pts/2    00:00:00 ps

(The prompt on my system says rosalyn@onizuka:~$. Needless to say, your computer will say something different. When I show an example like this, only type the words after the dollar sign. The computer’s response will be shown on the following lines.)

The computer responds telling me what processes I am currently running in this terminal window. First, I am running the terminal window itself using the BASH shell. Then I am running the command ps. That’s not very informative. Is it?

I would really like the computer to show me all of the processes running on my system. To find that, I must use options (letters typed after the command that modify its function). In order to see all of the processes running on my system, I use the ps aux command:

rosalyn@onizuka:~$ ps aux
  • ps reports a snapshot of the current processes running on your system.
  • a tells the computer to show all processes
  • u tells the user name of who owns the process, and
  • x lists processes that were not started in a terminal.

This command will return a long list of processes that scrolls off my terminal screen. Somewhere in that list is the process ID that I am looking for. If I am using a terminal with a scroll bar, I can just scroll back up and read it all to find the process. Personally, however, I prefer to use a different command to get the process ID. The command called top. Top is much like a command line version of Windows “task manager”. For a more advanced Top I tend to use an application called htop. It can be easily installed in Suse via “zypper in htop” as the superuser. But for the sake of the document we’ll stick with top as it comes with all linux systems.

Tasks and processes

What’s the difference between a task and a process? Nobody knows. For the most part people use the word task when they are talking about sending things to the processor to avoid saying things like, “the processor processes the process”.

Well, actually, there is a difference between tasks and processes. The process that starts your computer is called init. It is listed by the process ID 1. This process is also called Task [0]. For the most part, however, just consider tasks and processes to be the same thing.

Top lists the processes using the most time on the computer’s processor. It prints only what will fit in your terminal window, and it refreshes every few seconds to give you an up to date picture of your system. If your program has stalled, then it is probably taking up lots of processor time, and it will be right near the top of the list. Typing top on my system shows me this:

top - 00:15:36 up 10:53,  1 user,  load average: 0.79, 0.69, 0.58

Tasks:  86 total,   3 running,  83 sleeping,   0 stopped,   0 zombie

Cpu(s): 29.9% us,  6.6% sy,  0.0% ni, 62.8% id,  0.0% wa,  0.3% hi,  0.3% si

Mem:    484292k total,   361820k used,   122472k free,    25596k buffers

Swap:  1421712k total,        0k used,  1421712k free,   169384k cached  PID   USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

  13247 rosalyn   16   0  155m  67m  46m R 26.3 14.2  11:58.69 seamonkey-bin

   3363 root      15   0 93448  50m  44m S  9.0 10.6   6:05.50 XFree86

  14032 rosalyn   15   0 27320  14m  25m S  1.0  3.0   0:02.04 konsole

  13227 rosalyn   15   0 14168 9928  11m S  0.7  2.1   0:09.65 gvim

   3094 gkrellmd  15   0 18824 1340 2240 S  0.3  0.3   2:24.32 gkrellmd

  13207 rosalyn   15   0 26532  14m  23m S  0.3  3.1   0:01.69 kdeinit

  14196 rosalyn   16   0  2104 1084 1888 R  0.3  0.2   0:00.11 top

      1 root      16   0  1516  520 1364 S  0.0  0.1   0:00.58 init

If you lengthen the terminal window, it will show more data. Now, suppose the program “seamonkey” was frozen. I could kill it by typing the command kill followed by seamonkey’s process ID 13247.

Of course, to do this I need to get a prompt again. Top will keep refreshing in the terminal window until you tell it to stop. Both the letter q for quit and typing the control button and c at the same time (Ctrl + C) will stop the program and give you back your prompt.

To kill seamonkey, I can type:

rosalyn@onizuka:~$ kill 13247

This should stop the process causing the seamonkey window to close, but sometimes it doesn’t. What do I do if seamonkey still won’t close?

Well, kill also has options. The basic command tries to be nice. It says, “Could you please stop now?” But if the process just won’t die when you ask it nicely, then use the option -9. The command kill -9 says “take no prisoners!”

So if kill alone doesn’t work, I can type:

rosalyn@onizuka:~$ kill -9 13247

No Posts Found

Comments are closed.