LabHub

Blog

Reading htop and top — How to Decode Every Number

한국어English日本語中文

Introduction — A Flood of Numbers

Open htop or top on a Linux server for the first time and you are overwhelmed by a flood of numbers and colors. Most people glance at the CPU and memory percentages and ignore the rest, but each of those numbers holds information you need to diagnose the state of the system. Prompted by Pēteris Ņikiforovs's beloved explainer "Explanation of everything you can see in htop" recently resurfacing near the top of Hacker News, this article takes those fields apart one by one.

Reading the Process Columns

Let us start with what each column in the process list means.

VIRT, RES, SHR — The Trap of the Three Memory Values

The memory columns are the most commonly misunderstood part. The three values mean completely different things.

An important practical lesson follows: when hunting for a memory-hungry process, sort by RES, not VIRT. Sort by VIRT and a process that reserved a large address space but barely uses memory floats to the top, leading you astray.

The Process State Letters

The S column shows a one-letter process state. The letters mean:

Load Average — It Is Not CPU Usage

The most widely misunderstood metric is the load average. People often think it equals "CPU usage," but it does not.

First, load average is not a simple average but an exponentially damped moving average. Three values are shown — over 1, 5, and 15 minutes — weighting recent values more heavily. The 1-minute figure is roughly 63% of the last minute's load plus 37% of what came before.

Second, and more important — load counts not only running (R) processes but also processes in uninterruptible sleep (the D state). Because of this, a high load does not necessarily mean the CPU is busy. Load spikes even when many processes are waiting on disk or network I/O.

Third, load must be interpreted against the core count. On a machine with N cores, a load of N means roughly full utilization. Load 4 on a 4-core box is saturation; load 4 on an 8-core box is only half utilized.

Combining these gives a powerful diagnostic rule: if load is high but %CPU is low, it is almost certainly I/O wait. The place to start is looking for D-state processes.

The Meter Colors

The bar meters at the top of htop convey information through color too.

The key is not to mistake buffers and cache for "used memory." Buffers and cache are regions the kernel borrows temporarily for performance, and they are returned immediately when an application needs memory. So the value to watch is not "used" but available memory. This is why a Linux screen showing "memory almost full" is usually not a problem — memory filled by cache is, in effect, free memory that can be reclaimed on demand.

What Zombie Processes Really Are

Zombie (Z) processes are often misunderstood. A few facts:

A zombie is an already-dead process. It has finished executing, but its parent has not yet reaped its exit status, so only an entry remains in the process table. Because of this, a zombie consumes no memory at all — it occupies only a single slot in the process table.

Also, a zombie cannot be killed. To terminate a process you send it a signal, and only a live process can receive a signal. Sending kill -9 to a zombie that is already dead does nothing. The only way a zombie disappears is for its parent to reap it. If the parent dies first, the zombie is adopted by init (PID 1), which reaps it instead.

So there is no need to panic over a few zombies. If zombies keep piling up, that points less to the zombies themselves being a problem than to a bug in a parent process that fails to reap its children.

Copy-on-Write and the RES Illusion

One subtle phenomenon to add. When a process creates a child with fork, Linux uses copy-on-write. Parent and child share the same physical memory pages, and a page is copied only when one of them writes to it.

Because of this, htop can show both parent and child with the full RES each. It looks like double the memory, but the physical memory is shared, so the total is not that large. Keep this illusion in mind when looking at the memory of a program that forks heavily.

Practical Diagnostic Recipes

Applying all this to real troubleshooting:

If you want to get hands-on with these tools in the browser, open this site's Linux terminal or web terminal, and to explore how kernel parameters bear on this behavior, the kernel parameter explorer.

Conclusion

The numbers in htop and top look like a cipher at first, but once you know what each field means they become a powerful diagnostic tool for reading the state of a system. In particular, understanding just three things — the difference between VIRT and RES, that load includes I/O wait, and that cache is effectively free memory — already solves half of server troubleshooting.

References

Comments

No comments yet.

Sign in to leave a comment