Skip to content

Commit 760fe8a

Browse files
committed
Fix cpu_info bug
Grepping the output of top could sometimes return the grep process, leading to a nonsensical %CPU reading.
1 parent 6a0d43b commit 760fe8a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

scripts/cpu_info.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ get_percent()
99
{
1010
case $(uname -s) in
1111
Linux)
12-
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
12+
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "[C]pu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
1313
normalize_percent_len $percent
1414
;;
1515

0 commit comments

Comments
 (0)