fd最大值和限制
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最大值和限制的更多相关文章
- (十二)select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET
select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供select函数来实现多路复用输入/输出模型,原型:int select(int maxfd,fd_set *rdset ...
- 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函数用于在非阻塞中 ...
- select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET(转)
select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供select函数来实现多路复用输入/输出模型, 原型: int select(int maxfd,fd_set *rds ...
- socket基础函数(2)
http://www.cnblogs.com/RascallySnake/archive/2013/07/11/3185071.html 一.select winsock中 #include & ...
- select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET (转)
select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供select函数来实现多路复用输入/输出模型,原型: #include <sys/time.h> ...
- I/O多路转接之select
系统提供select函数来实现多路复⽤用输入/输出模型.select系统调用是用来让我们的程序监视 多个文件句柄的状态变化的.程序会停在select这里等待,直到被监视的文件句柄有一个或 多个发生了状 ...
- 异步套接字基础:select函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET
参考:[原创]技术系列之 网络模型(三)多路复用模型 select函数 select函数: 系统提供select函数来实现多路复用输入/输出模型.原型: #include <sys/time.h ...
- linux网络编程:select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET(转)
从别人的博客中转载过来了这一篇文章,经过重新编辑排版之后展现于此,做一个知识点保存与学习. select函数用于在非阻塞中,当一个套接字或一组套接字有信号时通知你,系统提供select函数来实现多路复 ...
- Linux编程之select
select系统调用的的用途是:在一段指定的时间内,监听用户感兴趣的文件描述符上可读.可写和异常等事件. select 机制的优势 为什么会出现select模型? 先看一下下面的这句代码: int i ...
随机推荐
- 贪心 CodeForces 124B Permutations
题目传送门 /* 贪心:全排列函数使用,更新最值 */ #include <cstdio> #include <algorithm> #include <cstring& ...
- C# winform与Javascript的相互调用[转]
原文链接<html> <head> <meta http-equiv="Content-Language" content="zh-cn&q ...
- 1270 数组的最大代价 dp
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1270&judgeId=194704 一开始贪心,以为就两种情况, ...
- java之数据处理,小数点保留位数
1.返回字符串类型,保留后两位: public static String getRate(Object d) { return String.format("%.2f", d); ...
- Java加密简介
加密算法: 1.对称加密 DES AES 2.非对称加密 RSA 3.散列函数算法加密 (单项加密)::MD5.SHA.Mac 4.数字签名算法:RSA.DSA 其中,前三种主要完成数据的加解密: ...
- 6-Java-C(移动距离)
题目描述: X星球居民小区的楼房全是一样的,并且按矩阵样式排列.其楼房的编号为1,2,3... 当排满一行时,从下一行相邻的楼往反方向排号. 比如:当小区排号宽度为6时,开始情形如下: 1 2 3 ...
- day1 python 基础
# 一行注释"""多行注释"""print("hello world\n" * 3)name = "sure& ...
- zTree 点击文字 勾选check
callback: { onClick:function(event, treeId, treeNode){ console.info("onClick") var treeObj ...
- 无法完成安装:'Cannot access storage file '/
今天自己编译了spice-protocol spice-gtk spice qemu,然后想用virsh去创建一个虚机: # virsh define demo.xml 定义域 demo(从 ...
- delphi byte to of set
最佳方案 type // Controls.TCMMouseWheel relies on TShiftState not exceeding 2 bytes in size TShiftState ...