From a7b4d1d4cd7b8d64067535cda61d687ad5a864d4 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Thu, 28 Oct 2021 14:54:50 +0200
Subject: [PATCH] check_cpu - Use 2nd update of top

---
 check_cpu | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/check_cpu b/check_cpu
index ae97bcf..581d1e5 100755
--- a/check_cpu
+++ b/check_cpu
@@ -13,6 +13,7 @@
 # 2020-07-08  v1.2  <axel.hahn@iml.unibe.ch> FIX: set "ph." instead "ps."
 # 2020-07-17  v1.3  <axel.hahn@iml.unibe.ch> use ph.require to check binaries
 # 2021-02-10  v1.4  <axel.hahn@iml.unibe.ch> added critical io wait
+# 2021-10-28  v1.5  <axel.hahn@iml.unibe.ch> Use 2nd update of top
 # ======================================================================
 
 
@@ -27,7 +28,7 @@ function showHelp(){
 cat <<EOF
 ______________________________________________________________________
 
-CHECK_CPU check cpu usage and cpu wait v1.4
+CHECK_CPU check cpu usage and cpu wait v1.5
 
 (c) Institute for Medical Education - Univerity of Bern
 Licence: GNU GPL 3
@@ -90,7 +91,9 @@ typeset -i iCriticalWait=`  ph.getValueWithParam 50 i "$@"`
 #   hi : time spent servicing hardware interrupts
 #   si : time spent servicing software interrupts
 #   st : time stolen from this vm by the hypervisor
-top -b -n 1 | head -5 | grep "^\%Cpu" >$tmpfile
+# top -b -n 1 | head -5 | grep "^\%Cpu" >$tmpfile
+# FIX read cpu from 2nd output of top
+top -b -n 2 -d 0.1 | grep -i "^\%Cpu" | tail -1 >$tmpfile
 
 cpuUser=`   awk '{ print $2 }' $tmpfile`
 cpuSystem=` awk '{ print $4 }' $tmpfile`
-- 
GitLab