spaziwk has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know how to determine if a Win32 Process is Hung? I can get a Process list with Win32::Process::Info, but I want to somehow check if the Process is hung. Win32::Process::Info also provides lot of detailed info about the process. Don't know what to to look for that would indicate a Hung Process.
  • Comment on How to Determine if a WIN32 Process is Hung

Replies are listed 'Best First'.
Re: How to Determine if a WIN32 Process is Hung
by PodMaster (Abbot) on Jun 04, 2004 at 10:19 UTC
    What qualifies as a hung process?

    If the process has a window you can use SendMessageTimeout to check.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: How to Determine if a WIN32 Process is Hung
by EdwardG (Vicar) on Jun 04, 2004 at 12:06 UTC

    How do you know if the process is hung?

    • It really, really depends on what your process is supposed to be doing.
    • 0% or 100% CPU, either or neither could be hung.
    • Has the process started a loop that it will never exit? How can you tell?
    • Is the process waiting on a resource that it will never get?
    • Is it just waiting for a slow network resource?
    • Is it dumping core?
    • Does it have too many messages queued?

    And so on.

     

      What does Windows itself use to determine when it decides an application is "Not Responding"?
        This is educated conjecture...

        Windows sends a message to the application; if the application takes N seconds without (a) responding to that message, or (b) receiving the message and letting it die, then it considers it "hung." You can easily write small applications which do this, just by doing something as benign as a sleep for 100 seconds.

        It could be smarter, and there are other issues with multiple-threaded applications: are all threads in a WaitForObject state at the same time (deadlock)? Has it handled ANY messages, not just the one test message?

        --
        [ e d @ h a l l e y . c c ]

        "Not Responding" has a precise meaning, "hung" doesn't, and that is the point.

         

Re: How to Determine if a WIN32 Process is Hung
by blueAdept (Beadle) on Jun 04, 2004 at 14:26 UTC
    If the process is a windows "service" then you should try to use the mechanism windows has within that API. The windows service API has an "INTERROGATE" request(or message) that is sent to the service, and as halley said it must respond within a certain amount of time - else be considered hung/unresponsive. You can perform this check using the Win32::Service 's "GetStatus" method, or another likely option is with WMI (using Win32::OLE)

    If its not a windows service I don't know what to suggest. I've seen utilities output the status of threads (e.g. "waiting") - I wonder if that type of information would be useful for determining if a process is hung. Not that I can suggest how to tap that info from perl.
Re: How to Determine if a WIN32 Process is Hung
by BrowserUk (Patriarch) on Jun 04, 2004 at 16:48 UTC

    You could try calling IsHungWindowApp() if you are monitoring a specific application (and can obtain the window handle for it).


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
Re: How to Determine if a WIN32 Process is Hung
by EdwardG (Vicar) on Feb 25, 2005 at 10:44 UTC

    Under XP

    tasklist /FI "STATUS eq NOT RESPONDING"