Is there a C API to get the:
Linux systems limit the number of file descriptors that any one process may open to 1024 per process. (This condition is not a problem on Solaris machines, x86, x64, or SPARC). After the directory server has exceeded the file descriptor limit of 1024 per process, any new process and worker threads will be blocked.
You can use /proc file system or the lsof command to find all the file descriptors used by a process.
For the current process count, you can use getrlimit
to get the file descriptor limit, then iterate over all integers from 0 to that limit and try calling fcntl
with the F_GETFD
command. It will succeed only on the file descriptors which are actually open, letting you count them.
Edit: I now have a better way to do it. After getting the rlimit
, make a large array of struct pollfd
(as large as the limit if possible; otherwise you can break it down into multiple runs/calls) with each fd in the range and the events
member set to 0. Call poll
on the array with 0 timeout, and look for the POLLNVAL
flag in the revents
for each member. This will tell you which among a potentially-huge set of fds are invalid with a single syscall, rather than one syscall per fd.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With