确定CPU使用率 [英] Determining CPU utilization

查看:170
本文介绍了确定CPU使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个命令或任何其他方式在Linux中获取当前或平均 CPU利用率(用于多处理器环境)?

Is there a command or any other way to get the current or average CPU utilization (for a multi-processor environment) in Linux?

我在一个小系统中使用嵌入式Linux。基本上,我需要确定CPU利用率,因此,如果它是高的,我可以代替转移的新工艺到另一个控制器在系统中,而不是主处理器,它可以是忙于一个更重要的过程上执行的。

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.

这问题不是仅仅优先处理,其他控制器足以处理新工艺,只是当主处理器不忙,我想preFER它做的执行。

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.

推荐答案

您需要两次采样在的/ proc / STAT 的值,并计算平均利用率在这段时间。 (瞬时利用率不作一大堆意义 - 它永远是单核的机器上100%,因为你的utilsation测量code运行时,它看起来)。

You need to sample the values in /proc/stat at 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).

这篇关于确定CPU使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆