Linux command of the day, 7 of 31 - top

By Gavin Davies on 6 August 2020

Page image
I’m looking briefly at a Linux command every day for a month. Today: top

I’m looking briefly at a Linux command every day for a month. Today: top. This isn’t intended to be a tutorial, just some brief notes for fun

top is a command I’ve used thousands of times but I’ve never really gotten the most out of it. The densely packed jumble of numbers at the top of the screen has always intimidated me just a little bit so I’ve tended to use it as a jump off point for more narrowly purposed tools.

However, in writing this I tried to capture the top output but it kept updating and unselecting in my console, so I piped it into head, and hey presto, a comprehensible, legible output!

$ top | head -n15
Processes: 493 total, 2 running, 491 sleeping, 2646 threads
2020/08/07 07:06:46
Load Avg: 3.35, 3.67, 4.13
CPU usage: 8.57% user, 10.80% sys, 80.61% idle
SharedLibs: 272M resident, 58M data, 19M linkedit.
MemRegions: 244034 total, 9717M resident, 161M private, 5767M shared.
PhysMem: 31G used (4360M wired), 1009M unused.
VM: 3245G vsize, 1998M framework vsize, 6491365(0) swapins, 7114909(0) swapouts.
Networks: packets: 10734821/8204M in, 12389981/2626M out.
Disks: 6435136/123G read, 35004853/266G written.

oh man, that’s so much less dense!

Here I can see how many processes/threads are running on my Mac, and the datestamp.

The load average numbers are apparently calculted from the number of running and waiting threads. The load averages are shown over 1, 3 and 15 minutes.

So, in my example, over the last minute my load averaged 3.35 but over the last 15 it averaged 4.13, which suggests the load has decreased a bit.

This mac has a 6 core i9 CPU, so I can say that a load average of 3 is very approximately 50% utilisation.

Bridge metaphor

This webpage has a great illustration of load averages.

Imagine a CPU is a bridge. For a single CPU system, a load of 1 is a bridge that has cars flowing across at capacity with no cars waiting.

A load greater than 1 implies there are cars waiting to get on the bridge - a traffic jam. Unix systems call this the run-queue length - procs running + procs queued.

Interpreting load averages

They show things like:

  1. Is load going up or down in the last 5 or 15 minutes?
  2. If you’ve got load ~0 your system is idle
  3. If your load is greater than your number of CPU cores, you have waiting. If you had load of 5.0 on a single core system, you’ve got massive problems.
  4. If load >~0.7 (assuming a single CPU) you have potential problems as you don’t have much headroom left


I didn’t do a post yesterday but uptime tells you load averages without all the extra stuff top bombards you with, so that’ll do for yesterday!

The rest of top…

top is so big, I think that’s enough for today!