tags:

views:

75

answers:

2

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 opened 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.

A: 

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)

Kimvais
+2  A: 

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);
edgar.holleis