How to Use Top Command in Linux
How to Use Top Command in Linux
The options modify the command's behavior and output. They affect what
processes are shown, how often the information is updated, and which
resources are highlighted. Either specify the options when running top in
the terminal or use the designated hotkey (if available) once you are in
the top interactive mode.
The table below lists the most commonly used top command options and
hotkeys and their descriptions:
Hotk
Option Name Description
ey
-v Version N/A Shows the program version and usage prompt and then quits the pro
Starts top in batch mode, allowing users to send the command's out
-b Batch mode N/A a file or other programs. By default, it does not accept input in batch
and runs until it is killed or reaches the specified iteration limit.
Toggle command
Reverses the last remembered c state. If top displayed command lin
-c line/program c
that field now shows program names and vice versa.
name
-d Prompts you to specify the delay before updating the screen, overrid
[secs.tenth Delay time interval N/A the default value. The value is in seconds. The command accepts frac
s] seconds but does not accept negative numbers.
Allows you to change top task area memory scaling. The available sc
-e [k | m | Toggle task
g | t | p] e options
memory scaling
are k (kibibytes), m (mebibytes), g (gibibytes), t (tebibytes), p (pebib
-E [k | m | Toggle summary E Allows you to change top summary area memory scaling. The availa
g | t | p | memory scaling scaling options
e]
are k (kibibytes), m (mebibytes), g (gibibytes), t (tebibytes), p (pebib
Hotk
Option Name Description
ey
(exbibytes).
Threads mode
-H H Displays individual threads instead of a sum of all threads in each pro
operation
Reverses the last remembered i state. When the toggle is OFF, top
-i Idle process toggle i
not display the tasks that haven't used CPU resources since the last u
Limit iteration Specify the maximum number of iterations you want top to produce
-n N/A
number before ending.
Specify the field name top uses to sort tasks. Prepending a + to the
-o [field Overwrite sort name forces top to sort high to low while prepending it with - orde
name] o
field low to high. The -o option primarily supports automated batch mod
operation.
Output field The -O option complements the -o option and instructs top to print
-O N/A
names of the available field names separately and then quit.
Instructs top to monitor only the processes with the specified proce
IDs (PIDs). When combined with the threads mode (-H), top shows
-p [N1, Monitor process 20 processes in each monitored PID thread group. Specifying the PID
N2...] N/A
IDs mode value 0 is considered as the top program process ID. To return to no
operation, issue any of the following commands: =, u, or U, as they a
mutually exclusive.
Secure mode
-s N/A Starts top in secure mode, even for root.
operation
Cumulative time Reverses the last remembered S state. When the cumulative time to
-S S
toggle ON, each process is listed with the CPU time it has used.
-u | -U [ID User filter mode u Displays only the processes matching the specified user ID or user na
or name] The -u option matches only the effective user, while the -U option
matches any user - real, effective, saved, or filesystem. Prepending t
Hotk
Option Name Description
ey
user ID or user name with an exclamation point (!) causes top to dis
only the processes that do not match the one provided.
Sort by memory
N/A M Sorts the tasks by memory (%MEM) usage.
usage
Sort by running
N/A T Sorts the tasks by running time.
time
Toggle
N/A ascending/descen R Reverses the sort order from descending to ascending.
ding order
up. Displays the system running time since the last reboot.
user(s). Shows the current number of active users.
load average. Lists the average system load over the last 1, 5, and 15
minutes. Lower values indicate less CPU demand.
Tasks
The Tasks section provides a quick overview of all running processes and
their states:
CPU Usage
This section shows how various processes are using the CPU.
total. Total swap memory (disk-based memory used when RAM is full).
free. Unused swap memory.
used. Swap currently in use.
avail Mem. Total memory available (sum of free and buffered memory).
Process List
The Process List displays detailed information about each active process.
top
The output displays the summary area (the dashboard with resource
usage stats) and the task area (a list of all processes). top updates the
information every three seconds by default.
If the process list is long, scroll through it using the Up and Down arrows
and Page Up and Page Down keys. Press q to quit top.
Send a Signal
Use the top command to send any signal to a running process. Press
the k key and enter the process PID. top prompts you to type the signal
you want to send. Not entering a specific signal kills the process.
For example: