I have tried like this but I don't want to use shell command through popen() system call
/*
* File: memoryInfo.cpp
* Author: root
*
* Created on 24 June, 2009, 6:32 AM
*/
#include <iostream>
using namespace std;
class MemoryInfo {
private:
char line[256];
public:
int GetFreeRamInKB(void);
int GetRamInKB(void);
void Display(int i);
int DiskSpace();
int TotalSizeofDisk();
};
int MemoryInfo::GetFreeRamInKB()
{
FILE *meminfo = fopen("/proc/meminfo", "r");
if(meminfo == NULL) printf("file opening error:");
// handle error
while(fgets(line, sizeof(line), meminfo))
{
int ram;
//if(sscanf(line, "MemTotal: %d kB", &ram) == 1)
if(sscanf(line, "MemFree: %d kB", &ram) == 1)
{
fclose(meminfo);
return ram;
}
}
fclose(meminfo);
return -1;
}
int MemoryInfo::GetRamInKB()
{
FILE *meminfo = fopen("/proc/meminfo", "r");
if(meminfo == NULL) printf("file opening error:");
// handle error
while(fgets(line, sizeof(line), meminfo))
{
int ram;
//if(sscanf(line, "MemTotal: %d kB", &ram) == 1)
if(sscanf(line, "MemTotal: %d kB", &ram) == 1)
{
fclose(meminfo);
return ram;
}
}
fclose(meminfo);
return -1;
}
void MemoryInfo:

isplay(int i)
{
cout << i << " KB" << endl;
}
int main() {
MemoryInfo RAM,HDD;
int freesize,Totalsize,Occupaied;
cout <<"\n\n RAM INFORMATION \n";
freesize =RAM.GetFreeRamInKB();
cout << "Free Memory space : ";
RAM.Display(freesize);
cout << "Total Memory space :";
Totalsize = RAM.GetRamInKB();
RAM.Display(Totalsize);
Occupaied = (Totalsize - freesize);
cout << "Occupaied memory :";
RAM.Display(Occupaied);
cout << "\n HARD DISK INFORMATION \n ";
HDD.DiskSpace();
HDD.TotalSizeofDisk();
return (EXIT_SUCCESS);
}
int MemoryInfo:

iskSpace()
{
FILE *fp;
// char line[200];
fp = popen( "df -H ", "r"); // df -H | grep /dev/sda
while ( fgets( line, sizeof line, fp))
{
printf("%s", line);
}
cout << endl;
pclose(fp);
}
int MemoryInfo::TotalSizeofDisk()
{
FILE *fp;
//char line[200];
fp = popen( "fdisk -l|grep Disk", "r");
while ( fgets( line, sizeof line, fp))
{
printf("Total %s", line);
}
cout << endl;
pclose(fp);
}
Dwijesh....