我想在 linux 中找到为进程打开的所有文件.
I wanted to find all fds opened for a process in linux.
我可以用 glib 库函数来做吗?
Can I do it with glib library functions ?
推荐答案自从您使用 Linux 以来,您(几乎可以肯定)已经安装了 /proc 文件系统.这意味着最简单的方法是获取 /proc/self/fd 的内容列表;其中的每个文件都以 FD 命名.(当然,使用 g_dir_open、g_dir_read_name 和 g_dir_close 来做列表.)
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.)
以其他方式获取信息比较麻烦(例如,没有有用的 POSIX API;这是一个未标准化的领域).
Getting the information otherwise is moderately awkward (there's no helpful POSIX API for example; this is an area that wasn't standardized).
更多推荐
为进程 linux(C 代码)查找打开的文件描述符?
发布评论