39 #include "safec_lib.h"
55 char memoryUtilization[MAXLEN]={
'\0'};
59 printf(
"USED_MEM:%s\n", memoryUtilization);
63 printf(
"USED_MEM:NOT AVAILABLE\n");
82 long long memTotal = 0;
83 long long memFree = 0;
84 long long memoryInUse=0;
89 int mem_total_len = 0, mem_free_len = 0 ;
92 if ((memoryinfo = fopen(
"/proc/meminfo",
"r")) == NULL)
94 printf(
"Failed to get Memory Utilization mode\n");
98 mem_total_len = strlen(
"MemTotal:");
99 mem_free_len = strlen(
"MemFree:");
101 while(fgets(line, MAXLEN, memoryinfo))
103 sscanf(line,
"%512s", tmp);
104 rc = strcmp_s(
"MemTotal:",mem_total_len,tmp, &ind);
106 if((!ind) && (rc == EOK))
108 sscanf(line,
"%*s %512s", tmp);
109 memTotal = atoll(tmp);
114 rc = strcmp_s(
"MemFree:",mem_free_len,tmp, &ind);
116 if((!ind) && (rc == EOK))
118 sscanf(line,
"%*s %512s", tmp);
119 memFree = atoll(tmp);
123 if (Total_flag == 1 && Free_flag == 1) {
129 memoryInUse = (memTotal - memFree);
130 if(memoryUtilization)
132 rc = sprintf_s(memoryUtilization,MAXLEN,
"%lld",memoryInUse);
141 printf(
"Exit from get Memory Utilization due to NULL pointer");