Back to Blog
Lesson 21 of the Linux: Linux Command Line for Developers course
LinuxAugust 8, 20264 min read

Real-time Monitoring with Top: A Developer's Guide to Performance

Master real-time system monitoring with top and htop. Learn to interpret CPU and memory usage, identify resource bottlenecks, and manage process performance.

linuxsystem monitoringperformancetophtopterminal
Laptop screen displaying code and performance graphs with eyeglasses resting on the keyboard.

Previously in this course, we covered the introduction to processes, where you learned how to list PIDs and understand the hierarchy of running applications. In this lesson, we move from static process lists to dynamic, real-time observability.

When your web server becomes sluggish or a service starts consuming excessive memory, you need a live view of the system. We use top and htop for this exact purpose—they are the standard tools for monitoring system performance and identifying immediate resource bottlenecks.

Launching and Interpreting top

The top command comes pre-installed on virtually every Linux distribution. It provides a real-time summary of the system and a list of processes currently managed by the kernel.

To start it, simply run:

Bash
top

The screen is divided into two parts:

  1. The Summary Area (Header): Shows system uptime, load averages (1, 5, and 15 minutes), total task count, CPU percentages, and memory (RAM/Swap) usage.
  2. The Task List: A table showing individual processes, their user, priority, and resource consumption.

Reading the Metrics

  • Load Average: These three numbers represent the average number of processes waiting for CPU time. If your system has 4 CPU cores, a load average above 4.00 means your system is effectively overloaded.
  • %CPU: The percentage of total CPU time used by a process.
  • %MEM: The percentage of physical RAM used by a process.
  • RES: The "Resident" memory—the actual physical RAM the process is using right now.

Introducing htop for Better Visibility

A reflective traffic warning light glowing in the nighttime with bokeh effect.

While top is ubiquitous, htop is a modern, interactive improvement that makes system monitoring far more intuitive. It features color-coded bars for CPU/Memory and allows you to use your mouse or arrow keys to navigate.

If it's not installed, you can typically grab it via sudo apt install htop (on Debian/Ubuntu systems). Launch it with:

Bash
htop

Key Differences

Featuretophtop
InteractionBasic (Keyboard only)Advanced (Mouse + Keyboard)
VisualizationText-basedBar graphs for CPU/RAM
Process TreeLimitedBuilt-in tree view (F5)
SortingSpecific keysInteractive clicking

Sorting and Filtering Processes

To effectively troubleshoot, you need to see who is hogging the resources. You don't need to guess; you can sort the list dynamically.

Inside top:

  • Sort by CPU: Press P (capitalized, so Shift+p). The most resource-intensive processes will jump to the top.
  • Sort by Memory: Press M.
  • Change refresh rate: Press s and enter a new number of seconds.

Inside htop:

  • Sort: Click on the column headers (e.g., PERCENT_CPU) with your mouse, or press F6 to select a sorting column from a menu.
  • Search: Press F3 to filter the process list by name (e.g., typing "nginx" to see only your web server processes).
  • Kill: Press F9 to send a signal to a highlighted process (we will cover this in detail in the next lesson).

Hands-on Exercise: Identifying Load

  1. Open two terminal windows.
  2. In the first, run htop.
  3. In the second, run a command that consumes some CPU, such as find / -name "*.log" to trigger disk and CPU activity.
  4. Observe the change in the CPU bars in htop.
  5. Press F3 in htop and type the name of the command you just ran to isolate its impact.
  6. Once finished, press q to exit htop.

Common Pitfalls

Close-up of a triangular warning sign indicating a slippery surface, fixed to a wooden post.

  • Misinterpreting "Load": A high load average isn't always bad. If your system is performing a heavy background task intentionally, high load is expected. Only investigate if the load is high and the system becomes unresponsive.
  • Ignoring Swap: If you see Swap usage climbing in the header, your system is running out of physical RAM and is writing data to the hard drive, which is significantly slower. This is usually a sign that your server needs more memory or a process has a memory leak.
  • Not Using sudo: You can see all processes with top or htop as a standard user, but you won't have permission to perform actions like changing priorities or killing processes owned by other users or the system.

If you find yourself frequently checking these tools, you are likely hitting the limits of your hardware. Understanding these metrics is a prerequisite for effective Linux performance monitoring: a practical guide to htop & iostat, which helps you bridge the gap between process monitoring and disk I/O analysis.

Up next: We will discuss how to actually stop those resource-heavy processes using the kill command.

Similar Posts