#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
struct dirent *dirp;
DIR *fdir;
fdir = opendir("/proc");
while(dirp = readdir(fdir)){
if(strcmp(dirp->d_name, ".")==0 || strcmp(dirp->d_name, "..") == 0)
continue;
if(dirp->d_type == DT_DIR) {
// printf("%s\n", dirp->d_name );
// getchar();
char buf[256];
sprintf(buf, "/proc/%s/fd", dirp->d_name);
DIR *fdir2;
struct dirent *dirp2;
if((fdir2 = opendir(buf)) != NULL ){
while(dirp2 = readdir(fdir2)){
//printf("%s:%s\n", dirp->d_name, dirp2->d_name);
char buf2[256];
char tmp2[256];
sprintf(tmp2, "%s/%s", buf, dirp2->d_name);
readlink(tmp2, buf2, 256);
printf("%s:\t%s\t%s\n", dirp->d_name, dirp2->d_name, buf2);
// getchar();
}
}
}
}
return 0;
}