lkml.org 
[lkml]   [2009]   [Nov]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 如何通过fd找到 打开文件的路径及名称
On Mon, Nov 23, 2009 at 09:02:33AM +0800, Helight.Xu wrote:
> Américo Wang wrote:
>> On Fri, Nov 20, 2009 at 02:33:48PM +0800, Helight.Xu wrote:
>>
>>> 在用户程序中打开文件进行编辑,那在内核中如何能通过open后的fd
>>> 来找到相应打开文件的路径及其名字呢?
>>>
>>>
>>
>> 问题是你为什么要在内核中做呢?在用户空间完全可以完成:
>>
>> % readlink /proc/<PID>/fd/X
>>
> 我是想在内核中实现一些功能,所以现在内核中找到文件的路径及其名称,


能在用户层完成的就不要跑到内核里去做,完全没必要。

而且,你在处理这个问题时还要考虑pipe和socket这些特殊的文件,
它们对应的fd可是没有file的。

> 现在只
> 能找到文件名,还在找路径。。。

你可以看看proc文件中对fd/X的处理,或许能帮上忙。


--
Live like a child, think like the god.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2009-11-23 15:43    [W:0.054 / U:2.532 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site