How to Use the top Command to Monitor System Performance in Ubuntu

If an Ubuntu server or desktop machine suddenly becomes slow or unresponsive, your first step as an administrator is to determine which application is consuming all the resources. While graphical tools like the System Monitor exist for the desktop, server environments require command-line solutions.

The top command is the oldest, most reliable, and most universally available performance monitoring tool in the Linux ecosystem. It provides a real-time, dynamic view of your system’s hardware usage and a list of every active process currently running.

Understanding the top Interface

To launch the monitor, open your terminal and type top, then press Enter. The screen will immediately fill with data, refreshing every 3 seconds.

The interface is divided into two distinct sections:

1. The Summary Area (Top Half)

The first five lines provide a bird’s-eye view of your server’s health:

  • Uptime and Users (Line 1): Shows how long the server has been running without a reboot, how many users are logged in, and the “Load Average” (a measurement of CPU demand over the last 1, 5, and 15 minutes).
  • Tasks (Line 2): Displays the total number of running processes, and how many are currently sleeping, stopped, or “zombified” (dead but not properly cleared from memory).
  • CPU Usage (Line 3): The most critical line for troubleshooting. It breaks down processor usage. Pay attention to us (time spent running user processes), sy (time spent running system kernel processes), and id (idle time). If id is consistently near 0.0, your CPU is completely overwhelmed.
  • Memory and Swap (Lines 4 & 5): Displays your total RAM, how much is free, and how much is being used. It also shows Swap usage (virtual memory on your hard drive). If your server is aggressively using Swap space, it means you have run out of physical RAM.

2. The Process List (Bottom Half)

Below the summary is a list of individual processes, sorted by default based on which application is currently using the most CPU power.

  • PID: The unique Process ID number. You need this number if you want to force-quit an application.
  • USER: The name of the user who launched the application (e.g., root or www-data).
  • %CPU: The percentage of CPU time the process is currently consuming.
  • %MEM: The percentage of physical RAM the process is consuming.
  • COMMAND: The name of the program or script running (e.g., mysql, apache2, or python3).

How to Interact with top

While top is running, you can press specific keys on your keyboard to change how the data is displayed or take action against rogue processes. (Remember that top is case-sensitive, so do not hold Shift unless specified).

Sorting the Process List

By default, the list constantly jumps around as CPU usage changes. You can sort by other metrics to find memory leaks or long-running tasks.

  • Press M (Shift + m) to sort the list by Memory usage. This immediately reveals which application is hogging your RAM.
  • Press P (Shift + p) to return the list to sorting by CPU usage.
  • Press T (Shift + t) to sort by Time running, showing you which processes have been active the longest.

Managing Rogue Processes

If you identify a process that has crashed and is consuming 100% of your CPU, you can kill it directly from within the top interface.

  1. Look at the PID column for the offending process and write down the number (e.g., 4592).
  2. Press the k key (lowercase).
  3. A prompt will appear near the top of the screen asking “PID to signal/kill”. Type the PID number (e.g., 4592) and press Enter.
  4. It will ask you which signal to send, defaulting to 15 (SIGTERM, a polite request to close). Press Enter to confirm.

If the program refuses to close, you can press k again, enter the PID, and type 9 (SIGKILL) to force the operating system to immediately terminate the process without warning.

Exiting the Program

To safely exit top and return to your standard command-line prompt, simply press the q key.

Leave a Reply

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

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.