本文介绍了检查进程状态,如果无响应/已停止,则重新启动进程-Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows Server 2008上构建一个小的进程监视脚本.

I'm trying to build a small process monitoring script on Windows Server 2008.

脚本将:

  • 找到目标过程
  • 检查状态(运行/无响应/已停止)
  • 如果没有响应/已停止,则杀死并重新启动过程

关于实现此目标的最佳方法的任何建议吗?

Any suggestion on the best way to implement this?

推荐答案

将进程命名为无响应"是非常主观的.它可能正在等待数据并且似乎没有响应,或者可能处于(无休止的)循环中并且似乎没有响应.

Naming a process 'unresponsive' is quite subjective. It might be waiting for data and seem unresponsive, or it might be in a (endless) loop and seem unresponsive.

通常,人们的工作是实施 hartbeat .即-在该进程中拥有一个非常小的套接字服务器,其他进程可以在该服务器中连接并发送ping消息,并向其回复pong.监视工具通常会定期对进程进行ping操作,如果它在超时内没有响应-则认为它没有响应(通常被杀死).

Usually, what people do is implement hartbeat. That is - have a very tiny socket server in the process where other processes can connect and send ping messages, to which it replies pong. What monitoring tools usually do is ping the process periodically, and if it doesn't respond within a timeout - it's considered unresponsive (and usually gets killed).

这篇关于检查进程状态,如果无响应/已停止,则重新启动进程-Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:27