fopen不会同时处理超过60个文件 [英] fopen does not deal with more than 60 files at the same time

查看:171
本文介绍了fopen不会同时处理超过60个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C程序中需要同时打开60多个文本文件。但是,似乎fopen不能同时处理超过60个文件。我在Windows环境下编程。



我使用下面的fopen语句:

 的fopen(fileName.c_str(), 重量); 

其中fileName是我的txt文件的路径,名称在100个文件的循环内改变。有没有人知道这个工作有什么窍门?或者有其他选择吗?

实际上有两个限制了您可以打开的文件数量任何时间:


  1. ulimit -n
  2. 指定的环境限制>
  3. C运行时库。我知道有几个限制你到256个文件句柄(Sun命名为1)。

当前的限制大概是63帐户STDIN,STDOUT和STDERR已经被打开了,我不知道的系统如此低,所以它可能是你的 ulimit 但是你需要注意其他限制。



在windows上,您可以使用 _setmaxstdio(n),但是在默认你应该仍然可以打开512个文件。所以我仍然有点困惑,为什么你只能得到60奇怪,除非你打开每个文件约8倍...

I need to have more than 60 text files opened at the same time in my C program. However, it seems that fopen is not able to handle more than 60 files simultaneously. I am programming in Windows environment.

I use the following fopen statement:

fopen(fileName.c_str(),"wt");

Where fileName is the path of my txt file, name which changes inside a loop along 100 files. Does anybody know any trick to make this work? Or any alternative?

解决方案

There's actually two things that constrain how many files you can have open at any time:

  1. The environment limit specified by ulimit -n.
  2. The C runtime library. I know of several that limit you to 256 file handles (Sun to name one)

Your current limit is probably 63 once you take into account STDIN, STDOUT and STDERR already being opened, and I don't know of a system that goes that low so it's probably your ulimit but you need to be aware of the other limit.

On windows you can use _setmaxstdio(n) but in the default case you should still be able to open 512 files. so I'm still a little confused as to why you only get 60 odd unless you open each file about 8 times...

这篇关于fopen不会同时处理超过60个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆