Get Memory Utilization (Linux C)

Source: Internet
Author: User
#define SYS_MEM_NAME_LEN 20#define SYS_MEM_BUFF_LEN 256#define SYS_100_PERSENT 100intget_sysMemUsage(){ FILE *fd; char buff[SYS_MEM_BUFF_LEN]; double mem_used_rate; char name01[SYS_MEM_NAME_LEN]; unsigned long mem_total; char name02[SYS_MEM_NAME_LEN]; char name11[SYS_MEM_NAME_LEN]; unsigned long mem_free; char name12[SYS_MEM_NAME_LEN]; fd = fopen ("/proc/meminfo", "r"); fgets (buff, sizeof(buff), fd); sscanf (buff, "%s %lu %s\n", name01, &mem_total, name02); fgets (buff, sizeof(buff), fd); sscanf (buff, "%s %lu %s\n", name11, &mem_free, name12); mem_used_rate = (1.0 - (double)mem_free/(double)mem_total) * SYS_100_PERSENT; fclose(fd); return mem_used_rate;}

Get Memory Utilization (Linux C)

Related Article

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.