• 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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Prashant SabnekarAVPCommented:
>>>jtrades, if you want it in Linux i can give you. But for windows I should try.

All the best
Prashant Sabnekar
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.