COM-FSM Seal College of Micronesia-FSM
Federated States of Micronesia
 
 
Computing · Directory · Home · Employment · Library · News

Computing
Facilities
Personnel
Activities
Statistics
Technology Policy

Resources
Virus Information
Web Tools
Software
How-To
Manuals
Monitoring

Learning
UNIX Commands

UNIX Command of the Day - top

Topic: System Load and Process Monitoring

When it becomes apparent that system load is higher than it should be, the task of locating the problem starts. Any running process may be the culprit, although on any system there are typically some regular abusers of resources.

The top command available on Linux provides a good overview of things including CPU and memory utilization, and a list of the top consumers of CPU. Best of all, it updates it's display every few seconds so you can monitor continuously.

Here's some sample output:

  9:08pm  up 7 days, 13:28,  2 users,  load average: 0.00, 0.01, 0.00
86 processes: 85 sleeping, 1 running, 0 zombie, 0 stopped
CPU states:  0.3% user,  2.9% system,  0.7% nice, 95.9% idle
Mem:  387600K av, 384176K used,   3424K free,  40940K shrd,  52644K buff
Swap:  66540K av,    680K used,  65860K free                180948K cached

  PID USER     PRI  NI  SIZE  RSS SHARE STAT  LIB %CPU %MEM   TIME COMMAND
26273 kgirrard  12   0  1052 1052   840 R       0  2.7  0.2   0:02 top
  561 nobody    13   0 58876  57M  1044 S       0  0.7 15.1  68:51 squid
 2341 kgirrard  12   5 60884  59M  1216 S N     0  0.7 15.7  24:13 java
    1 root       0   0   472  472   408 S       0  0.0  0.1   0:03 init
    2 root       0   0     0    0     0 SW      0  0.0  0.0   0:00 kflushd
    3 root       0   0     0    0     0 SW      0  0.0  0.0   0:00 kpiod
    4 root       0   0     0    0     0 SW      0  0.0  0.0   0:00 kswapd
    5 root     -20 -20     0    0     0 SW<     0  0.0  0.0   0:00 mdrecoveryd
  316 bin        0   0   364  364   300 S       0  0.0  0.0   0:00 portmap
  351 root       0   0   552  552   472 S       0  0.0  0.1   0:00 apcupsd
  373 root       0   0   716  716   588 S       0  0.0  0.1   7:39 syslogd
  384 root       0   0   756  756   388 S       0  0.0  0.1   0:00 klogd
  398 daemon     0   0   472  472   400 S       0  0.0  0.1   0:00 atd
  412 root       0   0   592  592   504 S       0  0.0  0.1   0:00 crond
  430 root       0   0   564  564   476 S       0  0.0  0.1   0:05 inetd
  444 root       0   0  2344 2104   572 S       0  0.0  0.5   0:45 named
  458 root       0   0  1324 1324  1140 S       0  0.0  0.3   0:01 xntpd

The first line should look familiar. It's the same first line that w displays. After that it gets interesting.

The number of system processes is displayed next, broken down into sleeping (waiting for input or output to occur), running (in the process queue), zombie, or stopped. Zombie and stopped processes consume memory but not other resources. They can indicate trouble, however, so if there are any it may be worth checking on them.

CPU states relates what type of activity the CPU is being used for. System activity might be considered overhead; it's the work required to keep other things working. This includes management of processes, virtual memory, and other non-task oriented activity. User activity is anything running directly on behalf of users of the system. The web server and proxy, WebMail, and e-mail services are user activity. Nice is utilization by processes whose priority has been raised by the system. (The mdrecoveryd process in the sample output is one; it's nice value (NI) is -20.) All remaining activity, or lack thereof, falls under idle.

Memory utilization follows, showing available (av), used, and free memory. Shared memory (shrd) is used by multiple processes concurrently (if two people are running the same program at the same time, the code for the program is only loaded in memory once but used by both people). Buffer (buff) and cached memory relate how much is in use for disk buffers and cached, recently accessed data. Large amounts of each improve overall system performance. When memory is short, these are reduced in size, especially the disk cache.

The remainder of top's display, the most active processes, is nearly identical to output from the ps command.

Top has a lot of options and commands that can change how information is displayed while it is running. Check the man page for complete information. The question you probably will have first is "How do I stop top?" Press q.

The Manual Page for top

Back to UNIX Command of the Day

Navigate graphicTo COM-FSM Home Page