Linux sysinfo获取系统相关信息

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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

posted on   深入浅出eBPF  阅读(2430)  评论(0编辑  收藏  举报

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示