Call for testers: libiberty/physmem.c
Krzysztof Parzyszek
kparz@iastate.edu
Fri Feb 21 17:45:00 GMT 2003
On Fri, Feb 21, 2003 at 12:00:15PM -0500, Kaveh R. Ghazi wrote:
> > From: Krzysztof Parzyszek <kparz@iastate.edu>
> >
> > On FreeBSD 4.8-PRERELEASE it doesn't work (prints zeros). FreeBSD
> > doesn't provide physical memory information via sysconf, you can use
> > sysctl instead.
> > Krzysztof
>
> How exactly? Thanks.
Here is a sample code that works on FreeBSD-STABLE. The values returned
by sysctl are said to be in bytes and so I don't know what happens when
you have >= 2G of available memory.
If you want to check out manual pages for sysctl(3) for various *BSD
systems, you can find them on http://www.freebsd.org/docs.html#man
Krzysztof
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
int main() {
int mib[2];
int physmem, usermem, pagesize;
size_t len;
mib[0] = CTL_HW;
mib[1] = HW_PHYSMEM;
len = sizeof(int);
if (sysctl(mib, 2, &physmem, &len, NULL, 0) != 0) perror("sysctl");
mib[1] = HW_USERMEM;
len = sizeof(int);
if (sysctl(mib, 2, &usermem, &len, NULL, 0) != 0) perror("sysctl");
mib[1] = HW_PAGESIZE;
len = sizeof(int);
if (sysctl(mib, 2, &pagesize, &len, NULL, 0) != 0) perror("sysctl");
printf("physmem = %d bytes\nusermem = %d bytes\npagesize = %d bytes\n",
physmem, usermem, pagesize);
}
More information about the Gcc
mailing list