码迷,mamicode.com
首页 > 编程语言 > 详细

ubuntu下C/C++获取剩余内存

时间:2019-04-26 20:54:13      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:ubunt   conf   nbsp   size   \n   style   std   ret   turn   

#include <stdio.h>
#include <unistd.h>
long get_memory_usage()
{
    long page_size = sysconf (_SC_PAGESIZE);
    long num_pages = sysconf (_SC_PHYS_PAGES);
    long mem = (num_pages/1024) * (page_size/1024);
    long long free_pages = sysconf (_SC_AVPHYS_PAGES);
    long long free_mem = (free_pages/1024) * (page_size/1024);
    fprintf(stderr,"Memory %lld MB\\%lld MB.\n", mem, free_mem);
    return (long)(free_mem);
}

 

ubuntu下C/C++获取剩余内存

标签:ubunt   conf   nbsp   size   \n   style   std   ret   turn   

原文地址:https://www.cnblogs.com/aimhabo/p/10776456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!