Monitor Linux System Performance with top and htop

Introduction

When managing Linux servers, especially on Red Hat-based systems as RHEL, Rocky Linux or any distribution of Linux, real-time monitoring tools like top and htop are handy. They provide a glance of your system health as CPU usage, memory consumption, process details and more.

 In this post, we'll walk you through the requirements, installation and usage of both top and htop on Linux systems.

Requirements

                A Linux-based system (RHEL, Ubuntu, and Rocky Linux or any Linux distribution)

                Access to terminal (CLI)

                Sudo privileges

Installation:

Mostly top utility is pre-installed on all Linux distributions; however, htop is not installed by default in RHEL 9. You can run it directly by typing top on bash.

#top

If htop is not pre-installed on any Linux distribution, you can easily install it. As is the case, htop is not installed on RHEL 9. Now, follow the following steps to install htop in RHEL 9.

Step 1: Enable the EPEL repository if not already enabled

EPEL stands for Extra Packages for Enterprise Linux. It is a community-driven repository maintained by the Fedora project that provides additional software packages that are not included in the official Red Hat or CentOS repositories. The EPEL repository includes these extra open-source packages built to be fully compatible with RHEL-based systems.

Here epel repository is enabled by this command on RHEL 9.

Now install epel-release with the command sudo dnf install epel-release. you must enable the EPEL repository before installing htop; otherwise, you will get an error message.

#sudo dnf install epel-release

Step 2: Install htop

# sudo dnf install htop


That’s it. Check htop is successfully installed with the command htop --version. Now htop is ready to use.

Usage

To start monitoring issue top command on bash.

# top

This is the interface of the top command with real-time statistics of the Linux system.

You’ll see real-time statistics. Here's what each section means:

·       Load average: System load over 1, 5 and 15 minutes

·       Up Time: shows the up time of the system

·       Total Task: show the total task

·       Seeping Task: show any sleeping process

·       Zombie Task: show any zombie process

·       Stopped Task: show any of the stopped processes

·       Running Task: number of running tasks

·       Tasks: Number of running, sleeping and stopped processes

·       %CPU: CPU usage per process

·       %MEM: Memory usage per process

·       Swap Memory: usage of swap memory


Common commands within top:

You can run commands during the top running interface to control things in real time like the following commands.

q: Quit

k: Kill a process (you'll be prompted for PID)

r: Renice a process (change priority)

h: Help

Using htop

To start monitoring with htop, issue the htop command on bash.

# htop

You'll get a colorful, interactive dashboard.

Features:

    Scroll with arrow keys

    Use F3 for search and F4 for filter

    F9 kills process and F6 changes sort column

Comparison between top and htop

top

  •     By default installed in almost all distributions
  •        Provides basic system information and lists processes sorted by CPU or memory usage
  •        Offers fewer command-line options for filtering and sorting
  •       Comparatively simple to use for basic monitoring

htop

  •       Installation is required before using
  •       Includes colored output, supports mouse input and easy process management
  •      An interactive interface with a visually more appealing
  •     Offers robust, customized options sorting and display
  •     Requires more deeper learning curve due to its advanced features

Key Differences


Feature

top

htop

Default installation

Yes

No

User interface

Basic text-based

Enhanced, interactive, color-coded

Mouse support

No

Yes

Process management

Limited

More intuitive, including killing/renicing

Customization

Basic

Extensive

Learning curve

Low

Moderate

Frequently Asked Questions (FAQ)

Q1: What is the top command used for in Linux?

It displays a real-time summary of running processes, CPU, and memory usage.

Q2: What is the difference between top and htop?

htop offers an interactive, color-coded interface and easier process management compared to the traditional top.

Q3: How can I kill a process using htop?

Select the process with the arrow keys and press F9 to kill it.

Q4: Is htop available on all Linux distributions?

Not by default; you may need to install it using your package manager.

Q5: Can top or htop affect system performance?

They use minimal resources and are safe to run even on production systems.

Best Practices for Using top and htop

·         Use top for minimal resource monitoring on production systems.

·         Prefer htop for interactive and colorful visualization.

·         Combine htop with tools like vmstat or iostat for deeper analysis.

·         Avoid running htop continuously on low-memory systems.

·         Use htop -d 5 to reduce refresh frequency and save CPU usage.

Final Thoughts

Both top and htop is essential tools in a Linux admin's toolbox. While top is always available and reliable, htop brings user-friendly enhancements that make system monitoring much more interactive.  You are diagnosing system performance issues or monitoring your system load, mastering these tools will give you a deep understanding of what is happening under the hood.

keep visiting seeklinux for more updates and information.

Post a Comment