#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 ("Gets the maximum number of file descriptors the process can open: \ 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 and Setlimit functions can be explained by:
Http://www.cnblogs.com/niocai/archive/2012/04/01/2428128.html
#include <stdio.h> #include <stdlib.h> #include <unistd.h>//sysconf#define one_mb (1024x768 * 1024x768) int Main (int argc, char **argv[]) { Long num_cpu = sysconf (_SC_NPROCESSORS_ONLN); printf ("Number of Cups:%ld\n", num_cpu); Long page_size = sysconf (_sc_pagesize); printf ("Size of system page:%ld k\n", page_size); Long num_pages = sysconf (_sc_phys_pages); printf ("Number of physical pages in system:%LD \ n", num_pages); Long free_pages = sysconf (_sc_avphys_pages); printf ("Number of pages available in the system:%LD \ 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 ("A total of%lld MB of physical memory, free physical memory has%lld mb\n", Mem, free_mem); Long Open_max = sysconf (_sc_open_max); printf ("Maximum number of files per process:%ld\n", Open_max); return 0;}
Sysconf, pathconf, fpathconf function Detailed reference:
Http://xingyunbaijunwei.blog.163.com/blog/static/7653806720119122344450/
Getrlimit and sysconf functions under Linux