this code it lists all processes and all threads of the process, but I want it lists only the thread of a process by pid ... example: explorer.exe pid = 5454 through the pid wanted him to have the ids of threads and thread state.
Asked
Active
Viewed 451 times
-1
-
1possible duplicate of [Listing Threads](http://stackoverflow.com/questions/20892367/listing-threads) – Retired Ninja Jan 05 '14 at 03:38
2 Answers
0
How about passing the process ID as a command line argument to the program and filter out the content required.
while( pi )
{
SYSTEM_PROCESS_INFORMATION* next = PROCESS_INFORMATION_NEXT( pi );
UINT32 count, n;
if (argc > 1 && pi->UniqueProcessId == (HANDLE)atoi(argv[1])) {
printf("**************************************\n");
if( pi->ImageName.Buffer )
wprintf(L"%u %s <------ PROCESSO\r\n", pi->UniqueProcessId, pi->ImageName.Buffer);
else
wprintf(L"%u %s *\r\n", pi->UniqueProcessId, L"System Idle Process");
if( next )
count = ThreadCount( pi, (ULONG_PTR)next );
else
count = ThreadCount( pi, (ULONG_PTR)spi + size );
for( n=0; n<count; n++ )
{
SYSTEM_THREAD_INFORMATION* th = pi->Threads + n;
wprintf(L" [%u] StartAddress=%p ID Processo=%u IdThred=%u State=%u \r\n",
n+1, th->StartAddress, th->ClientId.UniqueProcess, th->ClientId.UniqueThread,th->WaitReason);
}
}
pi = next;
}

Duleeka Gunatilake
- 366
- 3
- 9
-
if (argc > 1 && pi->UniqueProcessId == (HANDLE)atoi(argv[1])) explicate? – Wellison Jan 05 '14 at 18:49
0
-
2It's better to summarise the required steps in your answer rather than just posting a link. That way, the answer will still be useful if the link changes or disappears in future. – Roger Rowland Jan 05 '14 at 10:03