就其价值而言,第四版开始 Linux 编程于2007年出版;它的某些部分可能有点过时了。 (这不是对这本书的批评,我还没有读过。)
看起来OPEN_MAX
已被弃用,至少在 Linux 系统上是如此。原因似乎是可以同时打开的最大文件数不固定,因此扩展为整数文字的宏并不是获取该信息的好方法。
还有一个宏FOPEN_MAX
这应该是相似的;我想不出原因OPEN_MAX
and FOPEN_MAX
,如果它们都被定义,应该有不同的值。但FOPEN_MAX
是 C 语言标准强制规定的,因此系统没有不定义它的选择。 C 标准说FOPEN_MAX
扩展为整数常量表达式,该表达式是最小文件数
实施保障可同时开启
(如果“最小”这个词令人困惑,那么它是程序可以打开的保证at least一次有那么多文件。)
如果你想要current可以打开的最大文件数,请查看sysconf()功能;在我的系统上,sysconf(_SC_OPEN_MAX)
返回 1024。(sysconf()
手册页引用了一个符号OPEN_MAX
。这不是一个计数,而是一个由sysconf()
。而且我的系统上没有定义它。)
我已经寻找过OPEN_MAX
(单词匹配,因此排除FOPEN_MAX
)在我的 Ubuntu 系统上,发现了以下内容(这些显然只是简短的摘录):
/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.
*/