Sorting Processes in htop
The ability to sort processes based on different criteria is one of the most useful features of htop
. In this step, we'll learn various ways to sort processes to easily identify resource-intensive applications or locate specific processes.
Sorting Methods in htop
Launch htop
again:
htop
The simplest way to sort processes is by using the dedicated sort menu:
-
Press F6
while in htop
. This opens the sort menu.
-
You'll see a list of columns you can sort by:
- PID
- USER
- PRIORITY
- NICE
- M_SIZE (Memory size)
- M_RESIDENT (Resident memory)
- M_SHARE (Shared memory)
- STATE
- PERCENT_CPU
- PERCENT_MEM
- TIME
- COMM (Command)
-
Use the arrow keys to select a column, then press Enter
to sort by that column.
For example, to sort by CPU usage:
- Press
F6
- Select
PERCENT_CPU
using arrow keys
- Press
Enter
Now the processes are sorted by CPU usage, with the highest CPU-consuming processes at the top.
Direct Sorting Shortcuts
htop
also provides direct keyboard shortcuts for common sorting options:
- Press
P
to sort by CPU usage (Processor)
- Press
M
to sort by memory usage
- Press
T
to sort by time (cumulative CPU time)
- Press
N
to sort by process ID
Try each of these shortcuts now to see how the process list changes.
For example, press M
to sort by memory usage. Notice how the processes are now arranged with the most memory-intensive ones at the top.
Reversing Sort Order
You can reverse the current sort order by pressing I
(capital i). This toggles between ascending and descending order.
Try sorting by CPU usage with P
, then press I
to reverse the order. The processes with the lowest CPU usage will now appear at the top.
Column Highlighting
When you sort by a specific column, that column gets highlighted to indicate it's the current sort key. This makes it easy to remember which criterion you're currently using to sort the processes.
Try different sorting methods and observe how the highlighted column changes to reflect your selection.
Practical Example: Finding Memory-Intensive Processes
Let's practice with a specific scenario. Suppose you want to identify which processes are consuming the most memory:
- Press
M
to sort by memory usage
- The processes are now ordered by memory consumption (highest to lowest)
- The top processes in the list are your system's most memory-intensive applications
This sorting method is extremely useful when troubleshooting memory issues or identifying memory leaks.
When you're done exploring, exit htop
by pressing q
.