Subject: relationship between sysconf(_SC_OPEN_MAX) & FD_SETSIZE
To: None <netbsd-users@NetBSD.ORG>
From: Andrew Cassin <acas@catt.citri.edu.au>
List: netbsd-users
Date: 04/23/1997 20:55:11
I stumbled across a strange interaction between sysconf(3), FD_SETSIZE
and select(2) under NetBSD 1.1 (i386). This problem concerns the 
maximum number of open file descriptors available to a single process.

I was under the impression that the POSIX "sysconf(_SC_OPEN_MAX)" would yield
this number, but this does not work if this value is > FD_SETSIZE in
the kernel of the running system. Specifically, in 
/sys/kern/sys_generic.c in sys_select():

if (SCARG(uap, nd) > FD_SETSIZE)
    return (EINVAL);

(incidentally this results in fvwm 1.24r to cpu spin *if* HAS_SYSCONF is 
defined in the fvwm configuraration)

So what is the correct way to find out the maximum number of file descriptors?
Use FD_SETSIZE, sysconf() or something else? Are file descriptors between
FD_SETSIZE+1 and sysconf(_SC_OPEN_MAX) un'selectable?

Thanks,

ACAS