C/Count free file descriptors
From Attie's Wiki
(Difference between revisions)
(Created page with "This could be improved to detect the number of file descriptors set by ulimit, but most systems are set to ~1024 by default. <source lang="c"> { int i, fd[2048]; for (i = 0...") |
Revision as of 16:21, 18 January 2013
This could be improved to detect the number of file descriptors set by ulimit, but most systems are set to ~1024 by default.
{ int i, fd[2048]; for (i = 0; i < sizeof(fd) / sizeof(int); i++) { if ((fd[i] = open("/dev/null", O_RDONLY)) == -1) break; } printf("free fds: %d\n", i); for (i-- ; i >= 0; i--) { close(fd[i]); } }