为进程 linux(C 代码)查找打开的文件描述符? [英] Finding open file descriptors for a process linux ( C code )?

查看:24
本文介绍了为进程 linux(C 代码)查找打开的文件描述符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 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_openg_dir_read_nameg_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 代码)查找打开的文件描述符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆