Ashish Ashish - 3 months ago 9
Linux Question

Finding open file descriptors for a process linux ( C code )?

I wanted to find all fds opened for a process in linux.

Can I do it with glib library functions ?


Since you're on Linux, you've (almost certainly) got the /proc filesystem mounted. That means that the easiest method is going to be to get a list of the contents of /proc/self/fd; each file in there is named after a FD. (Use g_dir_open, g_dir_read_name and g_dir_close to do the listing, of course.)

Getting the information otherwise is moderately awkward (there's no helpful POSIX API for example; this is an area that wasn't standardized).