python 判断linux进程,并杀死进程的实现方法
如下所示:
''' @author:Jacobpc ''' importos importsys importsubprocess defget_process_id(name): child=subprocess.Popen(["pgrep","-f",name],stdout=subprocess.PIPE,shell=False) response=child.communicate()[0] returnresponse pid=get_process_id("pythonsocialbanklog.py") printpid ifnotpid: print"notargetpidtokill,pleasecheck" sys.exit(1) result=os.system("kill-9"+pid) ifresult==0: print"executekillsuccess" else: sys.exit(1)
以上这篇python判断linux进程,并杀死进程的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。