Process CPU Usage

  • Thread starter Thread starter Raghuvansh
  • Start date Start date
R

Raghuvansh

I am able to find out the process names by the code below but am
clueless how to find out the CPU Usage levels of hte process at any
given time.

Any help??

Dim myProcesses() As Process = Process.GetProcesses
Dim myProcess As Process
For Each myProcess In myProcesses
If (myProcess.ProcessName.ToLower = "buggyprocess") Then
myProcess.Kill()
End If
Next


PS: I want to monitor 'buggyprocess' and see if its 'CPU Usage'
remains above 75% over a period of time, then kill it.
 
Raghuvansh said:
I am able to find out the process names by the code below but am
clueless how to find out the CPU Usage levels of hte process at any
given time.

You may be able to work something out using TotalProcessorTime, regularly
polling this value, keeping track of the difference in TotalProcessorTime,
divide by the difference in real time, divide by the number of processors,
and you have the average processor usage since the last time you polled.

Be aware that you shouldn't poll too often, and that you should Sleep() your
thread in between polls, otherwise you'll be the one eating all the CPU
time.
 
Back
Top