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. 菜鸡CodeFoces打卡单

    2017.12.13 1:05 签到3题 Educational Codeforces Round 34 (Rated for Div. 2) 补题:

  2. 贪心 Codeforces Round #109 (Div. 2) B. Combination

    题目传送门 /* 贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊! */ #include <cstdio> #include <algorithm> # ...

  3. 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  4. magento 自建插件通道服务

    首先建立如下的目录结构 在channel.xml中如此写上 <channel> <name>local</name> <uri>http://local ...

  5. linux系统添加java和glassfish环境变量

    第一种方法: 可以在/etc/profile里面增加 #java环境变量 JAVA_HOME=/home/harries/develop/jdk1.6.0_23export JRE_HOME=/hom ...

  6. AJPFX:关于面向对象的封装

    1.回顾        面向对象 -- 注重的是结果,强调的是具备功能的对象.        面向过程 -- 强调的是函数,注重的实现的过程.        函数:对功能的封装.            ...

  7. Linux之测试服务器和端口连通

    目录 wget工具 telnet工具 ssh工具 wget工具: 该工具是网络自动下载工具,如果linux或centos中不存在,需要先安装,支持http.https.ftp协议,wget名称的由来是 ...

  8. 微信小程序flex布局

    一.flex布局基础 二.相对定位和绝对定位   flex的容器和元素   主轴(左-右),交叉轴(上-下)     flex容器属性详解 flex-direction 决定元素的排列方向(默认row ...

  9. leetcode790 Domino and Tromino Tiling

    思路: dp.没有像discuss中的那样优化递推式. 实现: class Solution { public: ; int numTilings(int N) { vector<vector& ...

  10. ASP.NET中调用事务处理的方法

    /// <summary> /// 事务处理 /// </summary> /// <param name="strSql"></para ...