实现代码如下:
#!/usr/bin/python #coding:utf8 from subprocess import Popen, PIPE import os nginxpid = Popen(["pidof", "nginx"], stdout=PIPE) nginxpid = nginxpid.stdout.read().split() memsum = 0 for i in nginxpid: pidfile = os.path.join("/proc/", str(i), "status") with open(pidfile) as f: for mem in f: if mem.startswith("VmRSS"): pidmem = int(mem.split()[1]) memsum += pidmem print("%d %s" %(memsum,"KB"))
本文出自 “蓝色_风暴” 博客,请务必保留此出处http://270142877.blog.51cto.com/12869137/1934859
使用python3.x实现统计Nginx进程所占用的物理内存
原文地址:http://270142877.blog.51cto.com/12869137/1934859