码迷,mamicode.com
首页 > 系统相关 > 详细

Linux sysinfo获取系统相关信息

时间:2016-01-21 18:58:42      阅读:237      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!