getrlimit读取进程能打开的最大文件描述符

         getrlimit,setrlimit - 控制系统资源的最大使用量

#include 
#include 
#include 


/*struct rlimit{  
    rlim_t rlim_cur;   //soft limit: current limit  
    rlim_t rlim_max;  //hard limit: maximum value for rlim_cur  
}*/  


int main()
{
  struct rlimit limit;
  getrlimit(RLIMIT_NOFILE,&limit);
  printf("rlim_cur =%ld,rlim_max =%ld\n",limit.rlim_cur,limit.rlim_max);

  struct rlimit limit1;	
  limit1={100,1000};
  setrlimit(RLIMIT_NOFILE,&limit1);
  printf("rlim_cur =%ld,rlim_max =%ld\n",limit1.rlim_cur,limit1.rlim_max);
  
  
  return 0;
}

打印:rlim_cur =1024,rlim_max =4096
           rlim_cur =100,rlim_max =1000

可以进行设置和读取。

 

更详细见:https://www.cnblogs.com/niocai/archive/2012/04/01/2428128.html

你可能感兴趣的:(linux)