00001
00002
#include <cstdio>
00003
#include <cstdlib>
00004
#include "procinfo.h"
00005
#include <plearn/base/plerror.h>
00006
00007
namespace PLearn {
00008
00009 int getSystemTotalMemory()
00010 {
00011
int memory_size=0;
00012
char units[1000];
00013 FILE* p=popen(
"grep MemTotal /proc/meminfo",
"r");
00014 fscanf(p,
"%*s %d %s",&memory_size,units);
00015
if (strcmp(units,
"kB")==0)
00016 memory_size*=1024;
00017
else
00018
PLERROR(
"getSystemTotalMemory: unknown memory units %s",units);
00019 pclose(p);
00020
return memory_size;
00021 }
00022
00023 }