1

Is it possible to know the CPU usage of a running/idle process programatically (in any language) in Windows?

Azodious
  • 13,563
  • 1
  • 33
  • 68
gravetii
  • 8,485
  • 8
  • 49
  • 69
  • 1
    Some what helps - http://stackoverflow.com/questions/11118647/get-process-cpu-usage-in-c – Jayan Oct 01 '12 at 11:16

2 Answers2

2

in C# you can do following:

private PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName);

cpuCounter.NextValue(); // it will give you cpu usage

you should refer here for details.

Azodious
  • 13,563
  • 1
  • 33
  • 68
2

If you don't care on support old Windows versions (earlier than Windows XP SP1) you could use GetSystemTimes Win32 API function.

Otherwise you have to use Performance Counters.

Rost
  • 8,619
  • 26
  • 48