linux下getrlimit与sysconf函数
生活随笔
收集整理的這篇文章主要介紹了
linux下getrlimit与sysconf函数
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>int main(int argc, char *argv[])
{struct rlimit nofile_rlmt;if (getrlimit(RLIMIT_NOFILE, &nofile_rlmt) != -1) {printf("獲取進(jìn)程最大能打開的文件描述符個(gè)數(shù)信息:\n""rlim_cur(Soft limit):%d""\nrlim_max(Hard limit (ceiling for rlim_cur)): %d\n",nofile_rlmt.rlim_cur, nofile_rlmt.rlim_max);}
}
getrlimit與setlimit函數(shù)詳解可以參照:
http://www.cnblogs.com/niocai/archive/2012/04/01/2428128.html
#include <stdio.h> #include <stdlib.h> #include <unistd.h> //sysconf#define ONE_MB (1024 * 1024)int main(int argc, char **argv[]) {long num_cpu = sysconf(_SC_NPROCESSORS_ONLN);printf("CUP的個(gè)數(shù):%ld\n", num_cpu);long page_size = sysconf(_SC_PAGESIZE);printf("系統(tǒng)頁(yè)面的大小:%ld K\n", page_size);long num_pages = sysconf(_SC_PHYS_PAGES);printf("系統(tǒng)中物理頁(yè)面?zhèn)€數(shù):%ld 個(gè)\n", num_pages);long free_pages = sysconf(_SC_AVPHYS_PAGES);printf("系統(tǒng)中可用的頁(yè)面?zhèn)€數(shù):%ld 個(gè)\n", free_pages);long long mem = (long long)((long long)num_pages * (long long)page_size);mem /= ONE_MB;long long free_mem = (long long)((long long)free_pages * (long long)page_size);free_mem /= ONE_MB;printf("總共有 %lld MB的物理內(nèi)存,空閑的物理內(nèi)存有 %lld MB\n", mem, free_mem);long open_max = sysconf(_SC_OPEN_MAX);printf("每個(gè)進(jìn)程最大打開的文件個(gè)數(shù):%ld\n", open_max); return 0; }sysconf、pathconf、fpathconf函數(shù)詳解參照:
http://xingyunbaijunwei.blog.163.com/blog/static/7653806720119122344450/
總結(jié)
以上是生活随笔為你收集整理的linux下getrlimit与sysconf函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 本地缓存之Guava简单使用
- 下一篇: 通过jquery回显操作(笔记)