The maximum number of files that can be opened with c "fopen" in linux

What is the maximum number of c fopen files that can be opened simultaneously on Linux?

+7
c fopen
source share
4 answers

You can see the maximum allowed open files (kernel restriction) by doing:

 cat /proc/sys/fs/file-max 

Quote from the kernel documentation:

The value in the max file means the maximum number of files that the Linux kernel allocates. When you get a lot of error messages about the end of work with files, you may want to increase this limit.

+3
source share

An implementation is needed to provide FOPEN_MAX in <stdio.h> . This is the minimum number of files that can simultaneously open implementation guarantees. You may be able to discover more, but this is the only way to find out what needs to be checked.

Note that the kernel restriction is different from this - it tells you how many files you can (potentially) open with open , creat and other OS calls. The standard library of your C implementation can (and often will) impose its own limit (for example, by statically allocating a FILE array). Theoretically, the largest number you can open is the minimum of the limit imposed by the kernel and the library implementation, but the kernel limit is almost always (much) higher.

Generally speaking, if you're interested, you are probably doing something wrong though.

+11
source share

It is defined by the POSIX standard. Removing this option causes portability problems. In addition, this macro is mentioned in glibc.info (at least in redhat-7.1). Please refer to the link below OPEN_MAX is not defined in limits.h .

+1
source share

This code should indicate max on your computer. Create the file "test" in the same folder and run it. It basically continues to open the file until it can no longer.

 # include <assert.h> # include <stdio.h> # include <stdlib.h> # include <unistd.h> # include <sys/types.h> # include <sys/stat.h> # include <sys/wait.h> # include <string.h> # include <fcntl.h> int main(){ int t; for(;;){ t = open("test", O_RDONLY); if (t < 0){ perror("open"); exit(1); } printf("%d: ok\n", t); } } 
0
source share

All Articles