开发者

How many files can i have opened at once?

On a typical OS how many files can i have opened at once using standard C disc IO?

I tried to read some constant that should tell it, but on Windows XP 32 bit that was a measly 20 or something. It seemed to work fine with over 30 though, but i haven't tested it extensively.

I need about 400 files op开发者_运维知识库ened at once at max, so if most modern OS's support that, it would be awesome. It doesn't need to support XP but should support Linux, Win7 and recent versions of Windows server.

The alternative is to write my own mini file system which i want to avoid if possible.


On Linux, this is dependent on the amount of available file descriptors. You can use ulimit -n to set / show the number of available FD's per shell.

See these instructions to how to check (or change) the value of available total FD:s in Linux.

This IBM support article suggests that on Windows the number is 512, and you can change it in the registry (as instructed in the article)

As open() returns the fd as int - size of int limits also the upper limit. (irrelevant as INT_MAX is a lot)


A process can query the limit using the getrlimit system-call.

#include<sys/resource.h>
struct rlimit rlim;
getrlimit(RLIMIT_NOFILE, &rlim);
printf("Max number of open files: %d\n", rlim.rlim_cur-1);


FYI, as root, you have first to modify the 'nofile' item in /etc/security/limits.conf . For example:

*                hard    nofile          10240
*                soft    nofile          10240

(changes in limits.conf typically take effect when the user logs in)

Then, users can use the ulimit -n bash command. I've tested this with up to 10,240 files on Fedora 11.

ulimit -n <max_number_of_files>

Lastly, all this is limited by the kernel limit, given by: (I guess you could echo a value into this to go even higher... at your own risk)

cat /proc/sys/fs/file-max

Also, see http://www.karakas-online.de/forum/viewtopic.php?t=9834

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜