网络编程
位置:首页>> 网络编程>> Python编程>> python 判断linux进程,并杀死进程的实现方法

python 判断linux进程,并杀死进程的实现方法

作者:Jacob-wj  发布时间:2022-06-24 22:31:54 

标签:python,linux,杀死,进程

如下所示:

'''@author: Jacobpc'''import osimport sysimport subprocess def get_process_id(name):  child = subprocess.Popen(["pgrep","-f",name],stdout=subprocess.PIPE,shell=False)  response = child.communicate()[0]  return response pid = get_process_id("python socialbanklog.py")print pidif not pid:  print "no target pid to kill,please check"  sys.exit(1) result=os.system("kill -9 "+pid)if result==0:  print "execute kill success"else:  sys.exit(1) 

来源:https://blog.csdn.net/wangjia55/article/details/80401423

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com