Created
April 24, 2012 17:42
-
-
Save gregpinero/2481884 to your computer and use it in GitHub Desktop.
Try to figure out how much memory is free on a Unix system. Returns free memory in mB.
This file contains 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
def get_free_memory(): | |
""" | |
Try to figure out how much memory is free on a Unix system. | |
Returns free memory in mB. | |
""" | |
data = open("/proc/meminfo", 'rt').readlines() | |
free = 0 | |
for line in data: | |
if line.startswith("MemFree") or line.startswith("Buffers") or line.startswith("Cached"): | |
items = line.split() | |
free += int(items[1]) | |
#print "free memory is",free/1000,"mB" | |
return free/1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment