How to Use the Linux 'top' Command to Show Running Processes

A real-time system resource monitor helps alert you to system bottlenecks

The Linux top command shows the running processes within your Linux environment that consume the most system resources.

How to Run the 'top' Command

top command

In its basic form all you need to do to show the current processes is type the following in a Linux terminal:

top

Command Output

The top command runs in the foreground and continuously updates itself. Its results show on five lines, plus the main table.

Line 1

The first line offers some basic high-level info about the system:

  • The time
  • How long the computer has been running
  • Number of users
  • Load average

The load average shows the system load time for the last 1, 5 and 15 minutes.

Line 2

The second line summarizes the number of ongoing, concurrent tasks:

  • Total number of tasks
  • Number of running tasks
  • Number of sleeping tasks
  • Number of stopped tasks
  • Number of zombie tasks

Line 3

The third line summarizes CPU performance:

  • CPU usage as a percentage by the user
  • CPU usage as a percentage by system
  • CPU usage as a percentage by low priority processes
  • CPU usage as a percentage by idle processes
  • CPU usage as a percentage by io wait
  • CPU usage as a percentage by hardware interrupts
  • CPU usage as a percentage by software interrupts
  • CPU usage as a percentage by steal time

Line 4

The fourth line emphasizes memory:

Line 5

The fifth line highlights available swap space and total memory inclusive of swap:

  • Total swap available
  • Total swap free
  • Total swap used
  • Available memory

Main Table

The main table lists running processes:

  • Process ID
  • User
  • Priority
  • Nice level
  • Virtual memory used by process
  • Resident memory used by a process
  • Shareable memory
  • CPU used by process as a percentage
  • Memory used by process as a percentage
  • Time process has been running
  • Command

Check out your distribution's package manager for alternative versions of this utility that offer more or different functionality.

Key Switches for the 'top' Command

Although you invoke top just by typing the name in a shell session, a few switches modify the utility's behavior:

  • -h: Show the current version
  • -c: This toggles the command column between showing command and program name
  • -d: Specify the delay time between refreshing the screen
  • -o: Sorts by the named field
  • -p: Only show processes with specified process IDs
  • -u: Show only processes by the specified user
  • -i: Do not show idle tasks

Adding Extra Columns to the Display

Press F to show the list of fields displayable in the table. Use the arrow keys to move up and down the list of fields.

To display or hide a field on the screen, press D to toggle it. An asterisk appear next to manually displayed fields.

Set the field to sort the table by simply by pressing the "S" key on the field you wish to sort by.

Press the enter key to commit your changes and press "Q" to quit.

Toggling Modes

Whilst running top press A to toggle between the standard display and an alternate display.

Changing Colors

Press Z to change the colors of the values within top.

Three stages change the colors:

  1. Press either S for summary data, M for messages, H for column headings or T for task information to target that area for a color change
  2. Choose a color for that target, 0 for black, 1 for red, 2 for green, 3 for yellow, 4 for blue, 5 for magenta, 6 for cyan and 7 for white
  3. Enter to commit.

Press B to make text bold.

Change the Display While Running 'top'

While the command runs in the foreground, toggle many features on and off by pressing relevant keys.

The following table shows the key to press and the function it provides:

Function Key Description
A Alternative display (default off)
d Refresh screen after specified delay in seconds (default 1.5 seconds)
H Threads mode (default off), summarises tasks
p PID Monitoring (default off), show all processes
B Bold enable (default on), values are shown in bold text
l Display load average (default on)
t Determines how tasks are displayed (default 1+1)
m Determines how memory usage is displayed (default 2 lines)
1 Single cpu (default off) - i.e. shows for multiple CPUs
J Align numbers to the right (default on)
j Align text to the right (default off)
R Reverse sort (default on) - Highest processes to lowest processes
S Cumulative time (default off)
u User filter (default off) show euid only
U User filter (default off) show any uid
V Forest view (default on) show as branches
x Column highlight (default off)
z Color or mono (default on) show colors
Function Keys

Alternative: 'htop' Utility

htop command

It's not installed on most distributions by default, but the htop utility functions similarly to top but it streamlines the display and ties behavior to real-time function key presses rather than a complex menu of letter-and-switch behavior. Significantly, htop shows all running processes whereas top focuses on the top processes that consume the most system resources.