查找打开的文件描述符一个过程的linux(C $ C $三)? [英] Finding open file descriptors for a process linux ( C code )?

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

问题描述

我想找到所有的FDS打开在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 /自/ 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 $ C $三)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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