Python 判断一个进程是否存在

import psutil

def judgeprocess(processname):
    pl = psutil.pids()
    for pid in pl:
        if psutil.Process(pid).name() == processname:
            print(pid)
            break
    else:
        print("not found")
        
if judgeprocess('notepad++.exe') == 0:
    print('success')
else:
    pass

猜你喜欢

转载自blog.csdn.net/kaida1234/article/details/79861596