AIX下C语言取得Load值

    在AIX下可以用libperfstat包来方便地取得Load Average的三个值.

#include <stdio.h>
#include <sys/time.h>
#include <sys/proc.h>
#include <libperfstat.h>

int main(int argc, char *argv[])
{
  perfstat_cpu_total_t cpu_total_buffer;
  perfstat_cpu_total(NULL, &cpu_total_buffer,
          sizeof(perfstat_cpu_total_t), 1);
  while(1 == 1)
  {
    sleep(10);
    perfstat_cpu_total(NULL, &cpu_total_buffer,
        sizeof(perfstat_cpu_total_t), 1);
    printf("%5.2f,%5.2f,%5.2f\n",
        1.0*cpu_total_buffer.loadavg[0]/(1<< SBITS),
  1.0*cpu_total_buffer.loadavg[1]/(1<< SBITS),
        1.0*cpu_total_buffer.loadavg[2]/(1<< SBITS));
  }
}

    在编译时用如下选项:

gcc -l perfstat ...

    在Google中找一下libperfstat, 可以找到更多的资料.

留言 (2)

系统里我都部署过了

借宝地问一下:我本机安装了oracle 8i,已关闭监听,网络上的其他机子是否可以侦查到我安装的数据库?

//公司屏蔽了论坛

发表留言:

« Previous | Main | Next »

英语900句 | English 900

  • Excuse me, madam. Could you tell me where the post office is?
  • 对不起, 女士, 请问邮局在哪里?
  • It's just around the corner.
  • 转弯就是.
  • Excuse me, how can I get to the bus station?
  • 对不起, 汽车站怎么走?
  • You can take the bus and get off at the second stop.
  • 你可以坐公共汽车第二站下.
  • Excuse me. Where is No.5 Street?
  • 对不起, 第五大街在哪儿?