Using top

Although ps is a very flexible and useful tool, it has a major shortcoming: Its output is static. One common problem you may encounter is the need to determine which processes are consuming a lot of CPU time. Such resource consumption can spike momentarily, so running ps to locate over-consuming processes doesn't always work. What's needed is a dynamic tool—one that takes a reading, then takes another reading a short time later, and so on, updating its display with every reading. If this tool sorts its output according to the CPU time use, CPU-hogging processes become obvious because they'll appear consistently at the top of the list. Other processes may run up and down the list as they make momentary demands for CPU time. Linux provides a tool that does just this, and its name is appropriate: top.

Basic use of top is fairly straightforward: Type top. The result should be a display similar to the one shown in Figure 14.2. This figure shows that the FahCore_65.exe process is consuming huge amounts of CPU time—89.5 percent of CPU time at the moment the screen shot was taken, with a cumulative total of 1,948 minutes. The X

process (XFree86) comes in a distant second, with 5.8 percent and a cumulative total of 86 minutes of CPU time.

Figure 14.2: The top utility provides a dynamic display of resource use. Note Several different top utilities are available, and produce output that's formatted slightly differently. For this reason, your output might have fields with slightly different names or positions than are depicted in Figure 14.2, but more-or-less the same information should be available.

Figure 14.2: The top utility provides a dynamic display of resource use. Note Several different top utilities are available, and produce output that's formatted slightly differently. For this reason, your output might have fields with slightly different names or positions than are depicted in Figure 14.2, but more-or-less the same information should be available.

Interpreting top's output isn't always easy. For instance, is the huge resource use of FahCore_65.exe excessive? Such a CPU hog might seem out of line at first glance, but in this case it's not; FahCore_65.exe is a distributed computing client for the [email protected] project (http://folding.stanford.edu), which aims to help scientists better understand how proteins "fold" within cells. This project necessarily requires a lot of CPU time, and the [email protected] project uses donated CPU time. If you examine Figure 14.2 again, you'll see that the FahCore_65.exe process is running with a nice value (the Nl column) of 19. The nice utility and the meaning of nice values are described in the upcoming section, "Starting Processes with nice," but for now, know that a nice value of 19 means the process is using CPU time only when other processes don't need it. As a result, this process's impact on the system is minimal. Of course, somebody unfamiliar with the system whose top output appears in Figure 14.2, and unfamiliar with [email protected] and its program names, wouldn't realize that nothing was wrong. The bottom line is that you must understand your own system in order to interpret CPU use information. It's also helpful to know something about typical resource use of common programs. For instance, it's not unusual to see X near the top of the CPU-use list, especially in terms of cumulative CPU use and when the system runs X continuously. If a small tool that normally terminates quickly, such as Is, starts racking up serious CPU time, though, something may be wrong.

In addition to the process-by-process data that dominates the lower two-thirds of Figure 14.2, top provides some overall usage information in the top third of its display. This information includes the time the system has been up, the number of users accessing it, the number of processes, total memory use, and three total CPU use figures (load averages), representing the load average over the past one, five, and fifteen minutes. A load average of 0.00 means that no processes are demanding CPU time (or that the demand is so low that it doesn't register). A load average of 1.00 means that programs are demanding exactly as much CPU time as the system can deliver. For instance, a single CPU-intensive program, such as the [email protected] client, imposes a 1.00 load average all by itself. Load averages above 1.00 mean that Linux must ration CPU time. Such a situation may spell trouble on a small single-user workstation, but other systems should run with higher load averages. A multiuser system or busy server, for instance, is likely to have a load average of well above 1.00. Precisely how high a load average is too high is impossible to say, because it depends on the computer and its function. A system with a high-powered CPU might run with a load average of, say, 3.0, and be subjectively faster than a system with a weaker CPU running with a load average of 1.0 or less.

Note Load average and system uptime information can also be obtained via the uptime and w commands. Thefree command returns memory use information.

In addition to displaying information on processes, you can use top to effect many of the changes described in the upcoming sections, "Improving Performance by Modifying Process Priorities" and "Killing Unwanted Processes." In particular, typing r enables you to change the nice value for a process, and typing k enables you to kill a process. You can also change many display options with command-line arguments or by typing characters once top is running. For instance, typing N sorts by PID number, M sorts by resident memory usage, T sorts by total CPU time used, and m toggles the display of system memory summary information. More options are described in the top man page or by typing h from within top itself.

0 0

Post a comment