Linux SysInfo Obtaining system-related information

Source: Internet
Author: User

Linux, you can use SysInfo to get information about your system.

 #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 copy directly from the Nroff source, remember to * REMOVE the extra backslashes in the printf state ment.           */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%l u\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 Obtaining system-related information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.