首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

limits.h中OPEN_MAX恒量在哪里

2013-07-08 
limits.h中OPEN_MAX常量在哪里?《linux程序设计第四版》 P101The number of files that any one running pro

limits.h中OPEN_MAX常量在哪里?
《linux程序设计第四版》 P101


The number of files that any one running program may have open at once is limited. The limit, usually
defined by the constant  OPEN_MAX in limits.h , varies from system to system, but POSIX requires that 
it be at least 16. This limit may itself be subject to local system-wide limits so that a program may not
always be able to open this many files. On Linux, the limit may be changed at runtime so  OPEN_MAX is
not a constant. It typically starts out at 256.


这本书中说,一个程序能打开的文件总数是OPEN_MAX个,OPEN_MAX在limits.h中定位,为什么我在Ubuntu10.04的/usr/include/limits.h中找不到OPEN_MAX呢?
[解决办法]

The OPEN_MAX macro in limits.h should not be there. It claims to be the
limit on file descriptors in a process, but its value is wrong for that.
There is no constant value, but a variable resource limit (RLIMIT_NOFILE).
Nothing in the kernel uses OPEN_MAX except things that are wrong to do so.
I've submitted other patches to remove those uses.

The proper thing to do according to POSIX is not to define OPEN_MAX at all.
The sysconf (_SC_OPEN_MAX) implementation works by calling getrlimit.

热点排行