Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

How to Use Top Command in Linux

Uploaded by

Jiten
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

How to Use Top Command in Linux

Uploaded by

Jiten
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Top Command Options

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.

Note: Hotkeys and options are case-sensitive.

The table below lists the most commonly used top command options and
hotkeys and their descriptions:

Hotk
Option Name Description
ey

-h Help N/A Shows the command help file.

-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.

When used without an argument, -w instructs top to format the out


using the COLUMNS= and LINES= environment variables, if applicab
Output width Otherwise, the width is fixed at 512 columns maximum. Appending a
-w [number] N/A
override argument to -w increases (up to 512) or decreases the output width
the row number is unlimited. The program never exceeds the actual
terminal dimensions at which top was invoked.

Reverses the last remembered CPU state portion. Depending on


Single/separate
-1 1 the NUMA Node command toggle (2) state, it either displays all CPU
CPU states toggle
information in a single line or separately.

N/A Sort by CPU usage P Sorts the tasks by CPU usage.

Sort by memory
N/A M Sorts the tasks by memory (%MEM) usage.
usage

N/A Sort by process ID N Sorts tasks by process ID.

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

How to Interpret top Command Output


The top command output is divided into several sections, each with
specific information about system performance and processes. This
section provides a breakdown of the output based on the information it
shows.
Header Information
This section shows basic system stats like uptime, active users, and
recent system load:

 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:

 total. Indicates the number of processes currently running on the system.


 running. Number of processes actively using CPU resources.
 sleeping. Processes waiting for an event to continue (e.g., input/output).
 stopped. Processes that are paused or waiting for signals.
 zombie. Processes that have finished execution but remain in the process
table.

CPU Usage
This section shows how various processes are using the CPU.

 us. Time the CPU spends on user (non-kernel) processes.


 sy. Time spent on system/kernel processes.
 ni. Time spent on user processes with adjusted priority (nice values).
 id. Percentage of time the CPU is idle.
 wa. Time spent waiting for I/O operations (like disk access).
 hi. Time handling hardware interrupts.
 si. Time handling software interrupts.
 st. Time "stolen" from the virtual machine by the hypervisor (when
using virtualization).

Memory Usage (Mem)


Memory usage stats explain how the system uses physical RAM.

 total. Total physical memory available.


 free. Unused RAM memory.
 used. Total memory in use by the system.
 buff/cache. Memory reserved for buffers and caches. This memory can be
reclaimed if needed by other processes.

Swap Usage (Swap)


The Swap section shows the disk-based memory usage, which the system
uses when RAM is full.

 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.

 PID. The process ID.


 USER. The user account that started the process.
 PR. Process priority.
 NI. Nice value, affecting scheduling priority.
 VIRT. Total virtual memory the process uses.
 RES. Resident memory (actual physical memory in use).
 SHR. Shared memory used by the process.
 S. Process state (e.g., S for sleeping, R for running).
 %CPU. Percentage of CPU time used by the process.
 %MEM. Percentage of RAM used by the process.
 TIME+. Total CPU time the process has consumed.
 COMMAND. The program, service, or command responsible for each active
process.

top Command Examples


Below are the most common top command use cases. The options are
case-sensitive, which means that pressing N and n invokes a different
action.
Note: Use the top command options by pressing the corresponding key
while top is running, or enter the option flag directly in the top command
syntax and run it from the command line.
List All Processes
To list all running Linux processes on your system, open the terminal
and enter:

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:

You might also like