How to Use htop for Advanced Server Monitoring and Management

use htop for advance server monitoring

When working on Linux, keeping track of system performance is an important task. For this, one of the most useful tools is the htop command. Unlike the traditional top command, htop gives a more user-friendly and interactive view of what’s happening inside your system.

With htop, you can easily check running processes, system resources, server monitoring, CPU load, memory usage, and swap space in real time. It highlights information with colors, supports mouse navigation, and even lets you scroll both vertically and horizontally to view complete details. This makes it much easier to spot performance issues or manage processes compared to older tools.

In this article, we’ll explore how to use the Linux htop command effectively, covering its main features and practical usage.

How to Use the Linux htop Command 

To use the htop command in Linux, simply type the following command in your terminal and hit the ENTER key:

htop

As a result, an interactive dashboard will be opened, where you can view all active processes along with CPU, memory, and Linux swap usage. You can also include different options when starting htop to adjust what information is displayed.

Common Options

When using the htop command in Linux, you can add different options to customize the output. Some of the most popular ones are listed in the following table:

  • -d <delay>: sets the refresh interval in seconds between screen updates.
  • -u <user>: shows only the processes that belong to a specific user.
  • -p <pid>: limits the display to the process or processes with the given IDs.
  • -s <column>: arranges the list of processes based on the chosen column.
  • -t: presents processes in a tree format, making the hierarchy easier to understand.
  • –no-color: starts htop in plain monochrome mode without colored highlights.

Server Monitoring and Management Using htop Command

The htop command helps us monitor and manage a Linux server in real time. It provides a dynamic, interactive view of all running processes, CPU and memory usage, and swap space, making it easy to spot resource-intensive tasks.

Let’s go through the following examples to see how this command helps us monitor and manage advanced servers.

Set Update Interval with -d <delay>

The -d option in htop allows you to control how often the display refreshes. For instance, running the following command sets the update interval to 1.0 seconds. 

htop -d 10

When I ran the htop command on my Linux system, I immediately got a clear, real-time view of how my system was performing. At the top, I could see the CPU usage for each core, CPU 0 was almost idle at 0.0%, while CPU 1 was barely active at 1.0%. Memory usage showed 880MB of my 3.82GB RAM in use, and swap wasn’t being used at all. 

The system had 110 tasks running across 347 threads, with just 2 actively running, and the load average over 1, 5, and 15 minutes was comfortably below 2, indicating the system was lightly loaded.

Set Update Interval

Similarly, you can specify any value to set the delay according to your needs. For example, use 16, 20, etc. to set the delay of 1.6, 2.0 seconds, and so on.

Adjusting this delay is useful because it reduces the frequency of screen updates, making it easier to observe system activity without constantly changing numbers. This can be especially helpful when monitoring a busy system, as it gives you a clearer view of resource usage over time.

Display Processes for a Specific User Using htop

You can use the htop command with the -u option to view only the processes running under a specific user. This is useful when you want to monitor or manage the tasks of one particular user without getting distracted by other system processes. For example, to see processes for a user named linuxuser, you can run the following command:

htop -u linuxuser

The htop command filters the output and shows only the processes belonging to linuxuser, making it easier to focus on that user’s activity.

Display Processes for a Specific User Using htop

Monitor Specific Processes Using htop

The htop -p <pid> command allows you to focus on a specific process by its Process ID (PID). When you use this command, it shows the PID you specify along with all child processes or threads created by that process. This gives a complete view of the process’s activity. For example, to monitor a process with PID 8759, you would run:

htop -p 8759

This helps you track the CPU, memory, and overall resource usage of the main process along with any related subprocesses, making it easier to understand how the process operates.

Monitor Specific Processes Using htop

Sort Processes by a Specific Column Using htop

The htop -s <column> command allows you to organize the process list based on a specific column, such as CPU usage, memory usage, or process ID. This makes it easier to find the processes that are using the most resources or to track processes in a particular order. For example, if you want to sort processes by memory usage, you can specify the memory column:

htop -s PID

The output shows that htop has sorted the processes based on their PID. 

Sort Processes by a Specific Column Using htop

This makes it easier to view processes in numerical order and quickly locate a specific PID among all running processes. Similarly, you can sort the output with respect to any other column of your choice.

View Processes in a Tree Structure Using htop

You can use the htop command with the -t option to show all running processes in a tree view under the Commands column. This layout makes it easy to see the parent and child relationships between processes, helping you understand which processes are spawned by others and how they are connected.

htop -t
View Processes in a Tree Structure Using htop

Run htop Without Colors

The htop --no-color command launches htop without using any colors in the interface. This can be useful if you are working in a terminal that does not support colors or if you prefer a plain, monochrome view for easier reading or capturing output in logs.

htop --no-color
Run htop Without Colors

Interactive Commands in htop

When using htop, you can interact with your system’s processes using several keys and shortcuts:

  • Arrow Keys, Page Up, Page Down, Home, End: Navigate through the list of running processes.
  • Space: Mark (tag) or unmark a process for actions.
  • U: Remove all tags from processes that were marked with the Space key.
  • s: Trace the system calls of a process to monitor what it’s doing.
  • F1: Open the help menu for guidance on commands.
  • F2: Access setup options to configure htop preferences.
  • F3: Search for a specific process by name or command.
  • F4: Apply a filter: type part of a process name, and only matching processes will be displayed.
  • F5: Switch to a tree view to see processes in a hierarchical structure.
  • F6: Sort processes by different criteria like CPU, memory, or process ID.
  • F7: Increase the priority (nice value) of a selected process. Only the superuser can perform this action.
  • F8: Decrease the priority of a selected process.
  • F9: Terminate (kill) the selected process.
  • F10: Exit htop.

These commands allow you to efficiently monitor and manage system processes while maintaining full control over resources.

Conclusion

The htop command is a useful tool that helps us monitor and manage Linux systems in real time. It offers a clear view of running processes, CPU and memory usage, swap space, and system load, making it easier to identify resource-intensive tasks. With its options, you can customize the display to focus on specific users, individual processes, or particular columns, view processes in a hierarchical tree structure, adjust refresh intervals, or even run it without colors.

Looking to take your Linux experience to the next level? Ultahost’s Ubuntu VPS hosting gives you the perfect balance of speed, reliability, and flexibility. Whether you’re running applications, managing websites, or handling development projects, our VPS solutions are designed to deliver smooth performance and hassle-free management.

FAQ

What is the htop command in Linux?
How is htop different from the top command?
How can I view processes for a specific user using htop?
How do I sort processes in htop?
How do I adjust the refresh interval in htop?
Is htop useful for server monitoring?
Can I customize the htop interface?

Related Post

How to Check Apache Version in Linux

Apache is a widely used, open-source web server compati...

How to Set Docker Environment Variables

Docker has revolutionized how we build, deploy, and run...

Efficient User Session Management in Linux us...

User management is an important aspect of maintaining a...

How to Install Deb Files / Packages on Ubuntu

The .deb packages are the standard format for installin...

How to Set Environment Variables in ZSH

Environment variables are useful when working with scri...

Exploring Sed Command in Linux

The sed command stands for stream editor is a powerful ...

Leave a Comment