How to Read and Use `top`

3 min read .

Managing system performance is one of the main tasks for a Linux administrator. The most commonly used tool for monitoring the system is top. It is a command-line utility that displays running processes and provides real-time information about resource usage. How to read and use top to effectively monitor your Linux system’s performance.

What is the top Command?

top is a terminal-based utility that displays a list of processes running on a Linux system in real-time. With top, you can see which processes are running, how much CPU and memory they are using, and other information that helps you understand system load.

Using the top Command

To run top, simply type top in the terminal and press Enter:

top

Once the command is executed, you will see a continuously updating display. This is the default view of top and includes various important information about your system.

Understanding the top Display

The top display is divided into two main sections: system information at the top and the process list at the bottom.

1. Top Section: System Information

At the top of the screen, you will find crucial information about your system’s performance:

  • Uptime: Time since the system was last restarted.
  • User Sessions: Number of users currently logged in.
  • Load Average: Three numbers showing the system load average over the last 1, 5, and 15 minutes.
  • Tasks: Displays the total number of processes, including active, sleeping, stopped, and zombie processes.
  • CPU Usage: Shows CPU usage broken down into categories such as user, system, idle, and others.
  • Memory: Displays total RAM usage, used, free, and buffered memory.
  • Swap: Shows total swap usage, used, and free swap space.

2. Bottom Section: Process List

This section displays a list of processes running on the system, with important information arranged in columns:

  • PID: Process ID, a unique number identifying each process.
  • USER: The user running the process.
  • PR: Process priority.
  • NI: Nice value, which affects the process priority.
  • VIRT: Amount of virtual memory used by the process.
  • RES: Amount of physical memory used by the process.
  • SHR: Amount of shared memory used by the process.
  • S: Process status (R for running, S for sleeping, Z for zombie).
  • %CPU: Percentage of CPU used by the process.
  • %MEM: Percentage of memory used by the process.
  • TIME+: Total CPU time used by the process since it started.
  • COMMAND: The command or name of the program running the process.

top is an interactive tool, so you can perform various actions directly from the main display. Here are some useful keyboard commands while using top:

  • q: Quit top.
  • h: Display help to see a list of available commands.
  • k: Kill a process by PID. After pressing k, you will be prompted to enter the PID of the process you want to terminate.
  • r: Change the nice value (priority) of a specific process. After pressing r, enter the PID of the process, then specify the new nice value.
  • M: Sort processes by memory usage.
  • P: Sort processes by CPU usage.
  • T: Sort processes by CPU time used since the process started.
  • Space: Refresh the display immediately (by default, top refreshes every few seconds).

Customizing the top Display

You can customize the top display to suit your needs:

  • Change Update Interval: By default, top updates the display every 3 seconds. You can change this by pressing d and entering a new interval in seconds.
  • Display Additional Columns: Press f to open the column configuration menu, where you can add or remove columns from the main display.
  • Filter Processes: Press o to enter filter criteria to display only processes that match the filter.

Saving top Settings

If you have customized the top display and want to save the settings for future sessions, press W. This will save the configuration to a .toprc file in your home directory.

Conclusion

top is a highly useful tool for monitoring the performance of your Linux system. With the real-time information provided in detail, you can easily identify processes that are taxing the system and take necessary actions. Understanding how to read and use top is an essential skill for anyone working with Linux, especially for managing complex systems or troubleshooting performance issues.

Tags:
Linux

See Also

chevron-up