How to Monitor System Processes Using htop Command

Introduction

htop is an interactive process viewer for Unix systems. It provides a real-time, dynamic overview of system processes, displaying CPU, memory, and swap usage, along with other system metrics. Unlike the traditional top command, htop offers a more user-friendly, colorful interface and a variety of features for sorting and managing processes.

Installation

Before using htop, you need to install it. Depending on your Linux distribution, the installation command may vary:

  • Ubuntu/Debian: sudo apt-get install htop

Understanding the Interface

When you launch htop, you'll see a colorful interface with several columns of information. Here's a breakdown of what you see:

  1. Header Section:

  • CPU Usage: Shows the usage of each CPU core with different colors indicating various types of load (user, system, nice, etc.).

  • Memory and Swap Usage: Displays the amount of RAM and swap space used.

  • Load Average: Provides the load average for the last 1, 5, and 15 minutes.

  • Uptime: Indicates how long the system has been running.

  1. Main Process List:

  • PID: Process ID.

  • USER: User running the process.

  • PRI: Priority of the process.

  • NI: Nice value of the process.

  • VIRT: Virtual memory used by the process.

  • RES: Resident memory (RAM) used by the process.

  • SHR: Shared memory used by the process.

  • S: State of the process (e.g., running, sleeping).

  • %CPU: Percentage of CPU usage.

  • %MEM: Percentage of memory usage.

  • TIME+: Total CPU time used by the process.

  • COMMAND: Command that initiated the process.

Interacting with htop

htop provides a range of interactive features to manage and monitor processes:

  • Arrow Keys: Navigate through the process list.

  • F1: Help – Displays the help screen.

  • F2: Setup – Customize htop settings (e.g., display options, meters).

  • F3: Search – Search for a specific process.

  • F4: Filter – Filter processes by name.

  • F5: Tree View – Display processes in a tree structure.

  • F6: Sort – Change the sorting column (e.g., by CPU, memory).

  • F7/F8: Adjust the nice value of a process.

  • F9: Kill – Send a signal to a process to terminate it.

  • F10: Quit – Exit htop.

Customizing htop

To tailor htop to your preferences, press F2 to access the setup menu. Here, you can configure different aspects of the interface:

  • Meters: Add or remove meters from the header section.

  • Display Options: Adjust display settings like highlighting, tree view, and more.

  • Colors: Customize the color scheme.

  • Columns: Add, remove, or reorder columns in the process list.

Steps to Monitor System Processes Using htop Command

Step 1: Connect Your Server with SSH

You need to connect your server through an SSH connection.

Step 2: Using htop Command Under SSH Terminal

Once your server is connected with SSH, you can run the htop command by just typing the htop and press Enter. A screen will open up as a result of this command and will look like the below screenshot.

The whole window above can be split up into three sections for the ease of our understanding. The top-left section comprises the CPU and memory usage information. The top-right section provides info about load average and uptime. The rest of the information contains real-time data of processes with stats like priority, CPU and memory consumption, etc.

We will cover these sections one by one.

CPU

Starting from the top left, there is a CPU line that shows the percentage of CPU being used. For a single-core CPU, there will be one line for it. In the case of multi-core CPUs, there will be no number of lines depending on the number of CPU cores. In any case, if the CPU percentage is near 0 marks then it means the CPU is not having much load and if it approaches 100 for a long time, it means the CPU is under load.

Color coding of CPU usage lines:The lines indicating CPU and Memory usage have a color-coding of CPU. Following colors indicate the type of process:

Red = Kernel process Green = Normal user process Blue = Low priority process

Memory

The next line denotes memory being consumed by the process running on the server, this is denoted by the number of memory used out of total memory.

Color coding of Memory usage lines:

Green: Used memory pages Blue: Buffer pages Yellow: Cache pages

Load Average

It is the average of computational work performed by the CPU. 1.0 on a single core CPU would mean 100 percent utilization, similarly, 2.0 on a dual-core CPU represents 100% CPU usage.

The load average contains three values. The first number is a minute average(0.00 in the figure above), the second number is 5 minutes average (0.01 in the above figure) while the third number is fifteen minutes average (0.05 in the figure).

Process Information

The information below shows the information about processes running on your server.

As shown in the above figure the following words denote:

PID: Unique Process ID. USER: Process Owner. VIRT: Virtual memory being consumed by the process %CPU: The percentage of the processor time used by the process. %MEM: The percentage of physical RAM used by the process. COMMAND: The name of the command that started the process.

The htop footer contains its menu command.

These commands can be used to do various functions for e.g. F6 Sort By can be used to sort the process via CPU usage and memory usage.

Conclusion

htop is a powerful tool for monitoring system processes, providing an intuitive interface and a wealth of information at a glance. With its interactive features and customization options, htop makes it easy to keep track of system performance and manage processes effectively.

Last updated