第2个回答 2017-08-28
#include#include#defineONE_MB(1024*1024)intmain(void){longnum_procs;longpage_size;longnum_pages;longfree_pages;longlongmem;longlongfree_mem;num_procs=sysconf(_SC_NPROCESSORS_CONF);printf("CPU个数为:%ld个\n",num_procs);page_size=sysconf(_SC_PAGESIZE);printf("系统页面的大小为:%ldK\n",page_size/1024);num_pages=sysconf(_SC_PHYS_PAGES);printf("系统中物理页数个数:%ld个\n",num_pages);free_pages=sysconf(_SC_AVPHYS_PAGES);printf("系统中可用的页面个数为:%ld个\n",free_pages);mem=(longlong)((longlong)num_pages*(longlong)page_size);mem/=ONE_MB;free_mem=(longlong)free_pages*(longlong)page_size;free_mem/=ONE_MB;printf("总共有%lldMB的物理内存,空闲的物理内存有:%lldMB\n",mem,free_mem);return(0);}