private static void Process_time()
{
int intInterval = 1000; // 1 second
string procName = "ProcessName";
while (true)
{
Process[] runningNow = Process.GetProcesses();
foreach (Process process in runningNow)
{
using (PerformanceCounter pcProcess = new PerformanceCounter("Process", "% Processor Time", process.ProcessName))
{
if (process.ProcessName == procName)>
{
pcProcess.NextValue();
System.Threading.Thread.Sleep(1000);
Console.WriteLine("Process:{0} CPU% {1}", process.ProcessName, pcProcess.NextValue());
//if (pcProcess.NextValue() > float.Parse("10");
// process의 점유율을 체크하여 10 이상이면 kill
//{
// Console.WriteLine(string.Format("Killing {0} at {1}", procName, DateTime.Now.ToString()));
// process.Kill();
//}
}
}
}
// Sleep till the next loop
Thread.Sleep(intInterval);
}
}[C#] CPU usage 측정, process kill
2011. 6. 14. 15:06