Using top to monitor processes

combo-chart

In this tutorial, we'll show you how to use top to monitor your processes in real time. Top gives an overview of what cpu and memory resources the processes on your system are using.

Reading time:
4 min

Basic usage

To run top, simply enter the command:

top

This will display the top few processes (sorted by CPU usage). The display is updated periodically (default is every 3 seconds) to ensure the info displayed is up to date. This page refresh rate can be controlled by hitting either d or s and entering the number of seconds you wish to use.

To highlight the values in the summary aread, hit B (that is for Bold).

Saving your changes

Before continuing any further with customising top's look and feel for your purposes, be aware that you must save any changes otherwise top will discard them when you exit (exit by typing q).

To save any changes you make just hit W.

Tweaking the summary area

The first area to the top of the screen while viewing the top program is called the summary area.

You can toggle which bits of this are included in the display.

  • To toggle the showing of load average and uptime, hit l.
  • To toggle memory and swap space information, hit m.
  • To toggle task data and cpu state information, hit t.
  • To toggle showing each cpu, hit 1.

Different display types

There are four display types (where each display type shows different column fields, column ordering, and sort field).

The default display type is 1. To change the display type, hit G followed by the number (1 - 4).

These are the column headers available in each display mode:

Mode 1 will show the following columns in the display:

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

Mode 2 will show:

PID PPID TIME+ %CPU %MEM PR NI S VIRT SWAP RES UID COMMAND

Mode 3 will show:

PID %MEM VIRT SWAP RES CODE DATA SHR nFLT nDRT S PR NI %CPU COMMAND

Mode 4 will show:

PID PPID UID USER RUSER TTY TIME+ %CPU %MEM S COMMAND

Alternate mode

There is an "Alternate Mode" that you can use which shows the top few from each display type/mode. To use the alternate mode just hit A.

Sort related options

You can change which field gets used for the sort order by hitting F or O. The following options are available:

Choose one by hitting the appropriate letter, then hit return.

The sort order itself can be changed (that is largest to smallest -> smallest to largest) by hitting R.

Also, you can highlight the column of the field used for sorting by hitting x

Tweaking the task area

To toggle the showing of the command line options used to start the applications, hit c.

To toggle whether to show threads or not, hit H.

The use of cumulative time (total cpu time used by the process and its dead children) can be turned on by hitting S.

You can toggle colour on/off by hitting z

Changing colours

You can change the colours used by top by hitting Z. You'll be shown the options as per the image below:

Simply hit the letter for the target area you want to change the colour of, then hit the number of the colour.You can save your changes immediately (by hitting a or w), or afterwards by hitting before you exit top.

Quick reference

This is a quick reference as per man page.

Global Defaults

Letter Function

A

alternate mode

B

bold summary headings

G

choose 1-4 to get different displays

Z

change colours

W

write current settings to its config file.

Tweak summary area

Letter Function

l

toggle show load average/uptime

m

toggle show memory and swap space info

t

toggle task data / cpu states

1

toggle show all cpu's

Tweak task area

Letter Function

c

show command line for program

H

toggle show threads

R

reverse sort

S

cumulative time

x

highlight the sort field column

y

row highlight the running task

z

toggle colour/mono

F

change sort field

O

change sort field

See the man page for a full list of options and configurables.

A big thank you to James C. Warner, Albert D. Cahalan, and Craig Small for this helpful tool .

Thank you for reading this article.
Please share if you liked it.