htop Command in Linux(Unix): An Easy Guide in 2 minutes

Rate this post

Introduction

The htop command in Linux/Unix is a powerful, interactive process viewer that offers an enhanced version of the top command. With htop, users can monitor system processes in real time, track system resource usage, and manage processes with an intuitive, colorful, and user-friendly interface.

First, get familiar with general uses of Linux commands. The htop command is a great tool to investigate about any processes (e.g – mongod, nginx etc) in general (like CPU usage, memory usages, i/o usages, number of child processes etc).

1. Installation of htop command

htop is usually available in the system’s package manager:

  • Ubuntu/Debian:sudo apt update && sudo apt install htop
  • CentOS/RHEL:sudo yum install htop
  • macOS (with Homebrew):brew install htop

2. Launching htop command

Launch htop by typing:

htop

This opens the interactive dashboard with process and resource information. The interface consists of three sections: CPU and memory meters, a summary of active tasks, and a table of detailed process information.

3. Key Features of htop command

  • CPU and Memory Usage: htop displays individual CPU core usage with color-coded bars and details for memory (RAM) and swap space.
  • Process Tree View: htop can visualize processes in a tree structure, making it easy to see relationships between parent and child processes.
  • Sorting Options: Sort by CPU usage, memory usage, process ID, and other criteria with a simple keystroke (F6).
  • View I/O: Recent versions of htop shows i/o of processes in a separate tab, see below:
I/O tab in htop command in linux

4. Commonly Used Commands in htop

  • F1 (Help): Displays help documentation.
  • F2 (Setup): Opens the configuration menu to customize appearance, display options, and color schemes.
  • F3 (Search): Search for specific processes.
  • F4 (Filter): Filter processes by keyword, showing only relevant entries.
  • F5 (Tree View): Displays hierarchical processes.
  • F6 (Sort): Change sorting criteria (CPU, memory, PID).
  • F9 (Kill Process): Send a signal to terminate a process.

5. Detailed Process Information

  • PID (Process ID): Unique identifier for each process.
  • USER: The user account running the process.
  • CPU%: Percentage of CPU resources consumed by the process.
  • MEM%: Percentage of RAM resources consumed by the process.
  • TIME+: Total CPU time the process has consumed.
  • COMMAND: The command that started the process, often including full command-line arguments.

6. Filtering and Searching

  • Searching: Press F3(or click on Search button) to initiate a search and enter keywords (e.g., process name) to locate specific processes quickly. See below the yellow row
use F3 or click on the search button to search for a process in htop in Linux
  • Filtering: Use F4 to filter by keyword, and only processes containing that keyword will be shown, which helps reduce the clutter when analyzing specific processes.
use F4 or click on Filter button to filter all processes matching keyword within htop in linux

7. Managing Processes in htop

  • Killing Processes: You can end processes directly within htop. Select a process using arrow keys and press F9. You’ll see a list of signals, such as SIGTERM(15) and SIGKILL(9), which you can use to terminate or kill processes.
terminate or kill a process with F9 within htop in linux
  • Renicing Processes: Use F7 and F8 to adjust the “niceness” of a process, which changes its priority in CPU scheduling. Lower values mean higher priority, allowing users to give critical processes more CPU time.

8. Customizing htop

htop is highly customizable:

  • Changing Colors and Meters: In the F2 setup menu, you can adjust the display colors and choose what system metrics to show.
  • Persistent Configurations: htop saves configurations in ~/.config/htop/htoprc, making customizations persistent across sessions.
  • Header Customization: Use the Meters option under F2 to add or remove information such as uptime, memory, load average, etc.

9. Monitoring Remote Systems with htop

htop can be run on remote servers via SSH for system monitoring:

ssh user@remote-server htop

This is helpful for administrators needing a quick, interactive view of system health.

10. Pros and Cons of htop vs top

  • Pros:
    • Visual and color-coded interface for better readability.
    • Process tree structure for hierarchical view.
    • Ease of use with function keys for commands.
  • Cons:
    • htop may consume slightly more resources than top.
    • Not installed by default on all systems, requiring extra installation.

Conclusion

The htop command is an advanced yet intuitive tool for real-time process monitoring. Its interface and functionality provide a clear, actionable snapshot of CPU, memory, and process details, making it invaluable for system administrators. With customizable views, process management options, and efficient resource monitoring, htop is a versatile choice for system performance oversight on Linux and Unix systems.

Spread the love

Leave a Comment