💻
🔧
🐧
Intermediate
Bash
July 6, 2025

htop Command Linux Guide: Master System Monitoring Like a Pro

Categories: System Admin
Tags: #htop

Description

How to Use htop for Linux System Monitoring?

Quick Answer: htop is an interactive process viewer that displays real-time system information with color-coded CPU, memory usage, and process management capabilities. Simply run htop in terminal for an enhanced alternative to the traditional top command.

Basic htop Commands

# Install htop on your system
sudo apt install htop        # Ubuntu/Debian
sudo yum install htop        # CentOS/RHEL  
sudo dnf install htop        # Fedora

# Start htop with default settings
htop

# Monitor specific user processes
htop -u username

# Start with tree view enabled
htop --tree

# Sort by CPU usage from start
htop --sort-key PERCENT_CPU

# Custom refresh interval (5 seconds)
htop -d 5

Frequently Asked Questions

What is htop and how is it different from top?
htop is an enhanced version of the top command that provides a colorful, interactive interface with mouse support, easier process management, and better visual representation of system resources. Unlike top, htop shows individual CPU cores and allows point-and-click process management.

How do I install htop on Linux?
Install htop using your distribution’s package manager: sudo apt install htop (Ubuntu/Debian), sudo yum install htop (CentOS/RHEL), or sudo dnf install htop (Fedora). Most modern Linux distributions include htop in their repositories.

What do the colors mean in htop?
CPU bars use blue for low priority processes, green for normal processes, red for kernel processes, and yellow for I/O wait. Memory bars show green for used memory, blue for buffers, and yellow for cache.

How do I kill a process in htop?
Select the process using arrow keys or mouse, then press F9 to open the kill menu. Choose the appropriate signal (SIGTERM is default, SIGKILL for force kill). You can also press ‘k’ as a shortcut.

Can I sort processes by CPU or memory usage?
Yes, press F6 to open the sort menu and select CPU% or MEM%. You can also click on column headers to sort by that column. Use htop --sort-key PERCENT_CPU to start with CPU sorting enabled.

How do I see process relationships in htop?
Press F5 or ‘t’ to toggle tree view, which displays processes in a hierarchical structure showing parent-child relationships. You can also start htop with htop --tree for immediate tree view.

Why can’t I kill certain processes in htop?
You need appropriate permissions to kill processes. System processes require root access, and you can only kill processes owned by your user account unless running htop with sudo privileges.

How to Install and Run htop?

Installation Steps by Distribution

DistributionCommandPackage ManagerNotes
Ubuntu/Debiansudo apt install htopAPTMost common installation
CentOS/RHEL 7sudo yum install htopYUMRequires EPEL repository
CentOS/RHEL 8+sudo dnf install htopDNFModern package manager
Fedorasudo dnf install htopDNFAvailable in default repos
Arch Linuxsudo pacman -S htopPacmanRolling release
openSUSEsudo zypper install htopZypperEnterprise and Leap

Basic Usage Commands

# Start htop with default settings
htop

# Monitor specific user processes
htop -u username

# Start with tree view enabled
htop --tree

# Custom refresh interval (seconds)
htop -d 5

How to Use htop Step-by-Step?

Complete Beginner Workflow

  1. Verify htop installation – Type which htop to confirm htop is installed
  2. Launch htop – Run htop command in terminal (no sudo required for viewing)
  3. Examine the header – Top section shows CPU cores (numbered), memory usage, and system load
  4. Understand color coding – Blue (low priority), green (normal), red (kernel), yellow (I/O wait)
  5. Navigate process list – Use arrow keys or mouse to select different processes
  6. Sort by resource usage – Press F6 and select CPU% or MEM% for performance analysis
  7. Filter processes – Press F4 and type username or process name to narrow results
  8. Manage processes – Select process and press F9 to kill, F8 to change priority
  9. Toggle tree view – Press F5 to see parent-child process relationships
  10. Exit htop – Press F10 or ‘q’ to return to command prompt

Advanced Monitoring Workflow

  1. Start with sorted view – Launch htop --sort-key PERCENT_CPU to immediately see high-CPU processes
  2. Set custom refresh rate – Use htop -d 2 for 2-second updates during troubleshooting
  3. Filter by user – Run htop -u apache to monitor specific service processes
  4. Enable tree view – Start with htop --tree to understand process relationships
  5. Customize display – Press F2 to access setup menu and configure columns
  6. Save configuration – Use F2 → Save to remember your preferred settings
  7. Monitor specific PIDs – Use htop -p $(pgrep nginx) to track particular processes
  8. Batch operations – Use Space to tag multiple processes, then F9 to kill selected ones

What are the Essential htop Commands?

CommandPurposeExampleKeyboard Shortcut
htopStart basic monitoringhtop
htop -u userShow user processes onlyhtop -u apacheF4 (filter)
htop -d 10Custom refresh intervalhtop -d 5
htop --treeProcess tree viewhtop --treeF5 (tree toggle)
htop --sort-key PERCENT_CPUSort by CPU usagehtop --sort-key PERCENT_MEMF6 (sort)

When Should You Use htop in Real-World Scenarios?

Server Performance Troubleshooting

# Monitor high CPU processes
htop --sort-key PERCENT_CPU

# Check memory usage patterns
htop --sort-key PERCENT_MEM

# Monitor specific service processes
htop -u www-data  # Web server processes
htop -u mysql     # Database processes

Development Environment Monitoring

# Watch processes in tree view to see parent-child relationships
htop --tree

# Monitor development server resources
htop -p $(pgrep node)  # Node.js processes
htop -p $(pgrep python) # Python processes

System Administration Tasks

# Monitor system during maintenance
htop -d 2  # Refresh every 2 seconds

# Track specific user activity
htop -u username

# Monitor after system changes
htop --sort-key TIME  # Sort by runtime

What Interactive Features Does htop Offer?

Complete Navigation Guide

ActionMethodKeyboardMouseDescription
Select processNavigation↑↓ arrowsClick processHighlight specific process
Scroll listPagingPage Up/DownScroll wheelMove through long process lists
Jump to top/bottomNavigationHome/EndQuick list navigation
Tag processesSelectionSpaceCtrl+ClickSelect multiple for batch operations
Process detailsInformationEnterDouble-clickView detailed process information
Sort by columnOrganizationF6 or < >Click headerChange sorting criteria
Filter processesSearchF4Show only matching processes
Tree toggleViewF5 or tShow/hide process relationships

Process Management Steps

  1. Locate target process – Use arrow keys or search (F3) to find the process
  2. Select the process – Click on it or navigate with arrow keys
  3. Choose action – Press F9 for kill menu, F8 for priority adjustment
  4. Confirm action – Select signal type (TERM, KILL, etc.) and confirm
  5. Verify result – Check that process disappeared or changed as expected
  6. Handle errors – If action fails, check permissions or try with sudo

Display Customization Options

SettingAccess MethodOptions AvailablePurpose
MetersF2 → SetupCPU, Memory, Swap barsCustomize header display
ColumnsF2 → ColumnsPID, CPU%, MEM%, TIME+Choose visible information
ColorsF2 → ColorsMonochrome, Color schemesVisual appearance
DisplayF2 → DisplayTree view, Kernel threadsProcess visibility
HeaderF2 → HeaderLayout optionsInformation organization

How to Understand the htop Display?

Header Section Breakdown

ElementColor CodingMeaningExample
CPU barsBlue: Low priorityNormal user processes[
CPU barsGreen: NormalRegular processes[
CPU barsRed: KernelSystem/kernel processes[
CPU barsYellow: I/O waitWaiting for disk/network[
Memory barGreen: UsedApplication memory[
Memory barBlue: BuffersFile system buffers[
Memory barYellow: CacheFile system cache[
Swap barRed: Used swapVirtual memory usage[

Process List Column Guide

ColumnFull NameDescriptionTypical Values
PIDProcess IDUnique process identifier1234, 5678
USERUserProcess ownerroot, apache, mysql
CPU%CPU PercentageCurrent CPU usage0.0, 25.5, 100.0
MEM%Memory PercentageRAM usage percentage0.1, 2.5, 15.8
TIME+CPU TimeTotal CPU time used0:01.23, 5:45.67
COMMANDCommand LineProcess name and argumentsnginx, python script.py
NINice ValueProcess priority-20 to 19
VIRTVirtual MemoryTotal virtual memory1.2G, 456M
RESResident MemoryPhysical RAM usage123M, 45.6M
SHRShared MemoryShared memory size12.3M, 2.1M

System Statistics Interpretation

MetricLocationMeaningGood ValuesWarning Signs
Load AverageTop rightSystem load (1min, 5min, 15min)< CPU cores> 2x CPU cores
TasksTop rightProcess countsRunning < 5High zombie count
CPU UsageCPU barsPer-core utilization< 80% averageConsistently > 90%
Memory UsageMemory barRAM utilization< 80%> 95% used
Swap UsageSwap barVirtual memory0 or minimalHeavy swap usage

Step-by-Step Display Analysis

  1. Check load average – Look at top-right corner for 1, 5, and 15-minute averages
  2. Examine CPU bars – Count cores, identify I/O wait (yellow) and kernel usage (red)
  3. Analyze memory usage – Note used (green), buffers (blue), and cache (yellow) portions
  4. Review swap activity – Red swap bar indicates memory pressure
  5. Scan process list – Sort by CPU% or MEM% to identify resource consumers
  6. Verify process states – Check for zombie processes or high nice values
  7. Monitor trends – Watch values over time rather than single snapshots

What Advanced htop Techniques Should You Know?

Custom Monitoring Setup

# Create monitoring aliases
alias htop-cpu='htop --sort-key PERCENT_CPU'
alias htop-mem='htop --sort-key PERCENT_MEM'
alias htop-apache='htop -u www-data'

# Monitor specific process types
htop -p $(pgrep -f "nginx\|apache")  # Web servers
htop -p $(pgrep -f "mysql\|postgres") # Databases

Performance Analysis Workflow

  1. Initial overview – Check overall system load and resource usage
  2. Identify bottlenecks – Sort by CPU% or MEM% to find resource hogs
  3. Examine relationships – Use tree view (F5) to see process hierarchies
  4. Filter relevant processes – Use F4 to focus on specific users or commands
  5. Take action – Kill problematic processes or adjust priorities as needed

How to Fix Common htop Issues?

How to Fix Common htop Issues?

Troubleshooting Table

ProblemSymptomsSolutionCommand Example
htop not found“command not found” errorInstall htop packagesudo apt install htop
Permission deniedCannot kill processesRun with sudo or check ownershipsudo htop
Display corruptedGarbled or unreadable outputReset terminal and resizereset && htop
No color displayPlain text without colorsCheck terminal color supportTERM=xterm-256color htop
High CPU not visibleSystem slow but htop shows low usageCheck I/O wait and system processessudo htop
Memory values wrongIncorrect memory reportingUpdate htop to latest versionsudo apt update && sudo apt upgrade htop
Tree view brokenProcesses not showing relationshipsReset htop configurationrm ~/.config/htop/htoprc
Slow performancehtop itself using high resourcesIncrease refresh intervalhtop -d 5

Step-by-Step Troubleshooting Guide

Installation Issues

  1. Check if htop exists – Run which htop to verify installation
  2. Update package lists – Execute sudo apt update (Ubuntu/Debian)
  3. Install htop – Run distribution-specific install command
  4. Verify installation – Test with htop --version
  5. Check PATH – Ensure /usr/bin is in your PATH variable

Display Problems

  1. Test terminal compatibility – Try TERM=xterm htop
  2. Resize terminal window – Make window larger if display is cramped
  3. Reset terminal settings – Run reset command before htop
  4. Check color support – Verify terminal supports 256 colors
  5. Update terminal software – Use modern terminal emulator

Performance Issues

  1. Identify bottleneck – Check if htop itself is causing high CPU
  2. Increase refresh interval – Use htop -d 10 for 10-second updates
  3. Limit process display – Filter to specific users with htop -u username
  4. Disable tree view – Turn off tree mode if system is very busy
  5. Close unnecessary terminals – Multiple htop instances consume resources

What are the Essential htop Keyboard Shortcuts?

Primary Function Keys

ShortcutFunctionDescriptionAlternative
F1HelpShow all available shortcutsh
F2SetupConfigure htop display optionsS
F3SearchFind processes by name/
F4FilterShow only matching processes\
F5TreeToggle process tree viewt
F6SortChange sorting column< or >
F7Nice-Decrease process priority[
F8Nice+Increase process priority]
F9KillSend signal to processk
F10QuitExit htopq

Navigation Shortcuts

ShortcutActionDescription
↑↓NavigateMove up/down process list
Page Up/DownScrollJump by page in process list
Home/EndJumpGo to first/last process
SpaceTagSelect multiple processes
EnterDetailsShow process details
uUserFilter by specific user
MMemorySort by memory usage
PCPUSort by CPU usage
TTimeSort by running time

Advanced Control Shortcuts

ShortcutFunctionUse Case
cCommandToggle command line display
eEnvironmentShow process environment
fFollowFollow process in tree view
HThreadsToggle user thread display
IInvertInvert sort order
KHide kernelToggle kernel threads
LLog filesShow open log files
sSystem callTrace system calls

How Does htop Compare to Other Monitoring Tools?

How Does htop Compare to Other Monitoring Tools?

Comprehensive Tool Comparison

FeaturehtoptopatopglancesSystem Monitor
Color coding✅ Yes❌ No✅ Yes✅ Yes✅ Yes
Mouse support✅ Yes❌ No❌ No❌ No✅ Yes
Tree view✅ Yes❌ No✅ Yes✅ Yes✅ Yes
Process killing✅ Interactive⚠️ Manual⚠️ Manual❌ No✅ Interactive
Multi-core display✅ Individual❌ Average✅ Individual✅ Individual✅ Individual
Historical data❌ No❌ No✅ Yes⚠️ Limited⚠️ Limited
Network monitoring❌ No❌ No✅ Yes✅ Yes✅ Yes
Disk I/O❌ No❌ No✅ Yes✅ Yes✅ Yes
Remote monitoring✅ SSH✅ SSH✅ SSH✅ Web UI❌ Local only
Resource usageLowMinimalMediumMediumHigh

When to Use Each Tool

ScenarioRecommended ToolReason
Quick system checkhtopInteractive, visual, easy to read
Scripting/automationtopBatch mode, consistent output
Performance analysisatopHistorical data, detailed metrics
Server monitoringglancesNetwork and disk metrics included
Desktop usersSystem MonitorGUI, graphs, user-friendly
Minimal systemstopAlways available, low overhead
SSH troubleshootinghtopBest interactive experience
Capacity planningatopLong-term data collection

Step-by-Step Tool Selection Guide

  1. Identify your monitoring needs – Determine if you need real-time, historical, or specific metrics
  2. Consider your environment – Choose SSH-compatible tools for remote servers
  3. Evaluate resource constraints – Use lighter tools on resource-limited systems
  4. Test tool availability – Verify if the tool is installed or can be installed
  5. Match interface preferences – Select GUI for desktop, CLI for servers
  6. Consider integration requirements – Choose tools that work with your monitoring stack

What Performance Impact Does htop Have?

Resource Usage Comparison

ToolCPU UsageMemory UsageDisk I/ONetworkBest Use Case
htop (default)< 0.5%2-4 MBMinimalNoneInteractive monitoring
htop (1s refresh)0.5-1%2-4 MBLowNoneActive troubleshooting
htop (tree view)0.5-2%4-8 MBLowNoneProcess relationship analysis
top< 0.3%1-2 MBMinimalNoneMinimal systems
System Monitor1-3%15-30 MBMediumNoneDesktop environments
glances2-5%10-20 MBMediumMediumComprehensive monitoring

Optimization Configuration Table

SettingDefaultOptimizedImpactWhen to Use
Refresh Rate1.5s5-10sLower CPU usageStable systems
Tree ViewOffOn when neededHigher memoryProcess debugging
Color ModeFullMonochromeMinimal impactTerminal compatibility
Thread DisplayUser onlyHide kernelLower overheadGeneral monitoring
Column CountStandardMinimal neededLess processingResource-constrained
Process FilterAllSpecific usersReduced displayFocused monitoring

Step-by-Step Performance Optimization

For Resource-Constrained Systems

  1. Increase refresh interval – Use htop -d 10 for 10-second updates
  2. Disable tree view – Start without --tree option to save memory
  3. Limit columns – Press F2 → Columns and disable unnecessary columns
  4. Filter processes – Use htop -u username to show only relevant processes
  5. Use monochrome mode – Press F2 → Colors → Monochrome to save processing
  6. Hide kernel threads – Press K to hide kernel processes if not needed

For Optimal Monitoring Experience

  1. Set comfortable refresh rate – Use htop -d 2 for 2-second updates during analysis
  2. Enable tree view – Use htop --tree when analyzing process relationships
  3. Customize meters – Press F2 → Setup to show relevant system information
  4. Save configuration – Press F2 → Save to preserve optimized settings
  5. Create monitoring aliases – Set up shell aliases for different htop configurations
  6. Combine with other tools – Use alongside iotop, nethogs for comprehensive analysis

Best Practices Checklist

PracticeFrequencyPurposeCommand Example
Regular monitoringDailyEstablish baselineshtop during normal operations
Performance analysisAs neededIdentify bottleneckshtop --sort-key PERCENT_CPU
Process cleanupWeeklyRemove zombie processesUse F9 in htop to kill zombies
Configuration reviewMonthlyOptimize display settingsPress F2 to review setup
Tool integrationAlwaysComplete system pictureCombine with logs and metrics
DocumentationOngoingTrack system changesNote normal vs. abnormal patterns

How to Integrate htop with System Administration?

Log Analysis Workflow

# Monitor processes while checking logs
htop &  # Run in background
tail -f /var/log/syslog | grep ERROR

# Or use split terminal
# Terminal 1: htop
# Terminal 2: log monitoring

Automation and Scripting

# htop in batch mode for scripting
htop -b -n 1 > system_snapshot.txt

# Combine with other monitoring
watch -n 5 'htop -b -n 1 | head -20'

What Related Tools Work Well with htop?

  • top – Traditional process viewer with similar functionality
  • atop – Advanced system and process monitor with historical data
  • iotop – I/O monitoring equivalent to htop for disk activity
  • nethogs – Network traffic monitor per process
  • glances – Cross-platform system monitoring tool
  • nmon – Performance monitoring for AIX and Linux systems

What is the htop Quick Reference Summary?

Installation: sudo apt install htop (Ubuntu/Debian)
Basic usage: htop
Key shortcuts: F9 (kill), F6 (sort), F4 (filter), F5 (tree)
Process management: Select process → F9 → choose signal
Customization: F2 → setup menu
Exit: F10 or q

htop transforms system monitoring from a complex task into an intuitive, visual experience that every Linux administrator should master for effective system management and troubleshooting.

Related Commands