Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking "liveness" of a Windows application?

I've got a Windows application running some expensive equipment; this application dies in a variety of creative ways. Usually when it goes, the process dies completely. I wrote a little monitoring program which looks for the process' name in the list of things which are currently running, and that works great for those failures. But sometimes it just becomes completely nonresponsive and requires termination via the task manager, but is still "running" in some unhelpful sense.

I'm completely unfamiliar with the Windows API, so this is perhaps quite a stretch, but is there anything I can do to programmatically check the "liveness" of other processes? Or which I might use to make guesses? (Watching for it to stop processing events from the OS, or for all disk access/memory allocation to halt, etc, etc)

Preferably it would be something I could do via the Python win32 module, but I'll branch out to anything that can successfully detect when this thing locks up. And, I realize "liveness" is vague, but I don't want to rule anything out, particularly when I don't have any insight into how this thing is really failing.

like image 338
Jay Kominek Avatar asked Mar 13 '12 20:03

Jay Kominek


2 Answers

I think the best way to go about this is by using the Process & Thread functions in the WIN32 API. NB: You can easily embed C++ code in python. This will likely require some time and patience, and I do not know most of these functions myself.

On the other hand, there is a detailed project on Process Monitoring on Codeproject and Python WMI, a wrapper for WMI in python, but remember WMI is considerably slow and you have to ensure the service is running on the PC.

It's also possible that you might be able to send a message to the process that will cause the process to provide a reply or change it's state if it is alive, and then check for this change in the process for some time.

like image 180
Chibueze Opata Avatar answered Sep 30 '22 06:09

Chibueze Opata


You'll need to get a HWND handle to the window in question (EnumWindowHandles might be a good start), and then try calling IsHungAppWindow to see if the system thinks it's unresponsive.

like image 45
SecurityMatt Avatar answered Sep 30 '22 08:09

SecurityMatt