Get disk usage (Linux C)

Source: Internet
Author: User
Tags disk usage
#define SYS_DISK_BUFF_LEN 256#define SYS_DISK_NAME_LEN 80#define SYS_100_PERSENT 100intget_sysDiskUsage(){ FILE * fp; char filesystem[SYS_DISK_NAME_LEN],available[SYS_DISK_NAME_LEN],use[SYS_DISK_NAME_LEN],mounted[SYS_DISK_NAME_LEN],buf[SYS_DISK_BUFF_LEN]; double used,blocks,used_rate; fp=popen("df","r"); fgets(buf,SYS_DISK_BUFF_LEN,fp); double dev_total = 0,dev_used = 0; while(6 == fscanf(fp,"%s %lf %lf %s %s %s",filesystem,&blocks,&used,available,use,mounted)) { dev_total += blocks; dev_used += used; } used_rate = (dev_used/dev_total)*SYS_100_PERSENT; pclose(fp); return used_rate;}

Get disk usage (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.