■ PerformanceCounter 클래스를 사용해 인스턴스명으로 프로세스 CPU 사용률을 구하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
string instanceName = "notepad#1"; // 두번째 메모장 프로그램인 경우 PerformanceCounter counter = new PerformanceCounter("Process", "% Processor Time", instanceName); for(int i = 0; i < 10; i++) { float cpuRate = counter.NextValue(); Console.WriteLine("인스턴스명 : {0}, CPU 사용률 : {1}", instanceName, cpuRate); Thread.Sleep(1000); } |