Human-readable RSS sizes with `numfmt`
The RSS
column from ps
(or the RES
column in top) is the nearest to “physical” memory actually used by a process:
Julia Evans, aka @b0rk has a great post about how memory works under Linux.
I wanted to see it in MB
rather than the default kB
. This superuser answer shows how, using the nifty numft
. It will convert from the kilobyte size and produce a human-readable output:
ps -o rss 24652 | numfmt --header --to=iec --field 1 --from-unit=1024
In my case PID 24652
was a greedy 2.8G
, converting from the RSS
size of 2935448
.
If it had been smaller, say an RSS
of 232
then numfmt
automatically adjusts its units and reports this as 232K
.
I’m helping numfmt
know that the input size is in kB
with the --from-unit=1024
. Converting values from a different process might not need this, but be wary of decimal versus binary scales:
echo "1M" | numfmt --from=iec --to=iec
1.0M
echo "1M" | numfmt --from=si --to=iec
977K
Pádraig Brady and Assaf Gordon have a thorough look at what you can do with numfmt
.
All links, in order of mention:
- Julia Evans: https://jvns.ca/about/
- @b0rk: https://twitter.com
- how memory works under Linux: https://jvns.ca/blog/2016/12/03/how-much-memory-is-my-process-using-/
- superuser answer: https://superuser.com/a/1221281/92621
- numft: https://man7.org/linux/man-pages/man1/numfmt.1.html
- be wary of decimal versus binary scales: https://www.pixelbeat.org/docs/numfmt.html#decimal-and-binary-scales
- Pádraig Brady: https://www.pixelbeat.org/
- Assaf Gordon: https://software.housegordon.com/foss.html
- a thorough look at what you can do with numfmt: https://www.pixelbeat.org/docs/numfmt.html
Recent posts:
- Patch for aarch64 (aka arm64) openssl 1.0.2 'relocation R_AARCH64_PREL64 against symbol OPENSSL_armcap_P error'
- TIL: the `NO_COLOR` informal standard to suppress ANSI colour escape codes
- Copy the contents of a branch into an existing git branch without merging
- Adding search to a static Jekyll site using pagefind
- asdf, python and automatically enabling virtual envs