The cpu_percentage value on linux does not show the current CPU load, but the overall average CPU load since the computer was started. I guess this is not intentional.
On linux there simply is no easy way (without installing strange extra packages) to get the current CPU load in a range of 0-100%.
The following might be considered as an alternative, but it gives values >100% (due to ps' way of calculating CPU loads):
More exact, but requires bc:
printf "%.0f\n" $(ps -A -o pcpu | tail -n+2 | paste -sd+ | xargs -i echo "(" {} ") / $(nproc)" | bc)
Does the job without bc, in zsh you wouldn't need the sed part:
`echo $(($(ps -A -o pcpu | tail -n+2 | paste -sd+ | sed 's/.[0-9]//g' | xargs -i echo "(" {} ") / $(nproc)")))``
The cpu_percentage value on linux does not show the current CPU load, but the overall average CPU load since the computer was started. I guess this is not intentional.
On linux there simply is no easy way (without installing strange extra packages) to get the current CPU load in a range of 0-100%.
The following might be considered as an alternative, but it gives values >100% (due to ps' way of calculating CPU loads):
More exact, but requires bc:
printf "%.0f\n" $(ps -A -o pcpu | tail -n+2 | paste -sd+ | xargs -i echo "(" {} ") / $(nproc)" | bc)
Does the job without bc, in zsh you wouldn't need the sed part: `echo $(($(ps -A -o pcpu | tail -n+2 | paste -sd+ | sed 's/.[0-9]//g' | xargs -i echo "(" {} ") / $(nproc)")))``