> My question is then...
>
> How do I write a program that will ask the kernel how much free
> physical memory there is available to me without causing a lot of
> swapping?
How about checking the source code of vmstat? It's not setuid, so
whatever it's doing, you can do too.