0
点赞
收藏
分享

微信扫一扫

关闭某进程

蛇发女妖 2023-06-24 阅读 77

# 关闭某进程
# 如果该进程存在 关闭
# 如果该进程不存在 忽略

# 判断某进程是否存在
# 根据进程名获取pid
# 如果获取到的结果不为空 即存在

# https://blog.51cto.com/lanzao/3232702
import psutil

def get_pid(name):
    '''
     作用:根据进程名获取进程pid
    '''
    pids = psutil.process_iter()
    print("[" + name + "]'s pid is:")
    for pid in pids:
        if(pid.name() == name):
            print(pid.pid)
            return pid.pid

pid_excel = get_pid("excel.exe")

# 返回结果为空
pid_excel is None

# 但是实验结果看来无论如何都是空

举报

相关推荐

0 条评论