How to View Process Trees in htop?
The htop command-line utility provides an interactive,
real-time monitoring system for Linux processes, offering a cleaner
interface than the traditional top command. One of its most
powerful features is the ability to display processes in a tree view
hierarchy, which visually groups child processes under their parent
processes. This hierarchical view makes it significantly easier to trace
the origin of a process, understand application dependencies, and
identify which master process spawned a series of resource-heavy
sub-tasks. Navigating this view can be done instantly through a simple
keyboard shortcut or by adjusting the permanent display settings within
the tool.
Enabling Tree View Instantly
When you have htop running in your terminal, the fastest
way to switch from the standard flat list to a hierarchical tree view is
by using a single keyboard shortcut.
- The F5 Key: Pressing
F5on your keyboard immediately toggles the tree view on and off. - The t Key: Alternatively, if your terminal
environment intercepts the function keys, you can press the lowercase
tkey to achieve the exact same result.
Once activated, you will see visual lines connecting parent processes to their children, and the process names will be indented to reflect their depth in the system architecture.
Configuring Tree View as the Default
If you prefer htop to always launch in tree view without
needing to press a shortcut every time, you can save this preference in
the configuration menu.
- Launch
htopin your terminal. - Press
F2(orS) to enter the Setup menu. - Use the arrow keys to navigate to the Display options column.
- Move down the list and highlight the option labeled Tree view.
- Press the Spacebar to check the box and enable it.
- Press
F10(orEsc) to save your changes and return to the main monitoring screen.
Navigating and Managing the Process Tree
Once the tree view is active, htop provides additional
functionality to manage how the hierarchy is displayed and interacted
with:
- Collapsing and Expanding Trees: You can collapse a specific parent process to hide all of its children by pressing the Minus (-) key. To expand it back out and view the sub-processes again, press the Plus (+) key.
- Sorting within Tree View: By default,
htopsorts the tree view by the Parent Process ID (PPID). If you want to sort the trees based on resource consumption while maintaining the hierarchy, you can pressF6and select a metric like CPU% or MEM%. This will sort the parent processes relative to each other based on that metric, keeping their respective child processes nested beneath them.