• C

Having a Program Monitor Its Own CPU Usage

I am looking for a way to have a program monitor its own CPU usage.  Can anyone describe how I may do this (code would be appreciated as well)?  I am trying to write the program in C using Microsoft Visual .Net.  Thanks.
Who is Participating?
You can call GetCurrentProcess() to get your your own process handle and then use GetProcessTimes() to find out how much time was spent by your process.

If you want to get a percentage value similar to those displayed in task manager you can use the Performance Data Helper API:
There is a discusssion about this and a code sample at the end of this articte:
see here how to get the value with PdhGetFormattedCounterValue directly:
Prashant SabnekarAVPCommented:
>>>jtrades, if you want it in Linux i can give you. But for windows I should try.

All the best
Prashant Sabnekar
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.