Having a Program Monitor Its Own CPU Usage

Posted on 2006-03-30
Last Modified: 2010-04-15
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.
Question by:jtrades
    LVL 11

    Accepted Solution

    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:
    LVL 3

    Expert Comment

    >>>jtrades, if you want it in Linux i can give you. But for windows I should try.

    All the best
    Prashant Sabnekar

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now