Call for testers: libiberty/physmem.c

Marc Espie espie@quatramaran.ens.fr
Sun Feb 23 19:47:00 GMT 2003


In article <20030221174040.GA80208@antares.student.iastate.edu> you write:
>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/param.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);
>
>}
>
>


And it's good on OpenBSD as well (and almost certainly NetBSD)



More information about the Gcc mailing list