-1

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.

Wellison
  • 19
  • 4

2 Answers2

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;
            }
0

you can see this on msdn i think this is what you are looking for.

Yanshof
  • 9,659
  • 21
  • 95
  • 195
  • 2
    It'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