How many files can I open at once?

In a typical OS, how many files can I open right away using a standard C IO drive?

I tried to read some constant that should say this, but in Windows XP there is 32 bit, which was a negligible 20 or something like that. It seems to work fine with over 30, but I haven't tested it extensively.

I need about 400 files that open immediately at max, so if most modern OSs support this, it would be great. It does not need XP support, but must support Linux, Win7, and the latest versions of the Windows server.

An alternative is to create my own mini file system, which I want to avoid if possible.

+4
source share
3 answers

On Linux, this depends on the number of file descriptors available. You can use ulimit -n to set / display the number of available FDs for each shell.

See instructions for checking (or changing) the value of the available full FD: s on Linux.

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

Since open() returns fd as int , the size of int is also the upper limit. (inappropriate since INT_MAX is a lot)

+2
source

A process can request a restriction 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); 
+3
source

FYI, as root, you must first change the nofile element in /etc/security/limits.conf. For instance:

 * hard nofile 10240 * soft nofile 10240 

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

Users can then use the ulimit -n bash command. I tested this with up to 10,240 files on Fedora 11.

 ulimit -n <max_number_of_files> 

Finally, all this is limited by the kernel limit defined by: (I think you could drop the value into this to go even higher ... at your own peril and risk)

 cat /proc/sys/fs/file-max 

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

+1
source

Source: https://habr.com/ru/post/1303791/


All Articles