Return the physical free memory on Linux
()
| 203 | |
| 204 | |
| 205 | def physical_free_linux(): |
| 206 | """Return the physical free memory on Linux""" |
| 207 | free_bytes = 0 |
| 208 | with open("/proc/meminfo") as f: |
| 209 | for line in f: |
| 210 | line = line.replace("\n", "") |
| 211 | ret = re.search(r'(MemFree|Cached):[ ]*([0-9]*) kB', line) |
| 212 | if ret is not None: |
| 213 | kb = int(ret.group(2)) |
| 214 | free_bytes += kb * 1024 |
| 215 | if free_bytes > 0: |
| 216 | return free_bytes |
| 217 | else: |
| 218 | raise Exception("unknown") |
| 219 | |
| 220 | |
| 221 | def physical_free_windows(): |