View a Dynamically Updated List of Running Processes


top

On occasion you'll find that your Linux machine suddenly slows down, apparently for no reason. Something is running on your computer at full tilt, and it's using up the processor. Or perhaps you'll start running a command, only to find that it's using far more of your CPU's cycles than you thought it would. To find out what's causing the problem, or if you just want to find out what's running on your system, you could use ps, except that ps doesn't update itself. Instead, it provides a snapshot of your system's processes, and that's it.

The top command, on the other hand, provides a dynamically updated view of what's running on your system and how many system resources each process is using. It's a bit hard to see in a book because you can't see top update its display every second, but here's what you would see at one moment while top is running.

$ top top - 18:05:03 up 4 days, 8:03, 1 user, load average: 0.83, 0.82, 0.97 Tasks: 135 total, 3 running, 126 sleeping, 2 stopped, 4 zombie Cpu(s): 22.9% us, 7.7% sy, 3.1% ni, 62.1% id, 3.5% wa, 0.1% hi, 0.7% si Mem:    1036136k  total,  987996k used,   48140k free, 27884k  buffers Swap:   1012084k  total,  479284k used,   532800k free, 179580k cached  PID  USER  PR  NI  VIRT  RES  SHR  S %CPU  %MEM TIME+   COMMAND 25213 scott 15 0 230m  150m   15m S 11.1 14.9  33:39.34 firefox-bin  7604 root  15 0 409m  285m 2896  S 10.8 28.2 749:55.75 Xorg  8378 scott 15 0 37084  10m 7456  S  1.0  1.1  13:53.99 kicker  8523 scott 15 0 69416  13m 3324  S  0.7  1.3  63:35.14 skype 29663 scott 15 0 76896  13m 4048  S  0.7  1.3  13:48.20 quanta 


The top command gives you a great deal of information about your system in the first five lines of its output, and then it focuses on listing each running process. Note that top automatically sorts the output by the numbers in the %CPU column, so as programs use more and then less of your processor, their position in top changes as well.

If you want to kill programs from within top, just press k. At the top of the listings, just after the line that begins with Swap:, you'll see the following:

PID to kill: 


Enter the PID for the process you want to end (let's say 8026), press Enter, and you're asked what signal number (discussed in the previous "End a Running Process" section) you want to use:

Kill PID 8026 with signal [15]: 


By default, top wants to use 15. If you're happy with that, just press Enter; if not, enter the signal number you want to use and then press Enter. A second or so later, that process will disappear from top.

To exit top, press q.

The top command is incredibly useful, and you'll find yourself turning to it often, just to find out what's happening on your Linux machine. When you have questions about your computer's activity, top often provides the answers.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net