使用python轮询某个进程是否存在如果进程存在返回TRUE
可以使用psutil模块来实现:
import psutil
def check_process(process_name):
for proc in psutil.process_iter():
try:
if proc.name() == process_name:
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
这个函数会遍历当前运行的所有进程,如果找到了指定的进程就返回True,否则返回False。
使用方法:
if check_process("进程名"):
print("进程存在")
else:
print("进程不存在")
原文地址: https://www.cveoy.top/t/topic/XY3 著作权归作者所有。请勿转载和采集!