统计系统中剩余的内存
[[email protected] 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‘
保存并退出
[[email protected] day2]# python neicheng.py
1030452 680640
664.69M
时间: 2025-01-02 09:36:32