问题
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