OPEN_MAX在Linux系统中定义在哪里? [英] Where is OPEN_MAX defined for Linux systems?
问题描述
OPEN_MAX
是定义单个程序允许的最大打开文件数的常量。
开始Linux编程4 th 版,页101:
$ b
这个限制通常由常量OPEN_MAX定义limits.h,因系统而异,...
在我的系统中,文件限制。 h
在目录 /usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
中没有这个常量。我是否看到错误的 limits.h
或者自2008年以来
值得一提的是,第四版的开始Linux编程于2007年发布;它的一部分可能有点过时。 (这不是对本书的批评,我没有读过。)
看来 OPEN_MAX
是不推荐使用,至少在Linux系统上。原因似乎是,可以同时打开的最大文件数量不是固定的,因此扩展为整数字面值的宏不是获取该信息的好方法。
还有另一个应该类似的宏 FOPEN_MAX
;我想不出为什么 OPEN_MAX
和 FOPEN_MAX
,如果它们都定义了,应该有不同的值。但是C语言标准要求 FOPEN_MAX
,所以系统没有选择不定义它。 C标准规定: FOPEN_MAX
展开为一个整数常量表达式, (
)实现保证的最小文件数可以同时打开
(如果minimum这个词很混乱,一个程序可以至少打开多个文件的保证。)
如果你想要当前可以打开的最大文件数量,请查看 sysconf()
功能;在我的系统上, sysconf(_SC_OPEN_MAX)
返回1024.( sysconf()
手册页引用符号 OPEN_MAX
。这不是一个计数,而是一个由 sysconf()
识别的值,并且它没有在我的系统中定义。
我搜索了 OPEN_MAX
(单词匹配,所以不包括 FOPEN_MAX
),并发现以下内容(这些显然只是简短的摘录):
$ b
/ usr / include / X11 /Xos.h
:
#ifdef __GNU__
#define PATH_MAX 4096
#define MAXPATHLEN 4096
#define OPEN_MAX 256 / *我们定义一个合理的限制。 * /
#endif
/ usr / include / i386- linux-gnu / bits / local_lim.h
:
/ *内核头文件污染了命名空间NR_OPEN符号
并定义了LINK_MAX,尽管文件系统具有不同的最大值。对于OPEN_MAX,
类似的事情是正确的:限制可以在
运行时改变,因此宏不能被定义。如有必要,在包含标题后删除此
。 * /
#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
:
/ *我们不提供
的固定值ARG_MAX`exec'函数参数的最大长度
包括环境数据。
ATEXIT_MAX可以用`atexit'注册的
的最大数量。
CHILD_MAX每个真实
用户ID的最大并发进程数。
OPEN_MAX任何时候一个进程可以打开
的最大文件数量。
PAGESIZE
PAGE_SIZE页面字节的大小。
PASS_MAX密码中有效字节的最大数量。
我们只为
提供一个固定限制IOV_MAX一个进程有
可用于`readv'或writev'的`iovec'结构的最大数量。
,如果这确实由底层系统修复的话。
* /
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_MAX
is 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_MAX
that should be similar; I can't think of a reason why OPEN_MAX
and FOPEN_MAX
, if they're both defined, should have different values. But FOPEN_MAX
is mandated by the C language standard, so system's don't have the option of not defining it. The C standard says that FOPEN_MAX
expands to an integer constant expression that is the minimum number of files that the implementation guarantees can be open simultaneously
(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. (The sysconf()
man page refers to a symbol OPEN_MAX
. This is not a count, but a value recognized by sysconf()
. And it's not defined on my system.)
I've searched for OPEN_MAX
(word match, so excluding FOPEN_MAX
) on my Ubuntu system, and found the following (these are obviously just brief excerpts):
/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.
*/
这篇关于OPEN_MAX在Linux系统中定义在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!