I have written a code which perfectly works on Ubuntu . But getting unexpected behavior on QNX .
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
int main( void )
{
printf( "Total Memory = %ld MB\n",
(sysconf(_SC_PHYS_PAGES)* sysconf(_SC_PAGESIZE))/1048576);
printf("Getting available memory...\n");
printf( "Available = %ld MB\n",
(sysconf(_SC_AVPHYS_PAGES)* sysconf(_SC_PAGESIZE))/1048576);
printf("Getting used memory...\n");
printf( "Used Memory = %ld MB\n",((sysconf(_SC_PHYS_PAGES) -
sysconf(_SC_AVPHYS_PAGES))* sysconf(_SC_PAGESIZE))/1048576);
return EXIT_SUCCESS;
}
This perfectly works fine on Ubuntu but not on QNX . Is there any different way out to do this ?
Output :
Total Memory = - 3906 MB
Available = - 3096 MB
Used Memory = 0 MB
After investing lot of time i got a way i could do it.
Using:
Showmem -S
To execute this command from c Programming Language use pipe
FILE *fp;
pf = popen(command,"r");
Then you can grab the data from fp.