python根据进程名获取windows下的进程id

1,安装psutil

   pip install psutil

2,脚本

import psutil

def get_pid(pname):
for proc in psutil.process_iter():
#print(“pid-%d,name:%s” % (proc.pid,proc.name()))
if proc.name() == pname:
return proc.pid

pid = get_pid(“SUT.Client.Upgrade.exe”)
print pid

你可能感兴趣的:(python)