后端开发|Python教程
python,linux系统,系统内存,使用情况
后端开发-Python教程
本文实例讲述了python在linux系统下获取系统内存使用情况的方法。分享给大家供大家参考。具体如下:
erp源码php,ubuntu 放网站目录,tomcat用花生壳,女孩踩死爬虫,护卫神php套件出现,seo应聘?lzw
"""Simple module for getting amount of memory used by a specified users processes on a UNIX system.It uses UNIX ps utility to get the memory usage for a specified username and pipe it to awk for summing upper application memory usage and return the total.Pythons Popen() from subprocess module is used for spawning ps and awk."""import subprocessclass MemoryMonitor(object): def __init__(self, username): """Create new MemoryMonitor instance.""" self.username = username def usage(self): """Return int containing memory used by users processes.""" self.process = subprocess.Popen("ps -u %s -o rss | awk {sum+=$1} END {print sum}\" % self.username, shell=True, stdout=subprocess.PIPE, ) self.stdout_list = municate()[0].split(\ ) return int(self.stdout_list[0])
源码有假的么,vscode写大风车,ubuntu安装dydra,怎么卸载tomcat 9,stata 爬虫案例,php格式化xml字符串,北京seo网络推广平台,php网站绑定域名,管理系统模板 jsplzw
将上面的代码保存为:memorymonitor.py
图片管理软件 源码,ubuntu无设置中文,爬虫技术抓取简历,php压缩实例,广西seo定制lzw
调用方法如下:
from memorymonitor import MemoryMonitormemory_mon = MemoryMonitor(username)used_memory = memory_mon.usage()