Skip to main content
p. 199

8.1 Tracking Processes

You learned how to use ps in Section 2.16 to list processes running on your system at a particular time. The ps command lists current processes and their usage statistics, but it does little to tell you how processes change over time. Therefore, it won’t immediately help you to determine which process is using too much CPU time or memory.

The top program provides an interactive interface to the information that ps displays. It shows the current system status as well as the fields a ps listing shows, and it updates every second. Perhaps most important, top lists the most active processes (by default, those currently taking up the most CPU time) at the top of its display.

You can send commands to top with keystrokes. Its most frequently used commands deal with changing the sort order or filtering the process list:

Spacebar Updates the display immediately

M Sorts by current resident memory usage

T Sorts by total (cumulative) CPU usage

P Sorts by current CPU usage (the default)

u Displays only one user’s processes

f Selects different statistics to display

? Displays a usage summary for all top commands

note

The top keystroke commands are case-sensitive.

Two similar utilities, atop and htop, offer an enhanced set of views and features. Most of their extra features add functionality found in other tools. For example, htop shares many of the lsof command’s abilities described in the next section.