统计内存信息

#!/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)

 

 

 

 

 

 

    

posted @ 2019-01-21 16:01  孔雀东南飞  阅读(123)  评论(0编辑  收藏  举报