How to Use the ‘htop’ Command for Interactive System Monitoring and Process Management

The Problem with Standard ‘top’

When a Linux server suddenly becomes unresponsive, the first instinct of any system administrator is to type top into the terminal. The classic top command provides a real-time view of system resources and running processes. However, top is notoriously difficult to read, lacks color-coding, and requires you to memorize arcane keyboard shortcuts just to kill a frozen application.

The modern, universally preferred alternative is htop. It provides a beautiful, interactive, color-coded dashboard that makes identifying CPU spikes, memory leaks, and zombie processes incredibly intuitive.

Installing htop

Unlike top, htop is not usually installed by default, but it is available in almost every package repository.

  • Ubuntu/Debian: sudo apt install htop
  • CentOS/RHEL: sudo yum install htop
  • macOS: brew install htop

Once installed, simply type htop to launch the dashboard.

Reading the Dashboard

The interface is divided into two main sections.

The Top Header (Hardware Meters)

At the very top left, you will see a visual representation of your CPU cores (labeled 1, 2, 3, etc.). The color-coding is crucial:

  • Green: Normal user processes.
  • Red: Kernel (system) processes.
  • Blue: Low-priority (nice) processes.

Below the CPU meters are the Memory (Mem) and Swap bars.

  • Green: Used memory.
  • Blue: Buffers.
  • Yellow: Cached memory.

The Process List (The Bottom Section)

This lists every process running on the server. The most important columns are:

  • PID: The unique Process ID number.
  • USER: The user account running the process.
  • RES: Resident memory (the actual physical RAM the process is using).
  • CPU%: The percentage of CPU time currently being consumed.
  • Command: The actual command or script that launched the process.

Interactive Navigation and Management

The greatest advantage of htop is its interactivity. You can use your arrow keys (or even your mouse) to navigate the interface.

1. Sorting Processes

If you want to know what is eating all your RAM, press F6 (SortBy). A menu will slide out on the left. Use the arrow keys to select PERCENT_MEM and hit Enter. The list will instantly re-sort to show the biggest memory hogs at the very top.

2. Searching for a Process

If you have hundreds of processes running and you only want to see the nginx web server threads, press F3 (Search), type nginx, and hit Enter. htop will immediately highlight the relevant processes.

3. Killing a Frozen Process

In standard top, killing a process requires you to note the PID, exit the program, and run the kill command manually. In htop, it is seamless.

  1. Use the up/down arrow keys to highlight the offending process.
  2. Press F9 (Kill).
  3. A menu will appear on the left asking what kind of kill signal to send. SIGTERM (15) asks the program to close politely. If it is completely frozen, select SIGKILL (9) to force the kernel to terminate it instantly.
  4. Press Enter.

Conclusion

By replacing the archaic text walls of the classic top command with interactive, color-coded meters and intuitive keystrokes, htop reduces the time it takes to diagnose and resolve server performance issues from minutes to mere seconds.

Get the best tech tips delivered straight to your inbox.

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