Understanding TOP Command in Linux

  • Post category:Linux / Redhat / Ubuntu
  • Post last modified:June 13, 2023

Introduction

The TOP command is a powerful utility in the Linux operating system that provides real-time information about system performance and resource usage. Whether you are a system administrator or a Linux enthusiast, having a solid understanding of the TOP command can help you monitor processes, identify performance bottlenecks, and optimize system efficiency. In this article, we will delve into the details of the TOP command and explore its various features and options.

What is the TOP Command?

The TOP command is a terminal-based tool that displays dynamic information about running processes on a Linux system. It offers a comprehensive overview of system statistics, including CPU usage, memory utilization, process IDs, and more. TOP is a go-to tool for monitoring system performance and identifying resource-intensive processes.

Launching the TOP Command

To launch the TOP command, open a terminal window and simply type “top” followed by pressing the Enter key. By default, the TOP command displays a real-time, continuously updating view of system activity.

The screen should look like this.

Understanding TOP Command in Linux

Understanding the TOP Command Interface

The TOP command interface provides a wealth of information about system performance. Here are some key elements of the interface:

  • Header Information: The top section displays system-level information such as uptime, load averages, and the number of running processes.
  • Process List: Below the header, you’ll find a list of running processes. Each process entry shows details like process ID (PID), CPU usage, memory consumption, and more.
  • Interactive Controls: TOP offers various interactive controls to sort and manipulate the displayed information. For example, pressing “P” sorts the processes by CPU usage, and “M” sorts them by memory usage.

Navigating the Process List

The process list in TOP provides vital insights into the system’s resource utilization. Here are a few important columns to pay attention to:

  • PID: Process ID, a unique identifier for each running process.
  • %CPU: The percentage of CPU time consumed by each process.
  • %MEM: The percentage of system memory consumed by each process.
  • COMMAND: The name of the command or application associated with each process.

Interactive Commands and Functionality

TOP offers a range of interactive commands and functionality to refine and customize the displayed information. Here are a few commonly used commands:

  • Sorting: Pressing specific keys like “P” (CPU usage) or “M” (memory usage) sorts the process list based on the chosen criteria.
  • Renicing: Pressing “r” allows you to modify the priority of a process (i.e., renice) by specifying its PID.
  • Filtering: Pressing “o” enables you to set filters to display specific processes based on user-defined criteria.
  • Process Termination: Pressing “k” allows you to send signals to selected processes, enabling you to terminate or control them.

Customizing the TOP Command Output

TOP provides customization options to tailor the displayed information according to your preferences. For instance, you can choose to hide or display specific columns, adjust the update frequency, and even save the TOP output to a file for later analysis.

Running TOP in Batch Mode

You can run the command:

top -b -d 10 -n 5 >/tmp/esxtstats.csv

–d Switch is used for the number of seconds between refreshes

–n switch is the number of iterations to run the esxtop

In our above example, esxtop command will run for about 50 seconds. 10 seconds delay* 5 iterations.

 

Conclusion

The TOP command is an invaluable tool for monitoring and managing system performance in Linux. By familiarizing yourself with its interface, navigating the process list, and utilizing its interactive commands and customization options, you can effectively monitor resource usage, identify bottlenecks, and optimize system efficiency. Whether you are a system administrator or a Linux enthusiast, mastering the TOP command will empower you to gain deeper insights into your Linux system’s performance.

Ashutosh Dixit

I am currently working as a Senior Technical Support Engineer with VMware Premier Services for Telco. Before this, I worked as a Technical Lead with Microsoft Enterprise Platform Support for Production and Premier Support. I am an expert in High-Availability, Deployments, and VMware Core technology along with Tanzu and Horizon.

Leave a Reply