Date: Fri, 13 Dec 1996 19:54:23 +1100 From: Bruce Evans <bde@zeta.org.au> To: freebsd-hackers@FreeBSD.ORG, freebsd-questions@FreeBSD.ORG, sameer@c2.net Subject: Re: getdtablesize, OPEN_MAX, and sysctl Message-ID: <199612130854.TAA26648@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
> So I have a machine (2.1-STABLE) with OPEN_MAX set to 256. >When I do sysctl -a kern.maxfiles is 2088. Is there a relationship >between OPEN_MAX and something that shows up in sysctl? No. OPEN_MAX is broken and should never be used. It is currently used in /usr/src only to configure the number of descriptors for the for the init process. This value is inherited by child processes. To determine the current limit, use sysconf(_SC_OPEN_MAX) in "portable" programs or getdtablesize() in BSD programs or sysctl() in BSD4.4 programs. getdtablesize() is the easiest to use and the least buggy. The limit is supposed to be invariant across the lifetime of a process, but isn't. Long-lived processes may have to worry about the limit being reduced by the sysadmin (`sysctl -w kern.maxfilesperproc=fewer'). The bugs have to do with this possibility. The actual limit is min(resource limit, maxfilesperproc). getdtablesize() returns this but the alternative syscalls return the resource limit. Also, setrlimit silently reduces the resource limit to min(requested resource limit, maxfilesperproc). > I have this program, where if I do a getdtablesize (or >sysconf(SC_OPEN_MAX)) it returns 256 at program startup, but returns >*258* on a getdtablesize() call further on in execution. (Right before >a select(), which then subsequently fails with EINVAL) Anyone know how >the getdtablesize() result could have changed by two? Something must have increased it using setrlimit(). > On the last two machines, the select runs fine On the first >two, the select (the result of the getdtablesize() is going to the >first arg of the select() call) returns EINVAL. select() only supports a fixed maximum number of descriptors in -stable. The default is FD_SETSIZE = 256. 2.2 and -current support any reasonable number provided the application is compiled with FD_SETSIZE defined as a larger number. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612130854.TAA26648>