【Python】linux下通过python脚本程序杀死指定PID的进程程序

版权声明:These violent delights have violent ends。WeChat:neonwater https://blog.csdn.net/u014647208/article/details/81983330

linux下通过python脚本程序杀死指定PID的进程程序。

# -*- coding: UTF-8 -*-
import os
import sys
import signal

def kill(pid):
    try:
        a = os.kill(pid,signal.SIGKILL)
        print ("已经杀死pid为%s的进程,返回值是:%s"%(pid,a))
    except Exception as ee:
        print("没有此进程!")

if __name__ == '__main__':
    kill(641)
    kill(643)
    kill(645)

执行命令:

python3 Kill_process.py

注意如果有进程,执行不成功,需要执行一下命令:

sudo python3 Kill_process.py 

猜你喜欢

转载自blog.csdn.net/u014647208/article/details/81983330