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

后端 未结 6 1253
遇见更好的自我
遇见更好的自我 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:34

    If you mean how can you do it programatically from within the process then the normal (if slightly horrid) method is to do something like looping over all possible descriptors (use getrlimit() to read RLIMIT_NOFILE to find the range) calling something like fcntl(fd, F_GETFD, 0) on each one and checking for EBADF responses to see which ones are not open.

    If you mean that you want to find out from the shell what files a process has open then lsof -p is what you want.

提交回复
热议问题