Is there a command or any other way to get the current or average CPU utilization (for a multi-processor environment) in Linux?
I am using embedded Linux in a small system. Basically, I need to determine the CPU utilization, so that if it is high, I can instead divert a new process to another controller in the system, rather than executing on the main processor, which could be busy doing a more important process.
This question is not about merely prioritizing processes, the other controller can sufficiently handle the new process, just that when the main processor is not busy, I would prefer it to do the execution.
You need to sample the values in
/proc/statat two times, and calculate the average utilisation over that time. (Instantaneous utilisation doesn’t make a whole lot of sense – it’ll always be 100% on a single core machine, since your utilsation-measuring code is running whenever it looks).