title: Getting the highest allocated file descriptor
body: <p>Is there a portable way (POSIX) to get the highest allocated file descriptor number for the current process?</p>
  
  <p>I know that there's a nice way to get the number on AIX, for example, but I'm looking for a portable method.</p>
  
  <p>The reason I'm asking is that I want to close all open file descriptors.  My program is a server which runs as root and forks and execs child programs for non-root users.  Leaving the privileged file descriptors open in the child process is a security problem.  Some file descriptors may be opened by code I cannot control (the C library, third party libraries, etc.), so I cannot rely on <code>FD_CLOEXEC</code> either.</p>