下面的代码可以得到硬盘使用情况:
#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)
{
struct mntent *mnt;
struct statfs fsu;
FILE *fp;
char *table = MOUNTED;
long total, used, available, available_to_root;
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)))
{
for (p = (char **)ignore_fs; *p; p++)
{
if (strcmp (mnt->mnt_fsname, *p) == 0)
{
flag = 1;
break;;
}
}
if (flag)
{
flag = 0;
continue;
}
if (statfs (mnt->mnt_dir, &fsu) mnt_fsname, mnt->mnt_type, total*scale, used*scale,
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
Linux下如何检查硬盘使用情况
转载请注明出处:服务器评测 » Linux下如何检查硬盘使用情况
相关推荐
- *██ 双倍 RAM 回归 ██ AMD RYZEN 7 █ 128GB RAM █ 1TB NVMe █ IPMI █ /24 IPv4 ██ 24 美元起
- *可解锁住宅 ISP,提供无限量 10G(抓取、流媒体、票务、SEO)
- 中国优化云服务器 香港/洛杉矶 低至2.9,BM美国E5/16g/1T仅19.9起,站群/10G独享服务器七折等更多活动请查看详情 – CST Server
- 云建站好用吗?云速建站与传统网站的区别
- windows云服务器远程桌面怎样实现复制粘贴?
- 买云服务器需要单独购买硬盘吗?易探云服务器有赠送数据盘吗?
- 泰国云服务器怎么选择?东南亚地区云服务器选择
- 买云服务器挖chia币靠谱吗?租云服务器能不能挖chia币?