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

Dear Monks,

Is there any option to find out the Applications running status in Windows Task Manager.

I need to find out the Application in Not Responding status.

Then quit the Application, then restart the application freshly.

Thanks in Advance,
Shanmugam A.
  • Comment on Applications running status in Windows Task Manager

Replies are listed 'Best First'.
Re: Applications running status in Windows Task Manager
by ikegami (Patriarch) on Nov 17, 2008 at 16:49 UTC

    Is the application you want to monitor one you wrote? If so, you could add a heartbeat. Have the monitored application perform an action periodically. For example, update the access time of a specific file every second. Your monitor would then check the access time of the file. If it's older than some threshold, somethings wrong.

    That's basically how "Not Responding" is obtained. I think an application is deemed "Not Responding" when it was asked to exit, but didn't after a certain amount of time.

      An application will be marked as not responding by windows if it hasn't interacted with the system for a minute or two.
      I had a small app once, that had to spin through 10k records, and it would be marked as not responding until it finished the tight loop and reported the results.
      So I just added a call to repaint the window every N times through the loop, and windows was happy from then on.

      The forceful terminate is a separate, if related issue, from the regular not responding status.
        Hi Monks,

        Still, i could not find the solution to get the applications status list from the windows task manager in windows 2k professonal/XP. I do not want the processes list.

        Since this Windows Task Manager, Applications tab only contains the "Not Responding" staus.

        Please guide me to do further. I am Struggling this task

        Thanks in Advance
        Shanmugam A.
Re: Applications running status in Windows Task Manager
by GrandFather (Saint) on Nov 17, 2008 at 19:58 UTC

    Windows marks an application as "not responding" when it hasn't re-entered the message loop within some (fairly short) period of time. That doesn't mean the application has "hung", just that the OS hasn't noticed it do anything interesting in a while. In principle there is no way to determine if an application has "hung" - that is a problem related to the Halting_problem.

    You can use Win32::Process to manipulate Windows processes, but you need the PID for a running process before you can work with it. Obtaining the PID is a bit tricky unless you created the process in the first place. I don't see any way of obtaining a "not responding" status for a process from the Win32 API (although that doesn't mean there isn't a way).


    Perl reduces RSI - it saves typing
Re: Applications running status in Windows Task Manager
by ig (Vicar) on Nov 17, 2008 at 22:21 UTC

    The .net process class has a responding property and a kill method. You might be able to access these via Win32::CLR, but I have never done that myself.

Re: Applications running status in Windows Task Manager
by BrowserUk (Patriarch) on Nov 19, 2008 at 20:08 UTC

    The Not Responding status is attributed to a process when it stops processing it's message queue for a period of 5 seconds. You can determine this situation using SendMessageTimeout() with the flag SMTO_ABORTIFHUNG.

    You will have to obtain the hwnd for the process you wish to monitor. Alternatively, use a thread to do the monitoring and use NULL for the hwnd. You'll need to use Win32::API or Inline::C to call these apis.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Applications running status in Windows Task Manager (SOLUTION)
by ccn (Vicar) on Nov 19, 2008 at 20:23 UTC

    "Not Responding" appears in the title bar of the program while Task manager showing 'not responding' status. Using this fact you can detect if your program is in 'not responding' status.

    Set $NOT_RESPONDING variable accordingly your application title.

    use strict; use warnings; use Win32::API; my $NOT_RESPONDING = 'Your App (Not Responding)'; use constant GW_CHILD => 5; use constant GW_HWNDNEXT => 2; Win32::API->Import('user32', 'HWND GetDesktopWindow()'); Win32::API->Import('user32', 'HWND GetWindow(HWND hWnd, UINT uCmd)'); Win32::API->Import('user32', 'GetWindowText', 'LPi', 'i'); my $hwnd = GetDesktopWindow(); $hwnd = GetWindow($hwnd, GW_CHILD); while ($hwnd) { $hwnd = GetWindow($hwnd, GW_HWNDNEXT); my $title = 'x' x 256; GetWindowText($hwnd, $title, length($title) - 1); if ($title =~ /\Q$NOT_RESPONDING/) { print "Detected: $NOT_RESPONDING\n"; } }

    I am not on Windows now and can't test if the script runs without errors. But I hope it will be helpful.