|
How to accurately determine memory (RAM) information
I'm writing a shell script to display as much useful information on physical and virtual memory availability and usage as possible. I need a CLI tool to print these numbers for me.
The utilities that I know to give out some statistics are the following:
free
top
vmstat
sysctl
In Linux there's also /proc/meminfo
I'm however using OpenBSD which doesn't by default utilize /proc, and I want the script to apply in as many different environments as possible, relying on the most common basic utilities. The command "free" isn't installed on OpenBSD out-of-the-box, so I've excluded that. sysctl seems the best bet at the moment, aside from the fact that I have to do some wildcarding/conditionals for my script to apply to both Linux and BSD kernels (for example in Linux the first level key for some parameters is "kernel" whereas in OpenBSD it's "kern").
sysctl also displays the amount of physical memory wrong:
hw.physmem=469037056
hw.usermem=467742720
I have 512MB of RAM on that machine. What's up with that? I've also seen it reported by some users that sysctl incorrectly displays the machine to have 2147483648 bytes of physical memory, even when the actual amount by far exceeds this. I'm not sure if this was a Mac-related or a universal issue.
Where does /proc/meminfo fetch its content from? What about free, top, vmstat? Surely there's some cross-referencing somewhere?
Lower the level, the better, as long as it's reachable by scripting.
|