Skip to content

Instantly share code, notes, and snippets.

@mauiaaron
Created January 21, 2014 23:31
Show Gist options
  • Save mauiaaron/8550720 to your computer and use it in GitHub Desktop.
Save mauiaaron/8550720 to your computer and use it in GitHub Desktop.
File Descriptor Counts on Linux
#ifndef NDEBUG
#include <string.h>
#include <stdio.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/resource.h>
int _debug_get_num_fds() {
int fd_count = 0;
struct dirent *dp = NULL;
DIR *dir = opendir("/proc/self/fd");
while ((dp = readdir(dir)) != NULL) {
++fd_count;
}
closedir(dir);
return fd_count;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment