#coding=utf-8 import os,time while True: cmd='ps -e|grep %s'%('python3') a=os.popen(cmd)#返回一个对象 txt=a.readlines() if len(txt)==0: print('没有') break else: for lin in txt: lin_=lin.split() pid=lin_[0] cmd='kill -9 %d'%(int(pid)) rc=os.system(cmd) #或者使用os.kill,,kill没有返回值,9是 系统的信号 #print(os.kill(int(pid),9)) print(rc) if rc==0: print('成功杀死pid%s'%pid) else:print('失败') time.sleep(2)