Name of the process with highest cpu usage

前端 未结 8 1298
栀梦
栀梦 2021-01-18 08:05

I have a Samurize config that shows a CPU usage graph similar to Task manager.

How do I also display the name of the process with the current highest CPU usage per

8条回答
  •  猫巷女王i
    2021-01-18 08:26

    Thanks for the formula, Jorge. I don't quite understand why you have to divide by the number of cores, but the numbers I get match the Task Manager. Here's my powershell code:

    $procID = 4321
    
    $time1 = Get-Date
    $cpuTime1 = Get-Process -Id $procID | Select -Property CPU
    
    Start-Sleep -s 2
    
    $time2 = Get-Date
    $cpuTime2 = Get-Process -Id $procID | Select -Property CPU
    
    $avgCPUUtil = ($cpuTime2.CPU - $cpuTime1.CPU)/($time2-$time1).TotalSeconds *100 / [System.Environment]::ProcessorCount
    

提交回复
热议问题