In C, overall CPU usage can be determined using Performance Counters (there is a small typo in the sample code: sleep
should be changed to sleep
).
In C ++, C #, Delphi, etc. I would recommend using WMI .
== EDIT ==
I found an approach to use a processor for each process . For example, to get the Microsoft Outlook processor load, change the counter path in the above example to the following:
PdhAddCounter(query, TEXT("\\Process(OUTLOOK)\\% Processor Time"), 0, &counter);
If you have multiple instances of the same executable, you can use indexes . This MSDN example is also very useful.
source share