The top command has been one of my favourites ever since I started working on Linux. But, recently I stumbled upon its big brother — htop. I used it for sometime and found that it offers some very interesting options. In this article, lets discuss some of these interesting and useful options, its strengths and areas where it falls short of expectations.
NOTE – All the examples presented in this article have been tested on bash shell in Ubuntu 13.04.
HTOP – Interactive Process Monitoring Tool
As written clearly on the man page, htop is similar to top but allows you to interactively monitor processes in real-time. For example, you can easily filter results based on user accounts, kill (or send any other signal to) a process from within the utility etc.
A Brief Tutorial
Just like top, htop can be executed by typing the name itself – htop. Once executed, the main window looks like :
So you can see that the whole window is divided into three sections :
- Top left section – This section contains information related to CPU and memory usage. The numbers 1 & 2 represents the number of cores and the coloured bars represent the amount of load on these cores. Similarly memory and swap rows provide information on their respective usage.
- Top right section – This section contains information related to load average, number of tasks, uptime etc.
- Bottom half section – This section provides a dynamic view of processes in Linux. Information like CPU usage, priority, memory consumption etc.
Regarding the bar colours, I searched and found the following information on ServerFault :
If you want to to understand the colour scheme yourself, you can take a look at the htop source code.
Now, lets discuss some features of htop utility.
1. View details of only selected PIDs
The htop tool provides an option (–pid) through which you can view details related to only selected process IDs. The syntax is htop –pid=pid1,pid2,…
Here is an example snapshot when –pid option was used with pids 1 and 2670 :
So you can see that process details of only selected processes were displayed in the output.
2. View details of processes owned by a particular user
You can use the -u[user-name] option to filter and display process details of only those processes which are owned by a user with account name as [user-name].
Here is an example snapshot when htop was run with -uhimanshu option :
So you can see that only the processes owned by the user himanshu were displayed in the output.
3. Tag selected processes
You can select individual processes by scrolling down (using up and down arrow keys) to a process details row and pressing space key. The row will turn yellow in colour. Here is an example :
So you can see that I have selected multiple processes. This is extremely useful when you want to continuously keep track of one or more selected processes.
4. Send Signals
Now, suppose you want to send a signal to a process. So, all you need to do is to first select the process and then press the key F9. Once done, the following details will emerge on the screen :
Observe that the left row now contains all type of signals. You can select a signal and press enter to send it to the selected process in the right side.
5. Keep track of opened files for a process
You can select a process and press the l key to keep track of all the files opened for the selected process.
Here is an example snapshot of the files that were opened for process compiz :
So you can see that all the files opened for the selected process were listed in the output.
6. Search for a particular process
You can easily search for a particular process by pressing F3 key. It brings up a prompt at the bottom of the window. You can write the process name or the search keyword and the matching process will be displayed as the last process in the window and that too in a different background colour.
Here is an example :
So you can see that the search keyword used in the example was bash and the corresponding process was displayed just above the search prompt.
7. Display processes as parent-child in a tree structure
If you want to display the processes in form of a tree structure then press F5 key. All the processes will be displayed as parent-child in tree structure.
Here is an example :
So you can see that all the processes were displayed in parent-child like tree structure.
8. Configure settings
What more? You can even configure the output display settings of the htop utility by pressing F2 key.
Here are the available settings options :
So you can see that a variety of customization options are available for almost every type of information that you see in the output.
These were just few features that should give you a good idea about the capabilities of the htop command. For more features and options, visit the man page of this utility.
Here are some of the important links related to htop :
You can use apt-get and yum tools to download htop through command line. Ubuntu users can also download htop utility from Ubuntu Software Centre. The version used for this review was 1.0.2.
- Adds many useful and interesting features
- Supports coloured output display
- The display format of process details remains same as that of traditional top command.
- Lack of choices in colour templates
Htop is a useful utility. It brings some real improvement over the good old top command that we have been using for years. If you love top then I am sure that you will love htop even more. Give it a try, you will not be disappointed.