In a bash script I need to wait until CPU usage gets below a threshold.
In other words, I'd need a command wait_until_cpu_low which I would use like this:
# Trigger some background CPU-heavy command wait_until_cpu_low 40 # Some other commands executed when CPU usage is below 40% How could I do that?
Edit:
- target OS is: Red Hat Enterprise Linux Server release 6.5
- I'm considering the average CPU usage (across all cores)
yum install sysstat, thenmpstat -P ALL 1 | grep all | awk '{print $9}'should get you in the ballpark of the idle % on all CPU. That said, you could also clarify the question by specifying whether the threshold is percentage "idle" or "used".100% * NumCPUs. So is that 40% meaning "40% of maximum CPU usage" or "40% as the system reports it"?