Introduction
The htop utility is an enhanced version of the traditional top command in Linux systems. It provides a user-friendly, interactive interface for monitoring system resources and managing processes in real-time. This tutorial will guide you through using htop with a focus on sorting processes by different criteria, such as CPU usage, memory consumption, and process IDs.
By learning to effectively sort processes in htop, you will be able to:
- Quickly identify resource-intensive applications
- Monitor system performance more efficiently
- Locate specific processes when troubleshooting
- Better manage your system resources
Installing and Launching htop
In this first step, we will install the htop utility on your Ubuntu system and launch it for the first time.
Installing htop
Before we can use htop, we need to install it. Open your terminal and execute the following commands:
sudo apt update
sudo apt install htop -y
The first command updates your package lists, and the second command installs the htop package. The -y flag automatically confirms the installation.
You should see output similar to the following:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
htop
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 132 kB of archives.
After this operation, 301 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 htop amd64 3.0.5-7build2 [132 kB]
Fetched 132 kB in 1s (132 kB/s)
Selecting previously unselected package htop.
(Reading database ...
Unpacking htop (3.0.5-7build2) ...
Setting up htop (3.0.5-7build2) ...
Processing triggers for man-db (2.10.2-1) ...
Launching htop
Now that htop is installed, you can launch it by simply typing the following command in your terminal:
htop
You should see an interactive display showing:
- A header with CPU, memory, and swap usage bars
- A process list showing running processes on your system
- A footer with keyboard shortcuts

Take a moment to observe the interface. The process list typically includes columns for:
- PID (Process ID)
- USER (Process owner)
- PRI (Priority)
- NI (Nice value)
- VIRT (Virtual memory)
- RES (Resident memory)
- SHR (Shared memory)
- S (Status)
- CPU% (CPU usage percentage)
- MEM% (Memory usage percentage)
- TIME+ (CPU time)
- Command (Process name/command)
To exit htop when you're done exploring, press the q key on your keyboard.
Navigating the htop Interface
Now that you have installed and launched htop, let's explore its interface and learn how to navigate through it.
Basic Navigation in htop
Launch htop again by typing:
htop
Using Arrow Keys
In the htop interface:
- Use the
UpandDownarrow keys to move the selection cursor through the process list - Use the
LeftandRightarrow keys to scroll horizontally if the process list is wider than your screen
Try using these arrow keys now to navigate through the process list.
Scrolling Through Pages
If you have many processes running, you can use:
Page UpandPage Downkeys to scroll through pages of processesHomekey to jump to the first processEndkey to jump to the last process
Understanding the Display
Take a moment to understand the main components of the htop display:
Header: Shows system-wide information
- CPU usage bars (one for each CPU core)
- Memory usage bar
- Swap usage bar
- Uptime (how long the system has been running)
- Load average (system load over the last 1, 5, and 15 minutes)
Process List: Shows detailed information about each process
- Each column represents a different attribute of the processes
- The currently selected process is highlighted
Footer: Shows available keyboard shortcuts
- Function keys (F1-F10) for common actions
- These shortcuts are essential for using
htopeffectively
Let's test some basic navigation. Try locating the htop process itself in the list. It should be visible among the running processes. Use the arrow keys to scroll until you find it.
To get help within htop, press the F1 key or h. This opens the help screen with a complete list of keyboard shortcuts.
To exit the help screen, press the Escape key or q.
When you're done exploring, exit htop by pressing q.
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
Using the Sort Menu
The simplest way to sort processes is by using the dedicated sort menu:
Press
F6while inhtop. 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
Enterto sort by that column.
For example, to sort by CPU usage:
- Press
F6 - Select
PERCENT_CPUusing 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
Pto sort by CPU usage (Processor) - Press
Mto sort by memory usage - Press
Tto sort by time (cumulative CPU time) - Press
Nto 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
Mto 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.
Managing Processes Based on Sorted Information
After learning how to sort processes in htop, let's explore how to use this sorted information to manage processes effectively.
Process Management Actions in htop
Launch htop once more:
htop
Selecting and Managing Processes
Once you've sorted the processes and identified ones of interest, you can perform various actions on them:
- Select a process: Navigate to it using the arrow keys
- View process details: Press
F2to customize the view orspaceto tag a process for batch operations - Kill a process: Press
F9to send a signal to a process (such as terminating it) - Change process priority: Press
F7to decrease priority (higher nice value) orF8to increase priority (lower nice value)
Let's practice these actions:
Sorting and Examining Resource-Intensive Processes
- Press
Pto sort by CPU usage - Navigate to one of the top CPU-consuming processes using arrow keys
- Press
F9to open the "Send signal" menu- Note that we won't actually send a kill signal; this is just for demonstration
- Press
Escto cancel the operation
You can see how easy it is to identify and manage high-resource processes with the sorting feature.
Changing Process Priority
After sorting processes, you might want to adjust the priority of certain resource-intensive processes:
- Press
Mto sort by memory usage - Navigate to a process with high memory usage
- Press
F8to open the priority adjustment menu- This would allow you to increase the priority
- Press
Escto cancel without making changes
Sorting by User
You can also sort processes by user, which is useful in multi-user environments:
- Press
F6to open the sort menu - Select
USERand pressEnter - The processes are now grouped by user, making it easy to see which users are running which processes
Tree View with Sorting
htop provides a tree view that shows the parent-child relationships between processes:
Press
F5to toggle tree viewNotice how processes are organized hierarchically
You can still use sorting while in tree view
- Press
Pto sort by CPU usage - The processes still maintain their hierarchical relationships while being sorted
- Press
Press
F5again to go back to the flat view
Filtering Processes
You can combine sorting with filtering to narrow down the process list:
Press
F4to activate the filterType a search term (e.g.,
bash)Press
Enterto apply the filterNow you can sort these filtered results using any sorting method
- Press
Pto sort filtered processes by CPU usage - Press
Mto sort filtered processes by memory usage
- Press
To clear the filter, press
F4again and thenEsc
Using Sorted Information for System Monitoring
Sorting in htop is particularly useful for ongoing system monitoring:
- Press
Pto sort by CPU usage - Leave
htoprunning in a terminal - Periodically check which processes are at the top to monitor system performance
- If you notice unusual resource usage patterns, you can investigate further
When you're done exploring, exit htop by pressing q.
Summary
In this tutorial, you have learned how to use the powerful htop utility to monitor and manage processes in Linux. You have gained practical skills in:
- Installing and launching
htopon Ubuntu - Navigating the
htopinterface and understanding its key components - Sorting processes using various criteria such as CPU usage, memory consumption, and process ID
- Using keyboard shortcuts for efficient process sorting
- Managing processes based on sorted information
- Using advanced features like process filtering and tree view
These skills will allow you to effectively monitor your system's performance, quickly identify resource-intensive processes, and make informed decisions about process management. Whether you are troubleshooting performance issues, optimizing system resources, or simply keeping an eye on your system, the sorting capabilities in htop provide a valuable toolset for system administrators and Linux users of all levels.
Remember that regular monitoring of your system processes can help you maintain optimal performance and identify potential issues before they become critical problems.



