列出线程 c++

Listing Threads c++

本文关键字:c++ 线程      更新时间:2023-10-16

这段代码它列出了进程的所有进程和所有线程,但我希望它只列出 pid 进程的线程......示例:资源管理器.exe PID = 5454 通过 PID 希望他拥有线程和线程状态的 ID。

如何将进程 ID 作为命令行参数传递给程序并过滤掉所需的内容。

            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 <------ PROCESSOrn", pi->UniqueProcessId, pi->ImageName.Buffer);
                    else
                        wprintf(L"%u %s *rn", 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  rn",
                                n+1, th->StartAddress, th->ClientId.UniqueProcess, th->ClientId.UniqueThread,th->WaitReason);
                    }
                }
                pi = next;
            }

你可以在msdn上看到这个我认为这就是你要找的。