统计系统中剩余的内存
[root@Client-1 day2]#vi neicheng.py
#!/usr/bin/python
with open(‘/proc/meminfo‘) as fd:
for line in fd:
if line.startswith(‘MemTotal‘):
total = line.split()[1]
continue
if line.startswith(‘MemFree‘):
free = line.split()[1]
break
print total,free
print "%.2f" % (int(free)/1024.0)+‘M‘
保存并退出
[root@Client-1 day2]# python neicheng.py
1030452 680640
664.69M
本文出自 “知识改变命运” 博客,谢绝转载!
原文:http://ahtornado.blog.51cto.com/4826737/1795406