windows 下获取当前进程的线程数量

#include <TlHelp32.h>

int
get_thread_amount() { int i = 0; char Buff[9]; PROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); int processid = GetCurrentProcessId(); HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == INVALID_HANDLE_VALUE) { printf("CreateToolhelp32Snapshot() failed. error code:%d.\n", GetLastError()); return 0; } BOOL bMore = ::Process32First(hProcessSnap, &pe32); HANDLE hProcess; while (bMore) { if (pe32.th32ProcessID == processid) { return pe32.cntThreads; } bMore = Process32Next(hProcessSnap, &pe32); i++; } return 0; }

 

posted @ 2014-07-02 09:23  莫压枯枯地  阅读(5301)  评论(0编辑  收藏  举报