fd的数量决定了fd的最大值

在Linux下,系统全部能够打开的fd总数为:

/proc/sys/fs/file-max,取决于内存

The file-max file /proc/sys/fs/file-max sets the maximum number of file-handles that the Linux kernel will allocate. We generally tune this file to improve the number of open files by increasing the value of /proc/sys/fs/file-max to something reasonable like 256 for every 4M of RAM we have: i.e. for a machine with 128 MB of RAM, set it to 8192 - 128/4=32 32*256=8192.

/proc/sys/fs/file-nr 记录系统中fd的使用情况,已分配文件句柄的数目 
已使用文件句柄的数目 
文件句柄的最大数目 ,

单个进程能够打开的最大fd数量为 ulimit -n, 可以通过sysconf(_SC_OPEN_MAX)获取默认的进程fd打开数量。

修改fd限制可以先修改shell的ulimit -n,

或者通过setrlimit函数进行修改:

void modifyfdlimit()
{
 rlimit fdLimit;

fdLimit.rlim_cur = 30000;
 fdLimit.rlim_max = 30000;

if (-1 == setrlimit (RLIMIT_NOFILE, &fdLimit))
 {
  printf ("Set max fd open count fai. /nl");

char cmdBuffer [64];
  sprintf (cmdBuffer, "ulimit -n %d", 30000);

if (-1 == system (cmdBuffer))
  {
   printf("%s failed. /n", cmdBuffer);

exit(0);
  }

if (-1 == getrlimit (RLIMIT_NOFILE, &fdLimit))
  {
   printf("Ulimit fd number failed.");

exit(0);
  }
 }

//printf("Hard limit: %d. Soft limit: %d", fdLimit.rlim_max, fdLimit.rlim_cur);
}

http://blog.csdn.net/pmunix/article/details/2416498

fd最大值和限制的更多相关文章

  1. (十二)select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET

    select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供select函数来实现多路复用输入/输出模型,原型:int select(int maxfd,fd_set *rdset ...

  2. select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET

    http://hi.baidu.com/%B1%D5%C4%BF%B3%C9%B7%F0/blog/item/e7284ef16bcec3c70a46e05e.html select函数用于在非阻塞中 ...

  3. select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET(转)

    select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供select函数来实现多路复用输入/输出模型, 原型: int select(int maxfd,fd_set *rds ...

  4. socket基础函数(2)

    http://www.cnblogs.com/RascallySnake/archive/2013/07/11/3185071.html   一.select  winsock中 #include & ...

  5. select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET (转)

    select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供select函数来实现多路复用输入/输出模型,原型: #include <sys/time.h>       ...

  6. I/O多路转接之select

    系统提供select函数来实现多路复⽤用输入/输出模型.select系统调用是用来让我们的程序监视 多个文件句柄的状态变化的.程序会停在select这里等待,直到被监视的文件句柄有一个或 多个发生了状 ...

  7. 异步套接字基础:select函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET

    参考:[原创]技术系列之 网络模型(三)多路复用模型 select函数 select函数: 系统提供select函数来实现多路复用输入/输出模型.原型: #include <sys/time.h ...

  8. linux网络编程:select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET(转)

    从别人的博客中转载过来了这一篇文章,经过重新编辑排版之后展现于此,做一个知识点保存与学习. select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供select函数来实现多路复 ...

  9. Linux编程之select

    select系统调用的的用途是:在一段指定的时间内,监听用户感兴趣的文件描述符上可读.可写和异常等事件. select 机制的优势 为什么会出现select模型? 先看一下下面的这句代码: int i ...

随机推荐

  1. fastboot命令详解

    Android手机分区(每个分区都有相应的img文件对应):开机启动画面区(splash1),数据恢复区(recovery),内核区(boot), 系统区(system),数据缓存区(cache),用 ...

  2. [书目20140902]实战Windows Azure——微软云计算平台技术详解 --徐子岩

    目录第1章  云计算技术简介    1.1  云计算所要解决的问题    1.2  云计算平台的分类    1.3  微软云计算平台Windows Azure        1.3.1  高可用性   ...

  3. SCANF输入错误

    while((a<=0||a>=10)||(b<=0||b>=10))    {        fflush(stdin);        cout<<" ...

  4. 最新版Kubernetes常用命令大全

    #查看所有namespace的pods运行情况 kubectl get pods --all-namespaces #查看具体pods,记得后边跟namespace名字哦 kubectl get po ...

  5. REMOVE A WINDOWS SERVICE

    You can easily remove a Windows service from the Windows registry using a simple command prompt comm ...

  6. 关于docker入门教程

    简介:docker入门教程 docker入门教程翻译自docker官方网站的Docker getting started 教程,官方网站:https://docs.docker.com/linux/s ...

  7. 基于ANGULAR.JS的下一代WEB应用开发-01-yeoman

    Angularjs 个人认为这是一款很好的框架!它将我们从AJAX应用的开发中解救了出来!嗯....废话就说道这里下面我们开始把! 首先我们必须了解一些核心的概念: 客户端模版 MVC 数据绑定 依赖 ...

  8. Dynamic type checking and runtime type information

    动态类型的关键是将动态对象与实际类型信息绑定. See also: Dynamic programming language and Interpreted language Dynamic type ...

  9. Android 关于文件及文件夹的创建 、删除、重命名、复制拷贝

    package com.example.administrator.myapplication.util; import java.io.BufferedReader;import java.io.B ...

  10. 【转】Web 前沿——HTML5 Form Data 对象的使用

    XMLHttpRequest Level 2 添加了一个新的接口——FormData.利用 FormData 对象,我们可以通过 JavaScript 用一些键值对来模拟一系列表单控件,我们还可以使用 ...