OPEN_MAX is the constant that defines the maximum number of open files allowed for a single program.
According to Beginning Linux Programming 4th Edition, Page 101 :
The limit, usually defined by the constant OPEN_MAX in limits.h, varies from system to system, …
In my system, the file limits.h in directory /usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed does not have this constant. Am i looking at the wrong limits.h or has the location of OPEN_MAX changed since 2008 ?
For what it’s worth, the 4th edition of Beginning Linux Programming was published in 2007; parts of it may be a bit out of date. (That’s not a criticism of the book, which I haven’t read.)
It appears that
OPEN_MAXis deprecated, at least on Linux systems. The reason appears to be that the maximum number of file that can be opened simultaneously is not fixed, so a macro that expands to an integer literal is not a good way to get that information.There’s another macro
FOPEN_MAXthat should be similar; I can’t think of a reason whyOPEN_MAXandFOPEN_MAX, if they’re both defined, should have different values. ButFOPEN_MAXis mandated by the C language standard, so system’s don’t have the option of not defining it. The C standard says thatFOPEN_MAX(If the word “minimum” is confusing, it’s a guarantee that a program can open at least that many files at once.)
If you want the current maximum number of files that can be opened, take a look at the
sysconf()function; on my system,sysconf(_SC_OPEN_MAX)returns 1024. (Thesysconf()man page refers to a symbolOPEN_MAX. This is not a count, but a value recognized bysysconf(). And it’s not defined on my system.)I’ve searched for
OPEN_MAX(word match, so excludingFOPEN_MAX) on my Ubuntu system, and found the following (these are obviously just brief excerpts):/usr/include/X11/Xos.h:/usr/include/i386-linux-gnu/bits/local_lim.h:/usr/include/i386-linux-gnu/bits/xopen_lim.h: