首页 > 系统服务 > 详细

Linux sysinfo获取系统相关信息

时间:2016-01-21 18:57:40      阅读:345      评论:0      收藏:0      [点我收藏+]

Linux中,可以用sysinfo来获取系统相关信息。

 #include <stdio.h>
       #include <stdlib.h>
       #include <errno.h>
       #include <linux/unistd.h>       /* for _syscallX macros/related stuff */
       #include <linux/kernel.h>       /* for struct sysinfo */

       //_syscall1(int, sysinfo, struct sysinfo *, info);

       /* Note: if you copy directly from the nroff source, remember to
 *        REMOVE the extra backslashes in the printf statement. */

       int
       main(void)
       {
           struct sysinfo s_info;
           int error;

           error = sysinfo(&s_info);
           printf("code error = %d\n", error);
           printf("Uptime = %lds\nLoad: 1 min %lu / 5 min %lu / 15 min %lu\n"
                  "RAM: total %lu / free %lu / shared %lu\n"
                  "Memory in buffers = %lu\nSwap: total %lu / free %lu\n"
                  "Number of processes = %d\n",
                  s_info.uptime, s_info.loads[0],
                  s_info.loads[1], s_info.loads[2],
                  s_info.totalram, s_info.freeram,
                  s_info.sharedram, s_info.bufferram,
                  s_info.totalswap, s_info.freeswap,
                  s_info.procs);
           exit(EXIT_SUCCESS);
       }

  

 

code error = 0
Uptime = 47428s
Load: 1 min 192 / 5 min 2272 / 15 min 2976
RAM: total 1027239936 / free 249516032 / shared 0
Memory in buffers = 0
Swap: total 2147479552 / free 2092707840
Number of processes = 391

Linux sysinfo获取系统相关信息

原文:http://www.cnblogs.com/davad/p/5148522.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!