Linux,实时获取磁盘空间

 1 #include <iostream>
 2 #include <stdlib.h>
 3 #include <stdio.h>
 4 #include <sys/statfs.h>
 5 #include <string>
 6 
 7 using std::cout;
 8 using std::endl;
 9 using std::string;
10 
11 int main()
12 {
13     FILE *pFile = fopen("test", "rw");
14     string strPath("/root");
15 
16     fclose(pFile);
17     struct statfs tagStatfs;
18     statfs(strPath.c_str(), &tagStatfs);
19 
20     while(1) {
21         statfs(strPath.c_str(), &tagStatfs);
22         cout<<"tagStatfs.f_bfree = "<<tagStatfs.f_bfree<<endl;
23         sleep(1);
24     }
25 
26     return 0;
27 }

 

posted @ 2013-07-02 01:46  素色江南  阅读(256)  评论(0)    收藏  举报