I want to warn the user when memory available is low. Currently I’m using sysconf(_SC_PHYS_PAGES) to get the number of physical pages available.
However, there is also memory that the OS uses as buffer and cache. How do I obtain them programmatically?
The way the free command from procps does it is by reading the
/proc/meminfofile. You can see their source here. The meminfo function updates globals, in particular kb_main_buffers and kb_main_cached. You could probably reuse their code to do what you want. (Assuming your license is compatible)