Reputation: 23
Right now, I use CreateToolhelp32Snapshot()
to calculate the number of running processes by traversing a snapshot of all processes. Is there any API to get the number directly, instead of traversing?
Upvotes: 0
Views: 695
Reputation: 1
I was looking into this recently and found GetPerformanceInfo which fills in the PERFORMANCE_INFORMATION struct. The total process count is written to the ProcessCount
member.
PERFORMANCE_INFORMATION performanceInfo;
GetPerformanceInfo(&performanceInfo, sizeof(performanceInfo);
printf("%d processes running", performanceInfo.ProcessCount);
I'm not sure what the performance difference is between this function and EnumProcesses as suggested by others though.
Upvotes: 0
Reputation: 4017
As far as I'm concerned, there is no proper API to get the numbers directly, instead of traversing.
For more details to get the list of running processes, I suggest you could refer to the example:
Taking a Snapshot and Viewing Processes
Upvotes: 0
Reputation: 101646
EnumProcesses
and divide by 4. Internally this calls the NT API and traverses last time I looked but that was a long time ago...
Upvotes: 1