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

Comments