方法一:
free -m
方法二:
建立一个文件 RAM.py 运行.
#!usr/bin/python
#-*- coding: UTF-8 -*-
import os
import time
import re
while True:
# Get memory usage info
cpuinfo = os.popen("free -m | grep Mem")
strMem = cpuinfo.readline()
# Get all the number from string
numMem = re.findall("\d+", strMem)
print("Total memory: %sMB, Used memory: %sMB, Memory usage:%d%%" \
%(numMem[0], numMem[1], int(numMem[1])*100/int(numMem[0])))
time.sleep(3)
运行结果:
参考:http://www.eefocus.com/nightseas/blog/15-05/312904_949ea.html