Created
January 21, 2014 23:31
-
-
Save mauiaaron/8550720 to your computer and use it in GitHub Desktop.
File Descriptor Counts on Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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