Re: Querying Kernel about RAM
From: Devlin Doe (devlin_at__NIXPIX_piratefish.net)
Date: 09/29/04
- Next message: David Schwartz: "Re: i thought RAID 5 had a stake through its heart"
- Previous message: Jose Maria Lopez Hernandez: "Re: customized ip stack over ethernet"
- In reply to: James Dabbs: "Querying Kernel about RAM"
- Next in thread: Kasper Dupont: "Re: Querying Kernel about RAM"
- Reply: Kasper Dupont: "Re: Querying Kernel about RAM"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 29 Sep 2004 22:34:14 +0200
On Tue, 28 Sep 2004 18:42:25 +0200, James Dabbs wrote:
> Is there a way for a utility application to query the kernel regarding
> the amount of physical ram in the box as well as the amount of RAM that
> is recognized by the kernel?
>
> For instance, if I have a machine with 1G and I pass a mem=512K param to
> the kernel, I'd like a way for my application to figure out what is
> going on.
>
As previous posters have said there are several methods of getting the
memory size:
* cat /proc/meminfo
- Highly linux dependant, including kernel version
* sysinfo()
- Never used it but it seems to give the same info as /proc/meminfo
* sysconf(_SC_PAGESIZE)*sysconf(_SC_PHYS_PAGES)
- The portable way.
See example code below for test usage, I have no idea how the linux
mem parameter is handled..
Regards
Devlin
---8<----8<-----chop-with-scissors----
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/sysinfo.h>
int main(){
struct sysinfo si;
long page_size, num_pages;
page_size = sysconf(_SC_PAGESIZE);
num_pages = sysconf(_SC_PHYS_PAGES);
printf("sysconf: Total ram %ld MB\n", (page_size*num_pages)/(1024*1024));
memset(&si, 0, sizeof(sysinfo));
if ( sysinfo(&si) == 0 ){
printf("sysinfo: Total ram %ld MB\n", si.totalram/(1024*1024));
}
return 0;
}
--->8---->8-----end-chop
- Next message: David Schwartz: "Re: i thought RAID 5 had a stake through its heart"
- Previous message: Jose Maria Lopez Hernandez: "Re: customized ip stack over ethernet"
- In reply to: James Dabbs: "Querying Kernel about RAM"
- Next in thread: Kasper Dupont: "Re: Querying Kernel about RAM"
- Reply: Kasper Dupont: "Re: Querying Kernel about RAM"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|