Re: Thread Status or Process Status

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Lasse (Lasse-NO_at_SPAM-engdahl.com)
Date: 10/31/04


Date: Sun, 31 Oct 2004 21:58:42 +0100

Hi Dhananjaya.R

Dhananjaya.R wrote:
> Hi Lasse,
>
> Thanks for early reply. I had a hard time understanding performance
> counters. Did you mean PSAPI and toolhelp32 uses performance counters to
> provide the same information.
> Is performance counters are part of Registry in all windows platforms?
> the strings we supply with the PDH counter path are path's of such
> predefined counters?
>
I think performance counters are part of Registry in all windows
platforms, but I don't know is the format is compatible in
releases before NT4. I guess you have to try it.

> So with this can we obtain the performance and wait time of a process and
> the reason for the wait time like user requested. thread blocked to accept
> some inputs from the user.
>
Yes, see my example output
ThreadState and WaitReason are described at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_thread.asp
(This is the Win32_Thread WMI class Arkady speaks of)

> Will it be possible to enumerate all the windows that are associated with
> a thread and if by some means if I have a predefined handling to close it
> will I be able to POST a WM_CLOSE to that window and continue with the
> process.
>

The EnumWindows() function enumerates all top-level windows on the screen
The EnumChildWindows() function enumerates the child windows that ...
The EnumThreadWindows() function enumerates all nonchild windows associated with a thread
Another process can POST a WM_CLOSE it close it.
(The trick is to know the Window Handle)

Lasse

> Once again all praises for any quick responses
>
> --
> Regards
> Dhananjaya R
>
> "Lasse" <Lasse-NO@SPAM-engdahl.com> wrote in message
> news:um44FSTvEHA.3152@TK2MSFTNGP14.phx.gbl...
>
>>Hi
>>I once implemented what you are asking about.
>>My implementation uses Performance counters.
>>
>>The Performance counters I am using are:
>> "ID Process"
>> "Priority Current"
>> "Thread"
>> "Thread State"
>> "Thread Wait Reason"
>> "% Processor Time"
>>
>>PSAPI and Toolhelp32 which you mention are (I think) only a
>>layer above using the Performance Counters directly.
>>
>>The output could look like this: (I just executed it)
>>
>>2004 explorer Thread information
>>
>>Num Prio ThreadTime(ms) State WaitReason
>>---------------------------------------------------
>>00 10 2_687.500 5= Wait 13= User request
>>01 11 2_125.000 5= Wait 13= User request
>>02 8 0_000.000 5= Wait 4= Exec delay
>>03 8 2_453.125 5= Wait 15= EventPairLow
>>04 10 0_000.000 5= Wait 6= UserRequest
>>05 11 0_000.000 5= Wait 6= UserRequest
>>06 15 0_000.000 5= Wait 6= UserRequest
>>07 10 0_109.375 5= Wait 13= User request
>>08 8 1_765.625 5= Wait 13= User request
>>09 14 0_015.625 5= Wait 13= User request
>>10 8 0_000.000 5= Wait 16= LPC Receive
>>
>>
>>Lasse
>>
>>
>>Dhananjaya.R wrote:
>>
>>
>>>Hi Experts,
>>>
>>> I have distributed application which is running NT/XP system. I need
>
> to
>
>>>find out the process state of an application. It is very much desirable
>
> if i
>
>>>can get a method where I can find the status of all the threads like(
>>>waiting for user i/o , suspended, idle etc). I am able to get the
>>>processID's and also threadID's. Is there any method by which we can
>>>identify whether a thread is in waiting status due to a modal pop
>
> window. Or
>
>>>thread is waiting for any other special cases.
>>>
>>> I did use PSAPI and Toolhelp32 to enumerate the process & threads. but
>>>don't know weather the state can be identified.
>>>
>>>Thanks in advance for all the help
>>>
>>>--
>>>Regards
>>>Dhananjaya R
>>>
>>>
>
>
>



Relevant Pages