统计内存信息

#!/usr/bin/env python
#-*- coding:utf-8 -*-

''' 统计内存信息 '''  

with open('/proc/meminfo') as fd:
    for line in fd:
        if line.startswith('MemTotal'):
            MemTotal = line.split()[1]
            continue
        if line.startswith('MemFree'):
            MemFree = line.split()[1]
            break
        
print "总内存:%sM" % (int(MemTotal)/1024)
print "剩余内存:%sM" % (int(MemFree)/1024)

    

原文地址:https://www.cnblogs.com/pzk7788/p/10299239.html