Linux htop command
htop
is an interactive process viewer and system monitor for Linux, which is often considered a more user-friendly alternative to top
. It provides a colorful, text-based, real-time view of system processes, CPU usage, memory consumption, and more. Unlike top
, htop
has a better interface for managing processes, such as the ability to kill or renice processes with just a few keystrokes.
Installation
htop
might not be installed by default, but you can install it easily using your package manager.
On Debian/Ubuntu-based systems:
On Red Hat/CentOS/Fedora-based systems:
On Arch Linux:
Basic Usage
To launch htop
, simply type:
This will open the htop
interface, which is divided into several sections:
1. Header (System Overview)
At the top of the htop
output, you’ll see an overview of your system:
- CPU Usage: Displayed as a bar graph, indicating the percentage of CPU usage for each core.
- Memory Usage: A bar graph showing the percentage of RAM being used.
- Swap Usage: A bar graph showing the percentage of swap space being used.
- Load Averages: This shows the system's load average over 1, 5, and 15 minutes.
- Uptime: The system's uptime since the last reboot.
Example:
2. Process List
The main section of htop
displays all currently running processes with the following columns:
Column | Description |
---|---|
PID | Process ID |
USER | User who owns the process |
PRI | Process priority |
NI | Nice value (affects process priority) |
VIRT | Virtual memory used by the process |
RES | Resident memory used by the process |
SHR | Shared memory used by the process |
S | Process state (e.g., S for sleeping, R for running) |
%CPU | Percentage of CPU usage by the process |
%MEM | Percentage of memory usage by the process |
TIME+ | Total CPU time consumed by the process |
COMMAND | Name of the command that started the process |
Processes are displayed in a table, with the option to sort and filter based on columns. You can interactively sort by CPU usage, memory usage, or other metrics.
Example:
3. Navigating htop
htop
is interactive and has several keyboard shortcuts that allow you to manage processes and customize the display. Some common keyboard commands include:
- F1: Show help (lists all commands).
- F2: Setup - Allows you to customize how
htop
looks (change colors, columns, etc.). - F3: Search - Search for a process by name.
- F4: Filter - Filter processes by a keyword.
- F5: Tree - View processes in a tree-like structure (shows parent-child relationships).
- F6: Sort by column - Choose a column to sort by (e.g.,
%CPU
,%MEM
). - F7: Decrease priority (renice) - Lower the process priority.
- F8: Increase priority (renice) - Increase the process priority.
- F9: Kill process - Send a signal to terminate the process.
- F10: Quit
htop
- Exit thehtop
interface.
You can also use the arrow keys to scroll through the list of processes.
4. Customizing htop
Display
You can customize htop
to display more information or change the way it looks.
- Display Columns: To add or remove columns, press
F2
to go into the "Setup" menu, then navigate to "Columns" to choose the columns you want to display. - Sorting: You can sort processes by clicking on the column header (e.g.,
CPU
,MEM
,PID
) or by using theF6
key.
5. Additional Options
You can use the following command-line options to modify how htop
behaves when starting:
htop -d <delay>
- Purpose: Set the delay between updates in milliseconds.
- Example:
This sets the update delay to 200 milliseconds.
htop -u <user>
- Purpose: Show processes for a specific user.
- Example:
This shows only the processes running for the user "john".
htop -p <pid>
- Purpose: Display information for a specific process.
- Example:
This shows information for the process with PID 3245.
htop -b
- Purpose: Start
htop
in batch mode (useful for scripting or logging). - Example:
This will run
htop
in batch mode for one iteration and output the results to the terminal.
Example Output of htop
In the above example:
- The CPU usage for the first core is at 85.5%.
- Memory usage is 4.6GB out of 8GB, with no swap used.
- The process list includes processes like
firefox
,apache2
, andvim
.
Summary
htop
is a much more interactive, colorful, and user-friendly tool than top
. It offers real-time monitoring of system resources, an easy-to-read display, and the ability to interact with and manage processes directly from the interface. It can be customized to display various system stats and supports several interactive features like sorting, filtering, and killing processes.