How to Sort by PID in htop Linux?
The htop command-line utility is a powerful, interactive
process manager for Linux that allows users to monitor system resources
and manage running processes in real time. While htop
defaults to sorting processes by CPU usage, you can easily change this
behavior to organize the list by Process ID (PID) number instead. This
article provides a quick, step-by-step guide on how to sort your process
list by PID using both keyboard shortcuts and the interactive setup
menu.
Sorting by PID Using Keyboard Shortcuts
The quickest way to change the sorting order in htop is
by utilizing built-in keyboard shortcuts. This allows you to reorder the
process list instantly without navigating away from the main screen.
- Open the Sort Menu: Press
F6(orOon some keyboard layouts) whilehtopis running. This opens a sidebar menu on the left side of the terminal listing all available column criteria. - Select PID: Use the arrow keys to scroll up or down
the list until
PIDis highlighted. - Confirm: Press
Enter. The process list will immediately rearrange itself in ascending order based on the Process ID numbers.
Sorting by PID Using the Setup Menu
If you prefer a more permanent configuration or want to adjust how columns are displayed, you can use the main setup interface.
- Enter Setup: Press
F2(orS) to open the configuration screen. - Navigate to Display Options: Use the arrow keys to
select
Display optionsfrom the Setup column. - Adjust Sorting: Move over to the right-hand columns
to find the default sort direction settings. You can combine this with
the
F6menu to ensurehtopbehaves exactly as needed for your troubleshooting workflow.
Quick Alternative: The Interactive Clicking Method
If your terminal emulator supports mouse interactions and you have
mouse tracking enabled in htop, you can simply click
directly on the column headers. Clicking the
PID column header at the top of the
process list will automatically sort the table by that column. Clicking
it a second time will reverse the sort order between ascending and
descending.