Page Body

Real-Time System Process Management With top

You can view a constant real-time update of running processes on a GNU/Linux system with the top command.

Note: If you are not familiar with the GNU/Linux command line interface, review the Conventions page before proceeding.

top Output

top is an interactive program and its output is dense, so it is helpful to break down the information it displays, line-by-line.

Line One

Line One

The first line of top's output tells you:

  • How long the system has been up
  • How many users are logged in
  • What the load average is

Essentially, this information is equivalent to the output of the uptime command.

Line Two

Line Two

The second line of top's output tells you the:

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

Running processes are those that are either running on the CPU or waiting to run on the CPU (i.e., those in the run queue).

Sleeping processes are those that are waiting for something to happen before continuing to resume (i.e., those in a wait queue). At any given time, most processes are in a sleep state.

Stopped processes are those that have been sent a SIGTSTP/SIGSTOP signal.

Zombie processes are child processes that have completed, but whose parent process has not inquired about their state (i.e., successfully picked up the child process's exit status). These processes have no impact on the system, except for a gratuitous entry in the system process table.

Line Three

Line Three

The third line of top's output tells you the:

  • Percentage of CPU time used running user processes (us) and system processes (sy)
  • Percentage of CPU time used running niced user processes (ni), i.e., low priority processes
  • Percentage of CPU time spent in the kernel idle handler (id)
  • Percentage of CPU spent waiting (wa) for I/O completion
  • Percentage of CPU spent servicing hardware (hi) versus software interrupts (si)
  • Percentage of time that a virtual CPU waits for a real CPU while the hypervisor is servicing another virtual processor (steal time, st)

Line Four

Line Four

The fourth line of top's output tells you the:

  • Total physical memory, free physical memory, used physical memory, and buff/cache (i.e., the sum of the memory used by the kernel buffers and the page cache/slabs)

Line Five

Line Five

The fifth line of top's output tells you the:

  • Total swap memory, free swap memory, used swap memory, and available memory (i.e., an estimation of how much memory is available for starting new applications, without swapping)

The information in lines four and five is comparable to the output of the free command.

Columns

Columns

The rest of top's output displays columnar data regarding the running processes on your system. The columns are:

PID
The Process ID.
USER
The User Owner of the process.
PR
The Priority Value of the process. This is the real priority value for a process at the moment inside of the kernel.
NI
The Nice Value of the process. This value represents a suggestion for the kernel about the priority a process should have.
VIRT
The total amount of virtual memory used by the process. Expressed in KiB (kibibytes).
RES
The subset of virtual address space (i.e., VIRT) representing the physical memory a process is currently using. Expressed in KiB (kibibytes).
SHR
The subset of resident memory (i.e., RES) that may be used by other processes. Expressed in KiB (kibibytes).
S
The process status.
%CPU
A process's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.
%MEM
A process's current resident share of available physical memory.
TIME+
The total CPU time the process has used since it started through hundredths of a second.
COMMAND
The command name or command line associated with the process.

Keyboard Shortcuts

There are a variety of keyboard shortcuts you can use to either change the output of top or to interact with running processes.

=
Clear filters.
c
Show command full paths.
f
Fields Management. Press Escape to exit.
H
Switch to thread view (press again to switch back to process view).
i
Show idle/zombie processes.
k
Kill process. You will need to enter a PID and can enter an optional signal (SIGINT is used by default).
m
Toggle between memory views.
M
Sort by memory usage.
n
Prompt for the number of processes to display.
N
Sort by PID.
o
Filter processes (e.g., COMMAND=getty, !COMMAND=getty, %CPU>3.0).
P
Sort by CPU usage.
r
Prompt for PID to affect and provide new nice number value.
q
Quit top.
R
Sort by ascending order.
t
Toggle between CPU views.
T
Sort by execution time.
u
Switch to processes for specific user (leave user blank to switch back to all users).
V
Switch to forest view.
W
Save changes to top's output.

Documentation

For more on top, you can run the man 1 top command to view its manual page. Alternatively, you can view its manual page online.

Avatar

Enjoyed this post?

Subscribe to the feed for the latest updates.