Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux htop command

Linux htop command

Linux Command Reference Linux Command Reference


What is htop

htop is an interactive process viewer for Linux systems. It offers richer features and a more user-friendly interface than the traditional top command.

Main features of htop


Install htop

On Debian/Ubuntu-based systems



sudo apt update

sudo apt install htop

On RHEL/CentOS-based systems



sudo yum install epel-release  # 先安装 EPEL 仓库

sudo yum install htop

On Arch Linux-based systems



sudo pacman -S htop


htop basic interface overview

To start htop, simply enter in the terminal:



htop

The interface is mainly divided into the following sections:

  1. Top area: System overview information

  2. CPU usage (displayed per core)
  3. Memory usage
  4. Swap space usage
  5. System uptime and average load
  6. - CPU usage (displayed per core) - Memory usage - Swap space usage - System uptime and average load
    1. Middle area: Process list

    2. PID: process ID
    3. USER: process owner
    4. PRI: process priority
    5. NI: nice value
    6. VIRT: virtual memory usage
    7. RES: physical memory usage
    8. SHR: shared memory size
    9. S: process state (running, sleeping, etc.)
    10. CPU%: CPU usage
    11. MEM%: memory usage
    12. TIME+: CPU time
    13. COMMAND: command name
    14. - PID: process ID - USER: process owner - PRI: process priority - NI: nice value - VIRT: virtual memory usage - RES: physical memory usage - SHR: shared memory size - S: process state (running, sleeping, etc.) - CPU%: CPU usage - MEM%: memory usage - TIME+: CPU time - COMMAND: command name
      1. Bottom area: Function key hints


      htop common shortcut keys

      Keyboard shortcut Description
      F1 or h Show help
      F2 or S Enter the settings menu
      F3 or / Search processes
      F4 or \ Filter processes
      F5 or t Display the process tree
      F6 or < Select the sort field
      F7 or [ Lower the process priority
      F8 or ] Raise the process priority
      F9 or k Terminate a process
      F10 or q Exit htop
      Space Key Mark/unmark processes
      u Display processes of a specific user
      H Show/hide user threads
      K Show/hide kernel threads
      P Sort by CPU usage
      M Sort by memory usage
      T Sort by running time

      htop advanced features

      1. Process tree view

      Press F5 or t You can switch to the process tree view to display the parent-child relationships between processes.

      2. Process filtering

      Press F4 or \ You can enter a filter condition to display only processes that match.

      3. Multi-select operations

      After marking multiple processes with the space bar, you can perform batch operations (such as termination).

      4. Custom display

      Press F2 Enter the settings menu to:

      5. System monitoring

      The top area of htop provides rich system monitoring information:


      Comparison of htop and top commands

      Feature htop top
      Interface Colored, intuitive Monochrome, basic
      Mouse support Is No
      Process tree view Supported Not supported
      Sorting method Multiple, can be adjusted dynamically Limited
      Process operations Richer Basic
      Customization Highly configurable Limited
      Resource usage Slightly higher Lower

      Practical Application Examples

      Example 1: Find and terminate a process with high CPU usage

      1. Start htop
      2. Press P Sort by CPU usage
      3. Find the target process
      4. Press F9 Select the termination signal (usually 15 SIGTERM)
      5. Press Enter to confirm

      Example 2: Monitor the processes of a specific user

      1. Start htop
      2. Press u Key
      3. Select the user name to monitor
      4. Display only that user's processes

      Example 3: Set the refresh interval

      1. Press F2 Enter the settings
      2. Select "Display options"
      3. Modify the "Delay" value (seconds)
      4. Press F10 Save and exit

      Frequently Asked Questions

      Q1: Which is better, htop or top?

      htop provides richer features and a more friendly interface, suitable for interactive use; top is more lightweight, suitable for use in scripts.

      Q2: Why do some processes appear green/red?

      Green usually indicates a normally running process, while red may indicate high resource usage or a zombie process.

      Q3: How do I view the full command line?

      Press F2 Enter the settings and adjust the "Show program path" option in "Display options".

      Q4: What does the memory information displayed by htop mean?

      Linux Command Reference Linux Command Reference