How to monitor memory usage of a Linux process

When you check memory usage of individual Linux processes, you may often use top command line utility. While top command is a solid program for system monitoring purposes, there are other enhanced versions of top, in terms of user-friendliness.

One such tool is called htop. The htop utility is an interactive process viewer for Linux. Similar to top, it shows resource usage of individual Linux processes in ncurses-driven text mode, but in much more user-friendly fashion.

To install htop on Ubuntu or Debian:

$ sudo apt-get install htop

To install htop on CentOS, RHEL or Fedora, first configure EPEL repository on your system, and then run the following.

$ sudo yum install htop

To run htop, simply run:

$ htop

The screenshot of htop command is shown above. At the top of the screenshot, you can see the overall resource usage of the system: CPU usage (labeled "1" for the first CPU, "2" for the second CPU, etc.), memory usage and swap space usage. The rest information is similar to the output of top utility.

If you want to sort processes by memory usage, press <F6>, and choose "MEM%".

With htop command, you can check a complete list of processes as opposed to top-N processes, by scrolling up/down the list. You can also scroll horizontally to see complete command line information of individual processes.

By toggling <F5>, you can enable or disable process tree views as shown below.

Besides keyboard, htop responds to mouse clicks as well. This is convenient when you nice or kill specific processes.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *