Python实现进程监控 避免程序意外终止
2022-05-20 10:40
import os import psutil import time # 被检测程序路径 name = r"" # 进程检测函数 def checkprocess(processname): pl = psutil.pids() for pid in pl: if psutil.Process(pid).name() == processname: return pid #监控函数 def run(): if isinstance(checkprocess('进程名'),int): print("进程存在") else: print("进程不存在") code(name) time.sleep(3) run() run()
本文来自博客园,作者:Haibara-Z3r0,转载请注明原文链接:https://www.cnblogs.com/Yu-0/articles/16337757.html