Gangmax Blog

htop

Here are some useful tips when using “htop”.

Question 1: Why does “htop” show more process than “ps”?

Answer:

From here.

By default, htop lists each thread of a process separately, while ps doesn’t. To turn off the display of threads, press H, or use the “Setup / Display options” menu, “Hide userland threads”. This puts the following line in your ~/.htoprc or ~/.config/htop/htoprc (you can alternatively put it there manually):

1
hide_userland_threads=1

In the first line of the htop display, there’s a line like “Tasks: 377, 842 thr, 161 kthr; 2 running”. This shows the total number of processes, userland threads, kernel threads, and threads in a runnable state. The numbers don’t change when you filter the display, but the indications “thr” and “kthr” disappear when you turn off the inclusion of user/kernel threads respectively.

When you see multiple processes that have all characteristics in common except the PID and CPU-related fields (NIce value, CPU%, TIME+, …), it’s highly likely that they’re threads in the same process.

Question 2: How to read htop output?

Answer:

From here.

The following is the detailed column meanings of htop. To get help in htop, hit the “h” key, then the UI will give you a shortcut keys map. Such as “H” to “hide/display user process threads”, “u” to “show processes of a single user” and etc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
PID – It describes the Process ID number.
USER – It describes the process owner.
PRI – It describes the process priority as viewed by the Linux kernel.
N – It describes the process priority reset by the user or root.
VIR – It describes the virtual memory that a process is consuming.
RES – It describes the physical memory that a process is consuming.
SHR – It describes the shared memory that a process is consuming.
S – It describes the current state of a process.
R: Running – Refers to the processes actively using CPU.
T/S: Traced/Stopped – Refers to the processes currently
in stopped (paused) state.
Z: Zombie or defunct – The process that has completed execution
(via the exit system call) but still has an entry in the process table.
S: Sleeping – Most common state for many processes. Generally,
processes are in the sleep state for most of the time and perform
small checks at a constant interval of time, or wait for user input
before it comes back to running state.
CPU% – It describes the percentage of CPU consumed by each process.
MEM% – It describes the percentage of Memory consumed by each process.
TIME+ – It displays the time since process execution has started.
Command – It displays the full command execution in parallel to each process.

Comments