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

后端 未结 6 1260
遇见更好的自我
遇见更好的自我 2020-12-08 01:02

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

Can I do it with glib library functions ?

6条回答
  •  佛祖请我去吃肉
    2020-12-08 01:24

    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).

提交回复
热议问题