免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7468 | 回复: 4

请教 windows 进程打开句柄个数的限制的问题 [复制链接]

论坛徽章:
0
发表于 2012-08-26 15:10 |显示全部楼层
   上周用c的fopen 函数同时打开很多文件,当打开到第47个后,就提示错误了, 后续得文件无法打开了。
刚用perl的open函数测试,发现打开到2045的时候才提示“Too many open files”。
请教为何2者差这么多。如何调高47这个门限值?

论坛徽章:
0
发表于 2012-08-26 20:09 |显示全部楼层
Perl flock()函数
语法
flock FILEHANDLE, OPERATION


定义和使用
支持文件锁定在指定的文件句柄,使用系统的flock(),fcntl()文件锁定,或使用lockf()。确切的实现是依赖于你的系统支持。操作是此处定义的静态值之一...

Operation        Result LOCK_SH         Set shared lock.
LOCK_EX         Set exclusive lock.
LOCK_UN         Unlock specified file.
LONG_NB         Set lock without blocking.
返回值
0 设置/取消锁定失败时

1 设置/取消锁定成功时

实例
以下是用法...

这里有一个邮箱附加器 BSD系统:

use Fcntl ':flock'; # import LOCK_* constants

    sub lock {
        flock(MBOX,LOCK_EX);
        # and, in case someone appended
        # while we were waiting...
        seek(MBOX, 0, 2);
    }
    sub unlock {
        flock(MBOX,LOCK_UN);
    }
    open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
            or die "Can't open mailbox: $!";
    lock();
    # by www.yiibai.com

    print MBOX $msg,"\n\n";
    unlock();

论坛徽章:
42
19周年集字徽章-周
日期:2019-10-14 14:35:31平安夜徽章
日期:2015-12-26 00:06:30数据库技术版块每日发帖之星
日期:2015-12-01 06:20:002015亚冠之首尔
日期:2015-11-04 22:25:43IT运维版块每日发帖之星
日期:2015-08-17 06:20:00寅虎
日期:2014-06-04 16:25:27狮子座
日期:2014-05-12 11:00:00辰龙
日期:2013-12-20 17:07:19射手座
日期:2013-10-24 21:01:23CU十二周年纪念徽章
日期:2013-10-24 15:41:34IT运维版块每日发帖之星
日期:2016-01-27 06:20:0015-16赛季CBA联赛之新疆
日期:2016-06-07 14:10:01
发表于 2012-08-27 10:38 |显示全部楼层
本帖最后由 laputa73 于 2012-08-27 10:53 编辑

我也想知道啊
之前用erlang的echo server,也是到1000多就挂住了(*2就是2000左右)
有人说要改注册表,但是没有搜到怎么改。
感觉是类似的问题
在linux下可以用ulimit改
windows下是什么样的机制?

论坛徽章:
0
发表于 2012-08-27 10:41 |显示全部楼层
linux 看看ulimit 能不能修改~~   

论坛徽章:
42
19周年集字徽章-周
日期:2019-10-14 14:35:31平安夜徽章
日期:2015-12-26 00:06:30数据库技术版块每日发帖之星
日期:2015-12-01 06:20:002015亚冠之首尔
日期:2015-11-04 22:25:43IT运维版块每日发帖之星
日期:2015-08-17 06:20:00寅虎
日期:2014-06-04 16:25:27狮子座
日期:2014-05-12 11:00:00辰龙
日期:2013-12-20 17:07:19射手座
日期:2013-10-24 21:01:23CU十二周年纪念徽章
日期:2013-10-24 15:41:34IT运维版块每日发帖之星
日期:2016-01-27 06:20:0015-16赛季CBA联赛之新疆
日期:2016-06-07 14:10:01
发表于 2012-08-27 10:55 |显示全部楼层
找到一个说法,说是c api的限制。不过很不甘心啊。
明明有人说可以改的(可气的是没有说怎么改)。
MSDN里的描述如下:

C run-time I/O now supports many more open files on Win32 platforms than in previous versions. Up to 2,048 files can be open simultaneously at the lowio level (that is, opened and accessed by means of the _open, _read, _write, and so forth family of I/O functions). Up to 512 files can be open simultaneously at the stdio level (that is, opened and accessed by means of the fopen, fgetc, fputc, and so forth family of functions). The limit of 512 open files at the stdio level can be increased to a maximum of 2,048 by means of the _setmaxstdio function.


Because stdio-level functions, such as fopen, are built on top of the lowio functions, the maximum of 2,048 is a hard upper limit for the number of simultaneously open files accessed through the C run-time library.

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP