Using C to retrieve amount of free memory?

Using C to retrieve amount of free memory?

Post by Steve Weiga » Wed, 31 Jul 1996 04:00:00

I'm trying to figure out how to go about getting the amount of free
virtual (swap) memory available in the system (Sun 4 / Sun 5 / HP).
Trouble is,  I have been running around man pages like I have my
head cut off,  and I still haven't found something that looks like it
will work.  And most archie and web searches come up with NetBSD /
FreeBSD stuff,  which is entirely different than SunOS,  as I've
discovered.  I'm pretty sure doing this involves opening up the
kernel with kvm_open() or something,  but it's just a guess.

Could some kind soul please post an example of how one could ask the
system (in C for Sun4/5/HP) for how much free virtual memory is available?
I'm also interested in finding the amount of actual (physical) RAM available.

I'm pretty sure I can use vmstat / pstat and just make a kludgy
system call to those executables and parse their output,  but I'd really
like to do this without having to make system() calls like that.

Any help would be appreciated!

  - Steve Weigand