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

#include stdio.h#include unistd.hlong 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 ...

#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++获取剩余内存

基础教程推荐