On 2019-Aug-21, Tom Lane wrote:
> Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> > I guess the other possibility is that there exists an operating system
> > that returns file descriptors higher than its FD_SETSIZE, when some fds
> > below FD_SETSIZE are still available. Doesn't seem realistic.
>
> I think POSIX requires open() to select the lowest unused FD. Otherwise
> tricks like closing and reopening stdout wouldn't work reliably.
Ah, yes, that's right -- my system's open(3p) manpage says:
The open() function shall return a file descriptor for the named file
that is the lowest file descriptor not currently open for that process.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services