Vijay Kiran Kamuju infyquest@gmail.com writes:
+#ifdef HAVE_SYSINFO
struct sysinfo sinfo;
if (!sysinfo(&sinfo))
{
ULONG64 freeram = (ULONG64)sinfo.freeram * sinfo.mem_unit;
ULONG64 totalram = (ULONG64)sinfo.totalram * sinfo.mem_unit;
ULONG64 totalswap = (ULONG64)sinfo.totalswap * sinfo.mem_unit;
ULONG64 freeswap = (ULONG64)sinfo.freeswap * sinfo.mem_unit;
if ((fp = fopen("/proc/meminfo", "r")))
{
unsigned long long available;
char line[64];
while (fgets(line, sizeof(line), fp))
{
if (sscanf(line, "MemAvailable: %llu kB", &available) == 1)
{
freeram = min(available * 1024, totalram);
break;
}
}
fclose(fp);
}
It seems to me that as long as we are parsing /proc/meminfo, we could get everything from there, instead of mixing it up with sysinfo().