遍历进程运行线程数

#include "stdafx.h"
#include <Windows.h>
#include <TlHelp32.h>
#include <stdio.h>
#include <stdlib.h>




void TestProcessGetThreadNumber() 
{


int i = 0;
char Buff[9];
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(pe32);


HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
{
printf("CreateToolhelp32Snapshot 调用失败.\n");
return ;
}
BOOL bMore = ::Process32First(hProcessSnap,&pe32);


HANDLE hProcess;


printf("%-30s %-20s %-20s %-15s\n","szExeFile","th32ProcessID","th32ParentProcessID","cntThreads");
while(bMore)
{
printf("%-30s ",pe32.szExeFile);
printf("%-20d ",pe32.th32ProcessID);
printf("%-20d",pe32.th32ParentProcessID);




//显示进程的线程数
printf("%-15d\n",pe32.cntThreads);


bMore = Process32Next(hProcessSnap,&pe32);
i++;


//pe32.th32ModuleID
}


printf("进程数:%d\n",i);
system("pause");
exit(0);
}


int _tmain(int argc, _TCHAR* argv[])
{
TestProcessGetThreadNumber();
return 0;
}

猜你喜欢

转载自blog.csdn.net/jangdong/article/details/80707381
今日推荐