#coding=utf-8
import psutil
import sys
import time
import os
def listen(PID):
f = open('listen_server.txt','w')
i = 1
while i == 1 :
p1 = psutil.Process(PID)
cpu1 = p1.cpu_percent(interval=1)
mem = p1.memory_percent()
#print(mem)
f.write('%f %f\n' % (cpu1,mem))
#print >> f, '%s %s' % (cpu1,mem)
f.flush()
os.fsync(f)
f.close
def main():
pd = 1123
listen(pd)
if __name__ == '__main__':
main()
可后台:nohup python *.py &
nohup python *.py >/dev/null 2>&1 &