Skip to content

Instantly share code, notes, and snippets.

@gregpinero
Created April 24, 2012 17:42
Show Gist options
  • Save gregpinero/2481884 to your computer and use it in GitHub Desktop.
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.
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