How to Monitor Processes in Linux with htop (Advanced Usage)

Ifย topย is the foundation,ย htop is the professional-grade tool.

This guide will take you from:

๐Ÿ‘‰ “I can open htop” โ†’ to ๐Ÿ‘‰ “I can debug production issues using htop efficiently”


What is htop (and Why It Matters)

htop is an interactive process viewer that improves on top with:

  • Visual CPU & memory bars
  • Mouse support
  • Easy sorting & filtering
  • Process tree visualization

Install it if not available:

yum install htop -y
# or
apt install htop -y

Basic Usage (Starting Point)

htop

You will see:

  • CPU usage per core
  • Memory and swap usage
  • Process list

Understanding the Interface (Expert View)

Top Section

  • CPU bars โ†’ real-time usage per core
  • Memory bar โ†’ RAM consumption
  • Swap โ†’ indicates pressure on system

Process Table Columns

ColumnMeaning
PIDProcess ID
USEROwner
CPU%CPU usage
MEM%Memory usage
TIME+Total CPU time
COMMANDProcess name

Essential Shortcuts (Must Know)

These shortcuts work inside terminal-based htop. On Linux, macOS, and Windows (via SSH/WSL) the keys are generally the same.

โš ๏ธ Note:

  • On some laptops (especially Mac), you may need to press Fn + F-key (e.g., Fn + F6)
  • On macOS Terminal/iTerm, function keys behave the same unless remapped
KeyFunction
F6 (or Fn+F6 on Mac)Sort column
F3 (or Fn+F3)Search process
F4 (or Fn+F4)Filter process
F5 (or Fn+F5)Tree view
F9 (or Fn+F9)Kill process
F10 (or Fn+F10)Exit

๐Ÿ‘‰ Alternative (if function keys donโ€™t work):

  • Use arrow keys + Enter
  • Or enable function keys in terminal settings

Advanced Usage (Where Experts Operate)

1. Sorting by Resource Usage

Press:

  • F6 โ†’ choose CPU or MEM

๐Ÿ‘‰ Quickly identify heavy processes


2. Filtering Specific Processes

Press:

F4 โ†’ type nginx

๐Ÿ‘‰ Shows only nginx-related processes


3. Tree View (Critical for Debugging)

Press:

F5

๐Ÿ‘‰ Understand parent-child relationships

Useful for:

  • PHP-FPM workers
  • Apache processes

4. Killing Processes Safely

Press:

F9 โ†’ choose signal

Recommended:

  • Try SIGTERM first
  • Use SIGKILL only if needed

Real Production Scenarios

Scenario 1: High CPU Usage

Steps:

  1. Sort by CPU (F6)
  2. Identify top process
  3. Check if expected
  4. Kill or investigate

Scenario 2: Memory Leak

Steps:

  1. Sort by memory
  2. Watch process growth over time
  3. Confirm leak pattern

Scenario 3: Too Many Processes

Use tree view (F5)

๐Ÿ‘‰ Identify runaway child processes


Scenario 4: Server Slow but CPU Low

Check:

  • Processes stuck
  • Low CPU but high load (from previous article)

๐Ÿ‘‰ Indicates I/O wait issue


Combining htop with Other Tools (Expert Workflow)

htop shows what is happening

Use other tools to see why:

strace -p PID
lsof -p PID

Common Mistakes

Only looking at CPU

Problem may be:

  • Disk I/O
  • Network
  • Locks

Killing without understanding

Always verify process role first


When This Matters in Production

htop is used when:

  • Server becomes slow
  • Load spikes
  • Applications misbehave

On production infrastructure like:

  • VPS servers
  • Dedicated servers
  • Cloud servers

๐Ÿ‘‰ Explore infrastructure:


Related Linux Guides


Final Takeaway

htop is not just a viewer.

It is a real-time decision tool.

An expert uses it to:

  • Identify problems quickly
  • Understand system behavior
  • Take controlled action

Share:

Facebook
Twitter
Pinterest
LinkedIn