Check status of process and restart process if unresponsive/stopped - Python

泪湿孤枕 提交于 2019-12-10 11:55:33

问题


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

The script would:

  • find target process
  • check status (running/unresponsive/stopped)
  • kill and restart process if unresponsive/stopped

Any suggestion on the best way to implement this?


回答1:


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.

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).



来源:https://stackoverflow.com/questions/7024626/check-status-of-process-and-restart-process-if-unresponsive-stopped-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!