대답 CPU 백분율 을 사용할 수 있습니다 .
While(1) { $p = get-counter '\Process(*)\% Processor Time'; cls;
$p.CounterSamples | sort -des CookedValue | select -f 15 | ft -a}
이제 컴퓨터의 작업에 대해 메모리 사용량과 CPU 백분율을 동시에 표시하는 데 문제가 있습니다. 나는 Get-Counter "\Process(*)\Working Set - Private"
메모리를 얻을 것이지만 id는 작업, CPU % 및 메모리 사용량이 동시에 표시되는 것을 좋아합니다.
업데이트 1 : 이상적으로 나는 이것을 일련의 명령으로 powershell에서 실행할 수 있기를 바랍니다. 출력을 다음과 같이 표시하고 싶습니다.
Process Name CPU (%) Memory (MB) ------------ ------- -----------
세 가지 항목 만 powershell에 표시 한 후 처리 할 수있는 디스플레이에 관해서는 얻을 수있는 것을 가져 가겠습니다.
업데이트 2 : 이 코드 섹션은 내가 원하는 것을 제공합니다.
while (1) {cls; Get-WmiObject Win32_PerfFormattedData_PerfProc_Process |
select-object -property Name, PercentProcessorTime, IDProcess, @{"Name" = "WSP(MB)"; Expression = {[int]($_.WorkingSetPrivate/1mb)}} |
? {$_.Name -notmatch "^(idle|_total|system)$"} |
Sort-Object -Property PercentProcessorTime -Descending|
ft -AutoSize |
Select-Object -First 15; start-sleep 5}
결과는 다음과 같습니다.
Name PercentProcessorTime IDProcess WSP(MB)
---- -------------------- --------- -------
MicrosoftEdgeCP#3 6 18972 6 WmiPrvSE#3 6 27300 7
svchost#22 0 7316 1
이것의 단점은 정보를 한 번 표시 한 후에 실패하고 이유를 모르겠다는 것입니다. 이것에 어떤 도움이 있습니까?
업데이트 : 3
$cores = (Get-WmiObject Win32_Processor).NumberOfLogicalProcessors
while ($true) {
$tmp = Get-WmiObject Win32_PerfFormattedData_PerfProc_Process |
select-object -property Name, @{Name = "CPU"; Expression = {($_.PercentProcessorTime/$cores)}}, @{Name = "PID"; Expression = {$_.IDProcess}}, @{"Name" = "Memory(MB)"; Expression = {[int]($_.WorkingSetPrivate/1mb)}} |
Where-Object {$_.Name -notmatch "^(idle|_total|system)$"} |
Sort-Object -Property CPU -Descending|
Select-Object -First 15;
cls;
$tmp | Format-Table -Autosize -Property Name, CPU, PID, "Memory(MB)";
Start-Sleep 5
}
내가 필요한 모든 것을 성취하고 미래에 구축 할 출발점을 제공합니다. 테이블 포매터에서 내가 가진 문제는 그것이 format-table
마지막이어야한다는 것입니다.
WMI를 통해 성능 카운터를 쿼리하는 또 다른 방법이 있습니다. 출력에는 여러 인스턴스가있는 프로세스를 추적 할 때 유용한 프로세스 ID도 포함됩니다. 또한 select-object
작업 집합 값을 바이트에서 메가 바이트로 변환하기 위해 내에서 "계산 된 속성"이라고하는 것을 사용합니다 . 또한 4 코어 시스템의 최대 CPU는 100이 아니라 400입니다. 따라서 전체 사용률 (최대 100)을 얻으려면 각 프로세스의 CPU 값을 코어 수로 나눠야합니다.
$cores = (Get-WmiObject Win32_Processor).NumberOfLogicalProcessors
while ($true) {
Get-WmiObject Win32_PerfFormattedData_PerfProc_Process |
Where-Object {$_.Name -notmatch "^(idle|_total|system)$" -and $_.PercentProcessorTime -gt 0} |
Format-Table -Autosize -Property @{Name = "CPU"; Expression = {[int]($_.PercentProcessorTime/$cores)}}, Name, @{Name = "PID"; Expression = {$_.IDProcess}}, @{"Name" = "WSP(MB)"; Expression = {[int]($_.WorkingSetPrivate/1mb)}}
Start-Sleep 5
}
CPU Name PID WSP(MB)
--- ---- --------- -------
1 chrome 12476 64
2 wuauclt 7504 0
3 SearchIndexer 10128 22
4 TIworker 11380 102
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다