christophe barbe on Wed, 6 Nov 2002 19:54:18 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] BSD total free memory in C ?


On Wed, Nov 06, 2002 at 09:43:20AM -0500, gabriel rosenkoetter wrote:
> On Wed, Nov 06, 2002 at 08:35:34AM -0500, christophe barbe wrote:
> > To get the total (including free swap) free memory I read /proc/meminfo. 
> > I have no knowledge of BSD but IIRC there is no proc filesystem. 
> 
> Say what?
> grappa:~% uname -a
> NetBSD grappa 1.6F NetBSD 1.6F (GRAPPA) #8: Thu Aug 15 00:54:54 EDT 2002     gr@grappa:/mp3/tmp/netbsd/src/sys/arch/i386/compile/GRAPPA i386
> grappa:~% ls -ld /proc /kern
> dr-xr-xr-x  2 root  wheel  512 Nov  6 09:33 /kern/
> dr-xr-xr-x  1 root  wheel  512 Nov  6 09:33 /proc/
> 
> Long, long ago, BSD systems didn't have /proc because it was a SysV
> thing. But since it's been part of both POSIX and SuS standards for
> quite a while now, any modern BSD system has it.
> 
> Note that Linux *way* overloads /proc, keeping *far* more than what
> belongs there there. (The only thing that belongs there is information
> about processes... things like meminfo, cpuinfo, modules, pci,
> iomem, et cetera just don't fit logically.)

Note that it was just ignorance not arogance. Even in linux, the /proc
fs is slightly deprecated. Linus prefers that each driver implement its
own filesystem if really needed. That said I guess you will not find
that better.

> > What would be the BSD way to get the quantity of free memory?
> 
> The closest you can get to /proc/meminfo on a (Net)BSD system is
> /kern/physmem, but it's not what you want.
> 
> You really want to be doing the same thing that top(whatever,
> probably 1) and vmstat(8) do, though, which is groveling through
> /dev/[k]mem. Check their sources for the details.

Thanks, I will have a look.
 
> Or, if you're lazy, just shell out a call to vmstat(8), I suppose,
> with the appropriate flags.

No, I prefer avoid that kind of solution.

Christophe

> -- 
> gabriel rosenkoetter
> gr@eclipsed.net



-- 
Christophe Barbé <christophe.barbe@ufies.org>
GnuPG FingerPrint: E0F6 FADF 2A5C F072 6AF8  F67A 8F45 2F1E D72C B41E

There is no snooze button on a cat who wants breakfast.
_________________________________________________________________________
Philadelphia Linux Users Group        --       http://www.phillylinux.org
Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce
General Discussion  --   http://lists.netisland.net/mailman/listinfo/plug