/* max-fds.c -- * find max number of open files, and those that keep open * atfer a program exists */ /* $Id$ */ /* Carlos Duarte , 990328 */ #define HAVE_GETDTABLESIZE #include #include #include #include #include #if defined(RLIMIT_OFILE) && !defined(RLIMIT_NOFILE) #define RLIMIT_NOFILE RLIMIT_OFILE #endif static int maxfds(void) { #if !defined(done) && defined(HAVE_GETDTABLESIZE) return getdtablesize(); #define done #endif #if !defined(done) && defined(RLIMIT_NOFILE) struct rlimit rr = {-1, -1}; getrlimit(RLIMIT_NOFILE, &rr); return rr.rlim_cur; #define done #endif return -1; } int main() { int md, d; md = maxfds(); printf("max open files: %d\n", md); for (d=0; d