首页 > 系统相关 >【python】根据进程名获取pid, 并杀死进程

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

时间:2022-08-24 16:33:07浏览次数:52  
标签:name python pid psutil https 进程 os

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

标签:name,python,pid,psutil,https,进程,os
From: https://www.cnblogs.com/fireblackman/p/16620605.html

相关文章