为进程 linux(C 代码)查找打开的文件描述符?

编程入门 行业动态 更新时间:2024-10-10 18:25:59
本文介绍了为进程 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_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 代码)查找打开的文件描述符?

本文发布于:2023-06-10 18:39:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/616530.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   代码   文件   linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!