How to use the command `htop` (with examples)

How to use the command `htop` (with examples)

htop is a command-line tool that displays dynamic real-time information about running processes. It is an enhanced version of the top command and provides a more user-friendly interface for monitoring system processes. With htop, users can easily view and manage running processes in an interactive and intuitive way.

Use case 1: Start htop

Code:

htop

Motivation: Starting htop without any arguments launches the tool and displays the running processes in real-time. This use case is useful when you want to quickly monitor the processes on your system without any specific filtering or sorting.

Explanation:

  • htop - The command to start htop without any additional arguments.

Example output:

htop 3.1.1 - (C) 2004-2021 Hisham Muhammad
Please report bugs to https://github.com/htop-dev/htop
...
[Processes]
[CPU]
[Memo]
[Swap]
[User]

Use case 2: Start htop displaying processes owned by a specific user

Code:

htop --user username

Motivation: If you want to focus on the processes owned by a specific user, you can use this use case to filter and display only those processes. This can be helpful in situations where you want to monitor the resource usage of specific users or troubleshoot issues related to a particular user’s processes.

Explanation:

  • --user username - Specifies the username whose processes will be displayed.

Example output:

htop 3.1.1 - (C) 2004-2021 Hisham Muhammad
Please report bugs to https://github.com/htop-dev/htop
...
[Processes]
  PID USER        VIRT RES  CPU% MEM%   TIME+ COMMAND
24180 username    562M 26M   1.8  0.3 14:51.83 chromium-browse
...

Use case 3: Sort processes by a specified sort_item

Code:

htop --sort sort_item

Motivation: By default, htop sorts processes by CPU usage. However, you can customize the sorting criteria based on specific parameters such as memory usage, process ID, or process name. This use case allows you to sort the processes based on the sort_item argument provided.

Explanation:

  • --sort sort_item - Specifies the item by which the processes will be sorted. Use htop --sort help to view the available sorting options.

Example output:

htop 3.1.1 - (C) 2004-2021 Hisham Muhammad
Please report bugs to https://github.com/htop-dev/htop
...
[Processes]
  PID USER        VIRT RES  CPU% MEM%   TIME+ COMMAND
24180 username    562M 26M   1.8  0.3 14:51.83 chromium-browse
21234 username    345M 20M   0.9  0.2 09:23.12 firefox
...

Use case 4: Start htop with the specified delay between updates

Code:

htop --delay 50

Motivation: The delay between updates in htop determines how frequently the displayed information is refreshed. By default, the delay is set to one second. You can adjust this delay based on your preference. This use case allows you to start htop with a specific delay value.

Explanation:

  • --delay 50 - Specifies the delay between updates in tenths of a second. In this example, the delay is set to 5 seconds (50 tenths).

Example output:

htop 3.1.1 - (C) 2004-2021 Hisham Muhammad
Please report bugs to https://github.com/htop-dev/htop
...
[Processes]
[CPU]
[Memo]
[Swap]
[User]
...

Use case 5: See interactive commands while running htop

Code:

?

Motivation: When running htop, you may need information on the available interactive commands to navigate and interact with the tool effectively. This use case displays the list of commands and their associated functionality.

Explanation:

  • ? - Typing ? while inside htop displays the interactive command list.

Example output:

Interactive commands:
  ...
  ...
  Esc, h         : Hide this help screen
  ...
  ...

Use case 6: Switch to a different tab

Code:

tab

Motivation: htop provides different tabs to view various system information, including processes, CPU usage, memory usage, swap, and users. This use case allows you to switch between tabs to access different information.

Explanation:

  • tab - Typing tab while inside htop switches to the next available tab.

Example output:

htop 3.1.1 - (C) 2004-2021 Hisham Muhammad
Please report bugs to https://github.com/htop-dev/htop
...
[CPU]
  CPU[||||||||||||||||||||||||||||||||||||||||||100.0%]
  Cpu(s): 50.0%us, 25.0%sy, 25.0%ni
...

Use case 7: Display help

Code:

htop --help

Motivation: To explore the available command-line options and functionality of htop, you can use this use case to display the help information.

Explanation:

  • --help - Displays the help screen with detailed information about the command-line options and their usage.

Example output:

htop 3.1.1 - (C) 2004-2021 Hisham Muhammad
Please report bugs to https://github.com/htop-dev/htop

Usage:
  htop [options]

Options:
  ...
  ...
  -u --user USERNAME     User filter (default: all users)
  ...
  ...

Conclusion:

In this article, we explored various use cases of the htop command. We learned how to start htop without any arguments, display processes owned by a specific user, sort processes by a specified item, set a specific delay between updates, access interactive commands and switch between tabs, and how to display the help information. htop is a powerful tool for monitoring and managing running processes, providing dynamic real-time information in an intuitive and user-friendly interface.

Related Posts

How to use the command nova (with examples)

How to use the command nova (with examples)

The nova command is a part of the OpenStack project that allows users to provision compute instances.

Read More
rbenv (with examples)

rbenv (with examples)

1: Install a Ruby version rbenv install version Motivation: This command is used to install a specific Ruby version on your system.

Read More
Symfony Console Command Examples (with examples)

Symfony Console Command Examples (with examples)

Creating a new Symfony project To create a new Symfony project, you can use the symfony new command.

Read More