physical memory
Nikola Vladov <[email protected]>
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <[email protected]> |
How can one find the physical memory of the system?
Recent xz utility <http://tukaani.org/xz/xz-4.999.8beta.tar.gz>
uses sysconf in src/common/physmem.h
May it's possible with getrlimit, setrlimit.
I don't know how glibc make this.
The next file shows that sysconf does not work in dietlibc.
The source of sysconf.c is obvious also :-)
Nikola
-------------------------------------------
#include <sys/param.h>
#include <sys/sysctl.h>
#include <unistd.h>
#include <stdio.h>
/*
gcc -s -Wall -W phm.c; ./a.out > phm_defs.h
diet -Os gcc -s -Wall -W phm.c; ./a.out
Since this is a test file I used printf :(
*/
#ifdef __dietlibc__
#include "phm_defs.h"
#endif
int main() {
const long pagesize = sysconf(_SC_PAGESIZE);
const long pages = sysconf(_SC_PHYS_PAGES);
#ifndef __dietlibc__
printf("#ifndef _SC_PAGESIZE\n");
printf("#define _SC_PAGESIZE %d\n", _SC_PAGESIZE);
printf("#endif\n");
printf("#ifndef _SC_PHYS_PAGES\n");
printf("#define _SC_PHYS_PAGES %d\n", _SC_PHYS_PAGES);
printf("#endif\n\n");
#endif
printf("/* pagesize=%ld pages=%ld */\n", pagesize, pages);
return 0;
}