标签:code proc rate ble 1.0 double can return pen
#define SYS_MEM_NAME_LEN 20
#define SYS_MEM_BUFF_LEN 256
#define SYS_100_PERSENT 100
int
get_sysMemUsage()
{
FILE *fd;
char buff[SYS_MEM_BUFF_LEN];
double mem_used_rate;
char name01[SYS_MEM_NAME_LEN];
unsigned long mem_total;
char name02[SYS_MEM_NAME_LEN];
char name11[SYS_MEM_NAME_LEN];
unsigned long mem_free;
char name12[SYS_MEM_NAME_LEN];
fd = fopen ("/proc/meminfo", "r");
fgets (buff, sizeof(buff), fd);
sscanf (buff, "%s %lu %s\n", name01, &mem_total, name02);
fgets (buff, sizeof(buff), fd);
sscanf (buff, "%s %lu %s\n", name11, &mem_free, name12);
mem_used_rate = (1.0 - (double)mem_free/(double)mem_total) * SYS_100_PERSENT;
fclose(fd);
return mem_used_rate;
}
标签:code proc rate ble 1.0 double can return pen
原文地址:http://blog.51cto.com/qiaopeng688/2140584