#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <errno.h>
#include <string>
using namespace std;
int main(int argc,char** agrv)
{
FILE *fd;
char buff[256];
int total = 0;
int free = 0;
float use=0;
fd = fopen ("/proc/meminfo", "r");
fgets (buff, sizeof(buff), fd);
sscanf (buff, "%*s %d %*s", &total);
fgets (buff, sizeof(buff), fd);
sscanf (buff, "%*s %d %*s", &free);
use=(float)((total-free) /(total * 0.01));//百分比
fclose(fd);
cout<<"use:"<<use<<endl;
return 0;
}
获取linux可用内存 剩余内存
最新推荐文章于 2024-03-04 21:32:01 发布