- Published on
Bash/Powershell コマンドラインからCPU使用率を出力する
- Authors
- Name
- Shou Arisaka / 有坂翔
LinuxのWSL BashやWindowsのcmd.exe、Powershellなどのコマンドライン上から、CPU使用率を出力する方法について紹介します。
![https://yuis.xsrv.jp/images/ss/ShareX_ScreenShot_723fe640-94cc-4e27-bb74-eccf0d644a09.png](https://yuis.xsrv.jp/images/ss/ShareX_ScreenShot_723fe640-94cc-4e27-bb74-eccf0d644a09.png)
Bashの場合
grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'
Powershellの場合
$( Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average ).Average
C#とかでやりたい場合に参考にどうぞ
get cpu usage site:stackoverflow.com - Google Search