首页 » 脚本 » 正文

获取内存的脚本

#!/usr/bin/python

from __future__ import print_function
from collections import OrderedDict

def meminfo():
”’ Return the information in /proc/meminfo
as a dictionary ”’
meminfo=OrderedDict()

with open(‘/proc/meminfo’) as f:
for line in f:
meminfo[line.split(‘:’)[0]] = line.split(‘:’)[1].strip()
return meminfo

if __name__==’__main__’:
#print(meminfo())

meminfo = meminfo()
print(‘Total memory: {0}’.format(meminfo[‘MemTotal’]))
print(‘Free memory: {0}’.format(meminfo[‘MemFree’]))

发表评论