From 135469a03d1a03903a57557decb99996aba835cb Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 25 May 2015 18:27:08 +0200 Subject: memory on Linux --- src/biruda.c | 2 +- src/system.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/biruda.c b/src/biruda.c index ea1fce5..091bbbf 100644 --- a/src/biruda.c +++ b/src/biruda.c @@ -205,7 +205,7 @@ static void print_config( struct gengetopt_args_info *args_info, cfg_t *cfg ) puts( "Environment:" ); printf( " Number of CPUs: %d\n", nofCpus ); int physMem = system_phys_memory( ); - printf( " Physical memory available: %d MB\n", physMem ); + printf( " Physical memory available: %d kB\n", physMem ); char machine_arch[100]; system_arch( machine_arch, sizeof( machine_arch ) ); printf( " System architecture: %s\n", machine_arch ); diff --git a/src/system.c b/src/system.c index b947ce2..9e2256d 100644 --- a/src/system.c +++ b/src/system.c @@ -390,8 +390,17 @@ int system_phys_memory( ) memset( &memState, 0, sizeof( MEMORYSTATUSEX ) ); memState.dwLength = sizeof( MEMORYSTATUSEX ); GlobalMemoryStatusEx( &memState ); - return memState.ullTotalPhys / 1024 / 1024; + return memState.ullTotalPhys / 1024; +#elif defined( linux ) || defined( __linux ) || defined( __linux__ ) + size_t pageSize; + size_t nofPages; + + pageSize = sysconf( _SC_PAGESIZE ); + nofPages = sysconf( _SC_PHYS_PAGES ); + + return ( pageSize / 1024 ) * nofPages; #else +#error Not ported yet! #endif } -- cgit v1.2.3-54-g00ecf