Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_linux_programming thread: obtain amount of system memory in C


Message #1 by millward@m... on Sat, 8 Mar 2003 03:42:17
All the 'free' command is doing is reading the file /proc/meminfo
so you could simply read that directly in your program, it looks easy enough to parse.
Just type 'cat /proc/meminfo' and have a look.

Alternatively grab the source code for 'free' and have a look how it does the job.
It is in the procps package.

I used the UK mirror service, but you could go direct to RedHat:

http://www.mirror.ac.uk/sites/ftp.redhat.com/pub/redhat/linux/8.0/en/os/i386/SRPMS/[page=4]

then download procps-2.0.7-25.src.rpm, install it (rpm -i procps-2.0.7-25.src.rpm)
which puts files into /usr/src/redhat/SOURCES/ so cd to there.

then unzip/untar the file:
tar zxvf procps-2.0.7.tar.gz
and the file you want is procps-2.0.7/free.c

Rick


-- 
Rick Stones mailto:rick@s... 
http://www.stixen.co.uk http://www.docbox.co.uk FAX +44(0)8700510557

-----Original Message-----
From: millward@m... [mailto:millward@m...]
Sent: 08 March 2003 03:42
To: Pro Linux Programming
Subject: [pro_linux_programming] obtain amount of system memory in C


 How would you get a C program to find 
out the amount of free system memory? 
I can do this eay using the command line 
free and I suppose in a C program I could 
do something like  system("free") but that 
doesn't tell the program itself anything. 
I have to put the amount into a numeric 
variable so it can be compared. Is there 
an easy way to do this? 

  Return to Index