How to Use the htop Command to Monitor Linux Server Performance

Why Use htop Instead of top?

Monitoring system resources is a fundamental task for any Linux administrator. Traditionally, this is done using the built-in top command, which displays real-time data about CPU, memory, and running processes. However, top is notoriously dense, lacks color-coding, and does not allow for intuitive process interaction without memorising obscure keystrokes.

htop is a modern, interactive process viewer for Linux that resolves all these issues. It provides a full-terminal, colorised visual representation of your server’s resources. More importantly, it allows you to scroll horizontally and vertically through the process list and manage processes (like sending kill signals) using simple function keys rather than typing out Process IDs (PIDs).

How to Install htop

While some newer distributions include htop by default, it usually needs to be installed manually.

For Debian and Ubuntu-based servers:

sudo apt update
sudo apt install htop

For CentOS, RHEL, and Fedora-based servers (you may need to enable the EPEL repository first on CentOS/RHEL):

sudo dnf install htop

Understanding the htop Interface

To launch the tool, simply type htop and press Enter. The interface is divided into three main sections:

1. The Resource Header

At the top of the screen, you will see visual progress bars.

  • CPU Usage: Each CPU core is represented by a numbered bar (1, 2, 3, 4, etc.). The color of the bar indicates the type of usage:
    • Green: Normal user processes.
    • Red: Kernel or system processes.
    • Blue: Low-priority (nice) processes.
  • Mem (Memory): Displays your total RAM usage. Green indicates used memory, blue is buffer memory, and yellow is cache.
  • Swp (Swap): Displays how much swap space (virtual memory on the hard drive) is currently being utilised. High swap usage generally indicates your server is running out of physical RAM.

2. The Process List

The middle section displays all running processes. The most critical columns include:

  • PID: The unique Process ID number.
  • USER: The account running the process.
  • RES: The Resident Set Size, representing the exact amount of physical RAM the process is consuming.
  • CPU%: The percentage of CPU currently being used by the process.
  • Command: The specific command or program path that initiated the process.

3. The Interactive Footer

The bottom row lists the function keys (F1-F10) you can use to interact with the interface. Unlike top, you do not need to memorize these commands, as they are always visible.

How to Manage Processes with htop

Sorting the Process List

By default, htop sorts processes by CPU usage. If you want to identify which application is causing a memory leak, you can sort by memory instead.

  1. Press F6 (or use your mouse to click “SortBy” in the footer).
  2. Use your arrow keys to select the %MEM column.
  3. Press Enter. The list will now display the most memory-hungry processes at the top.

Filtering and Searching

If you are running hundreds of processes and need to find a specific web server (like Nginx), you can filter the list.

  1. Press F4 (Filter).
  2. Type nginx. The list will instantly shrink to show only processes containing that keyword.
  3. Press Enter to lock the filter, or press Esc to clear it.

Terminating (Killing) a Process

If a process has frozen or is consuming 100% of a CPU core, you can terminate it directly from the htop interface without needing to use a separate kill command.

  1. Use the Up and Down arrow keys to highlight the offending process in the list.
  2. Press F9 (Kill).
  3. A menu will appear on the left side showing different termination signals. The default is SIGTERM (15), which politely asks the program to shut down and save its data. Press Enter to send this signal.
  4. If the program is completely unresponsive and ignores the SIGTERM, press F9 again, select SIGKILL (9), and press Enter. This forces the Linux kernel to destroy the process immediately.

How to Exit htop

To safely close the application and return to your standard terminal prompt, simply press the F10 key, or press the Q key on your keyboard.

Get the best tech tips delivered straight to your inbox.

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