OPEN_MAX
是定义单个程序允许的最大打开文件数的常量。
根据《Linux 编程入门》第 4 版,第 101 页:
The limit, usually defined by the constant OPEN_MAX in limits.h, varies from system to system, ...
在我的系统中,目录/usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
中的文件limits.h
没有这个持续的。我是在查看错误的 limits.h
还是自 2008 年以来 OPEN_MAX
的位置发生了变化?
最佳答案
Beginning Linux Programming 的第 4 版物有所值|发表于 2007 年;它的某些部分可能有点过时了。 (这不是对我没读过的书的批评。)
看来 OPEN_MAX
已被弃用,至少在 Linux 系统上是这样。原因似乎是可以同时打开的最大文件数不固定,因此扩展为整数文字的宏不是获取该信息的好方法。
还有一个宏FOPEN_MAX
应该是类似的;我想不出为什么 OPEN_MAX
和 FOPEN_MAX
(如果它们都已定义)应该具有不同的值。但是 FOPEN_MAX
是 C 语言标准强制要求的,所以系统没有不定义它的选项。 C 标准规定 FOPEN_MAX
expands to an integer constant expression that is the minimum number of files that the implementation guarantees can be open simultaneously
(如果“最少”一词令人困惑,它保证程序至少一次可以打开那么多文件。)
如果您想要当前 可以打开的最大文件数,请查看sysconf()
。功能;在我的系统上,sysconf(_SC_OPEN_MAX)
返回 1024。(sysconf()
手册页引用符号 OPEN_MAX
。这不是计数,但是 sysconf()
识别的值。而且它没有在我的系统上定义。)
我在我的 Ubuntu 系统上搜索了 OPEN_MAX
(单词匹配,因此排除了 FOPEN_MAX
),并找到了以下内容(这些显然只是简短的摘录):
/usr/include/X11/Xos.h
:
# ifdef __GNU__
# define PATH_MAX 4096
# define MAXPATHLEN 4096
# define OPEN_MAX 256 /* We define a reasonable limit. */
# endif
/usr/include/i386-linux-gnu/bits/local_lim.h
:
/* The kernel header pollutes the namespace with the NR_OPEN symbol
and defines LINK_MAX although filesystems have different maxima. A
similar thing is true for OPEN_MAX: the limit can be changed at
runtime and therefore the macro must not be defined. Remove this
after including the header if necessary. */
#ifndef NR_OPEN
# define __undef_NR_OPEN
#endif
#ifndef LINK_MAX
# define __undef_LINK_MAX
#endif
#ifndef OPEN_MAX
# define __undef_OPEN_MAX
#endif
#ifndef ARG_MAX
# define __undef_ARG_MAX
#endif
/usr/include/i386-linux-gnu/bits/xopen_lim.h
:
/* We do not provide fixed values for
ARG_MAX Maximum length of argument to the `exec' function
including environment data.
ATEXIT_MAX Maximum number of functions that may be registered
with `atexit'.
CHILD_MAX Maximum number of simultaneous processes per real
user ID.
OPEN_MAX Maximum number of files that one process can have open
at anyone time.
PAGESIZE
PAGE_SIZE Size of bytes of a page.
PASS_MAX Maximum number of significant bytes in a password.
We only provide a fixed limit for
IOV_MAX Maximum number of `iovec' structures that one process has
available for use with `readv' or writev'.
if this is indeed fixed by the underlying system.
*/
关于linux - Linux系统的OPEN_MAX定义在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14042824/