Getrlimit and sysconf functions under Linux

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.