Click to See Complete Forum and Search --> : Detect unresponsive process?


elumineX
September 12th, 2007, 05:53 AM
Is there a smart way to detect if a certain process is unresponsive. For ex if it has crashed and the crash dialog is shown waiting for the user to push the send report buttons etc. Or if it's stuck in a forever loop, has locked itself or something like it.

JVene
September 12th, 2007, 08:27 AM
Each condition you expressed represents very different 'sensory' logic.

If, for example, a dialog is showing some error condition, you could simply notify some 'protective service' that it's been shown. Some firewall and anti-virus applications run a separate 'service' application that can receive such a notice, and other period checks on it's brood.

The old 'tried and true' method is to see if the application is responding to messages, but it's no longer so 'true'. Back in the single thread days, if you sent a message to an application's main window and got no response, you'd know it's stuck. These days that could be a mistake - a thread might be locked but the UI thread still responds, so it's no longer as valuable a concept.

If you periodically check processor usage statistics and notice that your app is pegged at 100% utilization (gets complicated in multiple core systems), and that's not something you expect to happen for more than 'x' seconds, you can make some assumptions.

You'll notice that, occasionally, during shutdown (or application close), Windows may complain that an application isn't responding simply because it is taking too long to close. This is because they use a simple, not so universal means of determining that. It seems there are really no great solutions.

If you're in control of all the code you're attempting to control, you can incorporate heartbeats to check. The heartbeat is nothing more than some predictable action you can witness externally (could be implemented any number of ways, including, say, the setting of a semaphore - posting a message to the monitor service you're going to make for this - values written to shared memory established in a memory mapped file, etc).

elumineX
September 12th, 2007, 12:08 PM
Thanks for the informative reply. Your suggestions sounds worth investigating. I already have a service that monitors the process itself and restarts it when it's killed so I might try to play with that a bit and see if I can extend it to any of those things you mentioned.

Thank you again.