Skip to content

Instantly share code, notes, and snippets.

@siddarth
Created September 3, 2011 08:01
Show Gist options
  • Save siddarth/1190828 to your computer and use it in GitHub Desktop.
Save siddarth/1190828 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <glob.h>
#include <unistd.h>
#include <assert.h>
#define PATH_SIZE 1024
#define FD_PATH "/proc/%d/fd/*.*"
int main(int argc, char **argv) {
int pid = getpid();
char path[PATH_SIZE];
sprintf(path, FD_PATH, pid);
printf("%s\n", path);
glob_t data;
assert(glob(path, 0, NULL, &data) == 0);
int i;
for(i=0; i<data.gl_pathc; i++)
printf("%s\n", data.gl_pathv[i]);
globfree(&data);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment