Created
June 3, 2020 17:21
-
-
Save randhawp/f72032087566f815751472a913725208 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d' ' -f2 | |
or | |
free -m | head -2 | tail -1 | tr -s ' ' | cut -d' ' -f4 | |
------------------------------------------------------------------------ | |
#include <iostream> | |
int check_free_ram(){ | |
FILE *fp; | |
int status; | |
char result[24]; | |
std::string cmd="free -m | head -2 | tail -1 | tr -s ' ' | cut -d' ' -f4"; | |
fp = popen(cmd.c_str(), "r"); | |
if (fp == NULL) | |
return -1; | |
while (fgets(result, PATH_MAX, fp) != NULL); | |
//printf("%s", result); | |
status = pclose(fp); | |
if (status == -1) { | |
return -1; | |
} else { | |
return atoi(result); | |
} | |
--------------------------------------------------------------------------- | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment