首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于在linux中获取CPU负载的c API

用于在linux中获取CPU负载的c API
EN

Stack Overflow用户
提问于 2009-07-29 07:31:48
回答 5查看 16.1K关注 0票数 13

在linux中,是否有一个内置的C库函数来获取机器的CPU负载?我可以编写自己的函数,在/proc中打开和解析文件,但似乎应该有更好的方法。

  • 不需要携带
  • 必须不需要基础RHEL4安装以外的任何库。
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2009-07-29 13:35:17

如果您真的想要一个c接口,请使用getloadavg(),它也可以在不使用/proc的unixes中工作。

它有一个包含所有细节的手册页

票数 12
EN

Stack Overflow用户

发布于 2009-07-29 07:54:08

在linux上获取有关CPU负载信息的首选方法是从/proc/stat/proc/loadavg/proc/uptime读取。所有普通的linux实用程序(如top )都使用此方法。

票数 8
EN

Stack Overflow用户

发布于 2009-07-29 11:52:46

来自proc (5)手册页:

代码语言:javascript
复制
   /proc/loadavg
          The  first  three  fields  in this file are load average figures
          giving the number of jobs in the run queue (state R) or  waiting
          for disk I/O (state D) averaged over 1, 5, and 15 minutes.  They
          are the same as the load average numbers given by uptime(1)  and
          other  programs.  The fourth field consists of two numbers sepaâ
          rated by a slash (/).  The first of these is the number of  curâ
          rently   executing   kernel   scheduling   entities  (processes,
          threads); this will be less than or equal to the number of CPUs.
          The  value  after  the  slash is the number of kernel scheduling
          entities that currently exist on the system.  The fifth field is
          the  PID  of  the  process that was most recently created on the
          system.
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1198573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档