linux查詢內存使用率,linux c 獲取硬盤使用率,Linux通過c得到硬盤使用情況

 2023-11-11 阅读 30 评论 0

摘要:下面的代碼可以得到硬盤使用情況:#include #include #include #include #include #include #include #includestatic const char *ignore_fs[] = {"none", "proc", "sysfs", "devpts", "usbfs", "usbdevfs", NULL

下面的代碼可以得到硬盤使用情況:

#include #include #include #include #include #include #include #include

static const char *ignore_fs[] = {

"none", "proc", "sysfs", "devpts", "usbfs", "usbdevfs", NULL };

int main (int argc, char **argv)

linux查詢內存使用率?{

struct mntent?? *mnt;

struct statfs?? fsu;

FILE??????????? *fp;

char??????????? *table = MOUNTED;

long??????????? total, used, available, available_to_root;

docker查看內存占用、double????????? pct;

char??????????? **p;

int???????????? scale, flag = 0;

char??????????? buf[BUFSIZ];

memset (buf, 0, BUFSIZ);

fp = setmntent (table, "r");

硬盤使用率是什么回事,if (fp == NULL)

{

return -1;

}

while ((mnt = getmntent (fp)))

{

shell磁盤使用率。for (p = (char **)ignore_fs; *p; p++)

{

if (strcmp (mnt->mnt_fsname, *p) == 0)

{

flag = 1;

break;;

linux查看分區命令。}

}

if (flag)

{

flag = 0;

continue;

java獲取磁盤使用率。}

if (statfs (mnt->mnt_dir, &fsu) < 0)

{

return -1;

}

else

dockerfile cmd entrypoint。{

total = fsu.f_blocks;

available = fsu.f_bavail;

available_to_root = fsu.f_bfree;

used? = total - available_to_root;

scale = fsu.f_bsize / 1024;

dockerfile詳解、pct = 0;

if (total != 0 )

pct = (used * 100) / (used + available) + ((used *100) % (used

+ available) != 0);

fprintf (stdout, "%-15s %15s %10ld %10ld %10ld %9.0f%% %-s\n",

mnt->mnt_fsname, mnt->mnt_type, total*scale, used*scale,

開機磁盤使用率80?available*scale, pct, mnt->mnt_dir);

}

}

endmntent (fp);

return 0;

}

電腦磁盤使用率過高,[zhanghua@localhost ZA]$ gcc fsinfo.c -o fsinfo

[zhanghua@localhost ZA]$ ./fsinfo

/dev/sda2????????????????? ext3??? 5771500??? 5166820???? 311496??????? 95% /

/dev/sda1????????????????? ext3???? 101089?????? 9424????? 86446??????? 10% /boot

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/170744.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息