实现代码如下:
#!/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"))
时间: 2024-10-28 11:42:59