【python】根据进程名获取pid, 并杀死进程

1、pypi

https://pypi.org/project/psutil/

 

2、github

https://github.com/giampaolo/psutil

 

3、doc

https://psutil.readthedocs.io/en/latest/

 

4、获取chromedriver.exe的pid

import psutil

def get_pid(name):
    pids = psutil.process_iter()
    print("[" + name + "]'s pid is:")
    for pid in pids:
        if(pid.name() == name):
            print(pid.pid)


get_pid(
"chromedriver.exe")

 

5、根据pid杀死进程(win)

import os


os.kill(pid, signal.SIGINT)

 

 

 

参考链接:

https://blog.51cto.com/lanzao/3232702?b=totalstatistic

https://blog.csdn.net/craftsman2020/article/details/112917807

posted @ 2022-08-24 16:30  代码诠释的世界  阅读(1390)  评论(0编辑  收藏  举报