I'm trying to build a small process monitoring script on Windows Server 2008.
The script开发者_StackOverflow中文版 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?
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).
精彩评论