windows监控进程是否还活着,查看内存使用率

1、导入库psutil

pip install psutil

2、查看进程是否活着

def is_process_running(self, process_name):
    # 查看程序是否还存活
    for process in psutil.process_iter():
        try:
            if process.name() == process_name:
                return True
        except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
            pass
    return False

3、获取内存

mem = int(psutil.virtual_memory()[2])
print('内存使用率', mem)
01-07 20:22