From 6757a5329948f00addd66b02ea94f61dd94456f5 Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Mon, 28 Dec 2020 11:41:54 -0500 Subject: [PATCH] Fix cpu usage bug on MacOSX/darwin --- scripts/cpu_info.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index cc10c9d..9b845ef 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -23,7 +23,10 @@ get_percent() ;; Darwin) - percent=$(ps -A -o %cpu | awk '{s+=$1} END {print s "%"}') + cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}') + cpucores=$(sysctl -n hw.logicalcpu) + cpuusage=$(( cpuvalue / cpucores )) + percent="$cpuusage%" echo $percent ;;