Americas

  • United States
sandra_henrystocker
Unix Dweeb

Using htop to check performance on Linux

How-To
Jun 09, 20224 mins
Linux

Spend some time checking out the htop tool for viewing processes and system performance and you might just find it extremely handy when you need it.

Spinning top on a wooden floor.
Credit: Canonmark / Getty Images

While it’s one of the best tools for examining performance on Linux, htop still requires some explanation before you’ll be ready to take advantage of all the data it displays. It’s an excellent tool, but you need to understand the coloring scheme, how to scroll up and down through the processes displayed, and how to change your view of what’s happening on the system.

It may take some time to get used to the type of information shown and be ready to quickly notice performance problems. That, of course, means that you have to know what normal behavior looks like on your system, and this generally requires spending time with the tool on a relatively frequent basis. In other words, use htop when you’re not at all concerned about how your system is performing and you’ll likely be able to make good use of it when you are.

You can start htop in a terminal window or after logging in from another system using a tool like PuTTY.

The htop display should look something like this:

image1 Sandra Henry-Stocker

Stretch out the window and you’ll be able to see more details on more processes.

The top left shows the number of CPUs/cores on the system and how busy they are. The colors are important, too. The green bars represent user processes, while red bars represent kernel processes. You may see other colors as well. The colors represent:

  • Green – user processes
  • Red – kernel processes
  • Blue – low priority (nice) processes
  • Turquoise – virtualized processes

If you ask for help by pressing F1, you’ll see an explanation of the colors along with other information.

image2 Sandra Henry-Stocker

Next comes memory and swap usage. Notice in the screenshot above that memory is being significantly used, but swap isn’t being used at all. Clearly this system is not very busy since it doesn’t have to swap process data out of memory.

The upper right of the display shows you the number of tasks, threads (thr) and kernel threads (kthr). It also shows how many processes are currently running (using the CPU). In this case, there are 2.

image3 Sandra Henry-Stocker

This portion of the display also shows load averages and uptime. The load averages show how heavily loaded the system has been over the last 1, 5 and 15 minutes. Uptime shows how long the system has been up in hours, minutes and seconds along with days if it’s been up more than a day (e.g., Uptime: 1 day, 20:18:15).

The larger portion of the display shows the processes, organized by PID by default. You can scroll up and down to see additional processes using the up and down arrows on your keyboard.

image4 Sandra Henry-Stocker

The fields displayed include this information for each process:

  • PID – the process ID
  • USER – the individual running the process
  • PRI – process priority
  • NI – the “nice” setting (priority reset by user)
  • VIRT – virtual memory used
  • RES – physical memory used
  • SHR – shared memory used
  • S – the current process state
  • CPU% – the percentage of CPU used
  • MEM% – the percentage of memory used
  • TIME+ – the time the process has used since it started, measured in hundredths of a second (e.g., 2:34.56 means 2 minutes, 34 seconds and 56 hundredths of a second)
  • Command – the command being run

To sort the display by CPU usage, press the F6 key and select select PERCENT_CPU. Then hit the enter key to get back to viewing the processes using the new sort order. As you can see, a number of sorting options are available.

image5 Sandra Henry-Stocker

When you start htop up again, it will start using whatever sort order you last used.

Quit htop by typing “q” or by using the F10 key.

Wrap-up

The htop tool provides a lot of important information on running processes and can be very useful when looking for problems that might slow down the system. Getting comfortable with using it can help you detect problems easily and quickly or verify that system performance is good.

sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.