Mastering System Performance: How to Use the ‘top’ Command to Monitor Your Linux Environment

The top command in Linux has been a vital tool since its inception in 1984, providing system administrators with a clear picture of system utilization and identifying the most resource-heavy processes. Over the years, alternative tools like atop and htop have emerged, offering varied perspectives on system metrics that administrators should monitor. Nevertheless, the original top command continues to be a popular choice due to its straightforward presentation of system performance data.

When executed in its simplest form by typing “top”, this command displays the most relevant performance metrics typically required on a Unix-based system. It provides a summary in the first five lines, detailing system uptime, the current load average (which indicates system activity level), the total number of active processes, and information on memory and swap usage. Consider this sample output:

Key figures to monitor in the top command output include the load averages located at the top right of the display. These figures represent the system’s average activity over the past one minute, five minutes, and 15 minutes. These metrics can help gauge the extent of the system load. It is important to remember, however, that they only reflect system activity within the last 15 minutes.

The output also details the total number of tasks, including how many are actively running (using the CPU) and how many are inactive or in sleeping mode, as well as terminated processes that are still listed in the process table, known as “zombies.” Furthermore, it breaks down CPU usage into specific categories, using standard abbreviations:

us: % CPU time allocated in user mode
sy: % CPU time allocated in kernel mode
ni: % CPU time allocated to low priority processes marked as “nice”
id: % CPU remaining idle
wa: % CPU time waiting (typically disk IO)
hi: % CPU time handling hardware interrupts
si: % CPU time handling software interrupts
st: % CPU time wasted due to virtualization overhead

The continuation of the top command detailing shows a comprehensive breakdown of system processes. Displayed in order of their resource consumption, here is the layout of the top list:

The information in the fields is noted below:

PID: Indicates the process ID
USER: Identifies the user running the process
PR: Indicates process priority
NI: Represents the nice value of the process
VIRT: Amount of virtual memory used
RES: Indicates resident memory usage
SHR: Amount of shared memory utilized
S: Denotes process state (additional details available for different states)
%CPU: Portion of CPU time consumed by the process since last update
%MEM: Fragment of physical memory in use
TIME+: Total CPU time consumed by the process, in hundredths of a second
COMMAND: Displays the process command name or command line used

The values in the “S” (process status) field represent these states:

‘D’ = uninterruptible sleep
‘R’ = running
‘S’ = sleeping
‘T’ = traced or stopped
‘Z’ = zombie

You can ask the system to tell you the version of the top command that you are using like this:

While viewing the top command’s output, you can alter the presentation of the data by using the keys described below:

Tap the Q key to exit.
Tap the M key to arrange the process table by memory consumption. Higher memory consuming processes will appear first.
Tap the P key to organize the process table by CPU usage.
Tap the N key to order by process ID.
Tap the T key to sort based on duration of operation.
Tap the R key to invert the order of the current sorting.

The top command is straightforward for regular use and comprehension. It is beneficial to become acquainted with its display prior to encountering issues, as this will aid in understanding what is considered “normal.”

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Article

Grok AI: Unpacking the Implications for Privacy and User Trust

Next Article

Marvel Vs. Capcom Fighting Collection Review: Unleashing a New Age of Heroes

Related Posts