下面的代码可以得到硬盘使用情况:
#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下如何检查硬盘使用情况
相关推荐
- Hivelocity黑色星期五钜惠:专属服务器享终身35%优惠或前半年5折抢购!
- 高性价比独立服务器 ★ 月付仅$28起 ★ 12TB硬盘特惠 ★ IPMI远程管理 ★ 内存流量双倍赠送!
- 多伦多专属服务器 – 戴尔R220 & R260 | 托管优化版 | 月付仅49加元起
- DEDICATED.COM – 英特尔®至强™双 E5-2630v4 |128GB – 2 个 2TB 固态硬盘 |129.99 美元
- drServer.net |||经济实惠的美国 SSD 专用服务器 |快速配置 |不限流量
- ▌新鲜烘焙托管▐▌仅需 39 美元起▐▌#Super 便宜
- 欧盟/美国/亚洲 |1Gbit/10Gbit 不限流量服务器 |起价 @$14.99 |存储、GPU、流媒体、10%
- InterServer – 买 1 送 2 – 托管优惠
服务器评测





