Introduction to the `top` Command in Linux
In Linux, the top
command is an interactive utility that provides a real-time,
dynamic view of the processes running on a system. It displays information about
CPU, memory, and other resources, allowing users to monitor system performance
and manage processes effectively. With top
, users can identify
resource-intensive tasks and make informed decisions on system resource
management.
Utilizing the top
Command
To use the top
command, simply type top
in your terminal and press Enter.
You will be presented with a real-time updating list of the active processes and
their resource usage.
$ top
Understanding the top
Output
The top
command display is divided into two sections. The top section provides
a summary of the system's current state, including uptime, load average, and the
number of tasks. The bottom section lists individual processes and their
details.
Information Fields and Their Descriptions
Here is a table detailing the common information fields displayed by top
and
what each field represents:
Field | Description |
---|---|
PID | Process ID, a unique number assigned to identify each process. |
USER | The owner or the user who started the process. |
PR | Priority of the process. |
NI | Nice value, a user-space way to set priority of a process. |
VIRT | Virtual Memory Size of the process (includes all memory). |
RES | Resident Memory Size, the actual amount of physical memory used. |
SHR | Shared Memory Size, the amount of shared memory used by a task. |
S | Process Status: R (running), S (sleeping), Z (zombie), etc. |
%CPU | The percentage of CPU used by the process. |
%MEM | The percentage of RAM (physical memory) used by the process. |
TIME+ | Total CPU time used by the process since it started. |
COMMAND | The command that started the process, including command-line options. |
Practical Usage of top
While top
is running, you can interact with it using various commands:
- Pressing
k
allows you to kill a process by entering its PID. - Pressing
u
followed by a username shows only processes owned by that user. - Pressing
r
allows you to change the priority (nice value) of a process. - Pressing
q
quitstop
.
Command Keys For the top
Command
While top
is running, users can interact with it using a variety of shortcut
keys to access different features or manipulate the display. Here’s a list of
available shortcuts and their functions in the top
command:
Shortcut Key | Description |
---|---|
h or ? | Displays help screen showing almost all the commands available. |
q | Quits top . |
k | Kills a process. User is prompted to enter the PID of the process to be killed. |
r | Renices a process. User is prompted to enter the PID of the process to be reniced. |
u | Displays only the processes owned by a specified user. |
n or # | Allows the user to configure the number of processes to be displayed. |
M | Sorts the processes by memory usage. |
P | Sorts the processes by CPU usage. |
T | Sorts the processes by time/cumulative time. |
c | Toggles command line/command name display. |
m | Toggles between different memory information displays. |
t | Toggles between different CPU information displays. |
f or F | Enters the field select mode, allowing you to add, remove, or re-order columns/fields. |
e | Changes the memory scaling factor, cycling between kibibytes (KiB), mebibytes (MiB), gibibytes (GiB), and tebibytes (TiB). |
l | Toggles the display of load average and uptime information. |
s | Changes the delay between updates (screen refresh rate). |
z | Toggles color/mono. |
x | Highlights the sorted column. |
y | Toggles the display of the running tasks in the summary area. |
b | Toggles bold enable/disable. |
W | Writes the current setup to the ~/.toprc file, making it the default for future sessions. |
< or , | Moves the sorting column one to the left. |
> or . | Moves the sorting column one to the right. |
d or D | Shows or sets the delay (in seconds) between updates. |
V | Trees view of processes, showcasing the parent-child relationships. |
H | Toggles the display of threads. |
L | Allows user to locate a string within top . |
Each of these shortcuts can help users to swiftly and efficiently navigate
through the top
command, manipulate its displays, or perform specific actions
on processes, enabling more effective system monitoring and management.
Conclusion
The top
command in Linux is a powerful and interactive tool to monitor
processes and system resources. It provides a real-time view of the system’s
performance, allowing users to identify resource-consuming processes and manage
system load efficiently. Understanding the information provided by top
and
knowing how to interpret it is crucial for maintaining a healthy and responsive
Linux system. By mastering top
and its various features, users and
administrators can optimize resource allocation, troubleshoot issues, and ensure
smooth system operation.
What Can You Do Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.