Process CPU Usage

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.
 
S

Sven Groot

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top