1

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

Azodious
  • 13,752
  • 1
  • 36
  • 71
gravetii
  • 9,273
  • 9
  • 56
  • 75
  • 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,752
  • 1
  • 36
  • 71
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,779
  • 28
  • 50