Python获取Linux系统内存情况,pythonlinux,[Python]代码
Python获取Linux系统内存情况,pythonlinux,[Python]代码
[Python]代码 ``` pythonimport subprocessimport re
keydic = {"MemTotal":"总内存(单位G)", "MemFree":"剩余内存(单位G)", "MemAvailable":"可用内存(单位G)", "Cached":"缓存内存(单位G)"}
def command(command): p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) resultDic = {} for line in p.stdout.readlines(): line = str(line,encoding="utf-8") result = re.split("\s",line) if result[0][:-1] in keydic: resultDic[keydic[result[0][:-1]]] = "%.2f" %(int(result[1])/(1024*2)) return resultDic
if name == "main": print(command("cat /proc/meminfo"))```
相关内容
- 分形图,,#!/usr/bin/e
- 选择打开选择文件 神龙 QQ29295842,神龙qq29295842,#!/usr/
- Python 调用 C++,python调用,#include <bo
- print &quot;hello python&quot;,,print "hello
- 将华氏温度转换成摄氏温度,或者相反,华氏摄氏,#-
- 用XML_RPC实现P2P,XML_RPC实现P2P,# -*- coding
- 有道词典导出的xml生词本文件提取出单词,xml生词,im
- python通过PIL缩放互联网上的图片并保存,,python通过PI
- python将html表格转换成CSV,pythonhtml表格csv,python将html表
- 原 第三方Linux版网易云音乐 出新版了,第三方linux,pr
评论关闭