SUMMARY:Max Files, select & poll system call

From: Alan Hill (
Date: Wed Nov 27 1996 - 18:11:36 CST

Raw Data from Michael.Jaffee@Corp.Sun.COM (Michael Jaffe)
Can we fix it in the /etc/system file?
"rlim_fd_cur" is the soft limit, and "rlim_fd_max" is the hard limit.

Alter the number of file descriptors on a 2.4 system by adding the following
line to the /etc/system file.
this changes the number of file descriptors to 128, after a reboot.

        set rlim_fd_cur=0x80

However, note that..

1. Stdio routines are limited to using file descriptors 0 - 255. Even
though you can set the limit higher than 256, if fopen() cannot get a file
descriptor lower than 256, the fopen() fails. This is a problem if you have
other routines using open() directly. EXAMPLE, if you open 256 files with
open() without closing any, you won't be able to open any files at all with
fopen(), because all the low-numbered file descriptors have been used up.

2. It is dangerous to set the fd limits higher than 1024. There are some
structures defined in the system (like fd_set in <sys/select.h>) that assume
that the maximum fd is 1023. If the program uses an fd larger than this
with the macros and routines that access this structure (like FD_SET()), it
will corrupt its memory space because it will modify memory outside the
bounds of the structure. This structure is used specifically by the select()
routine, and indirectly by many library calls that use select().
Further discussion...
the "officially" supported rlim_fd_max is 1024. The reason is that there's
a data structure that is
sized for 1024 file descriptors (specifically, it's the "fd_set" type as
defined in <select.h>.

The problem you will see if you change this number to be greater than 1024
is that you may find that applications will start to fail. This was more
prevalent in 4.x than it is with 5.x, but there are a number of global data
structures ("svc_fdset" comes to mind) that will not be adequate for
programs that use higher limits. Because of its rarity, you may believe
that nothing is going wrong with raising this number -- but you can be
assured that there's an application somewhere that's going to start doing
something "interesting" once "svc_fdset" gets overwritten and whatever
follows it gets scribbled on.

The use of the "fd_set" type is somewhat deprecated for these reasons, as
are usage of the global variables the system exports which employ it. But
then, static linking is deprecated too and it's not like people don't still
use it.
Select is hard-wired at 1024 file descriptors, but not the poll system call.

BUT poll system call is less portable than select.
. Alan Hill in Montreal, Canada SUN&cisco&networking stuff .
` LanSer, for Wireless Financial Transactions, '

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:17 CDT