brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: top -o mem lists the Mac processes with the biggest memory footprint

Memory
~/tips/tip-macos-top-sorted-by-memory

top -o mem -n 10

Shows the processes with the biggest memory footprint first, in a fixed-size list.

When I suspect memory, I want top to sort by it from the first screen, and not hunt for the right column later.

The -o option picks the key to sort by, in descending order. The man page describes mem as the physical memory footprint of the process:

top -o mem -n 10

-n limits the list to ten processes. A + in front of the key sorts ascending and a - sorts descending. Other keys include cpu, pid, time, rprvt (resident private size) and vsize (total memory size). Press q to quit.

If you only want a few columns, -stats takes the same key names:

top -o mem -n 10 -stats pid,command,mem

Inside a running top you can change the sort without restarting: type o, then the key name, and press Return. The summary at the top has a PhysMem line with wired, active, inactive, used and free memory, and -S adds global statistics for swap and purgeable memory.

The caveat is logging mode. With -l you get a fixed number of samples as plain text, which suits a script. The manual warns that the first sample shows an invalid %CPU for every process, because CPU is calculated from the difference with the previous sample. So top -l 1 -o mem -n 10 works for the memory columns and is useless for CPU. For a closer look at what one process is made of, the man pages for vm_stat and footprint are the places I would go next.

Further reading: top man page

More Memory tips lsmem --summary for f in /proc/[0-9]*/status; do sudo apt install smem sudo pmap -x 1234 sudo systemctl edit indexer.service All Memory tips (12) All topics

Link