简体   繁体   English

文件名中的Linux文件描述符

[英]Linux file descriptor from file name

As it is possible to get the file name from the file descriptor, I was wondering if there was a way to do the reverse. 由于可以从文件描述符中获取文件名,我想知道是否有一种方法可以执行相反操作。

There has to be a Linux command that does this since it doesn't seem like it would be that hard to do if there is already a fd-->fn function. 必须有一个Linux命令来执行此操作,因为如果已经有了fd-> fn函数,看起来似乎很难做到。

To make this a question: how can one get the file descriptor from something like /dev/urandom ? 提出一个问题:如何从/dev/urandom类的文件中获取文件描述符?

See the command lsof to list all open files and their per-process file handle. 请参阅命令lsof列出所有打开的文件及其每个进程的文件句柄。

Of course if n processes have /dev/urandom open, then there will be at least n matches (a process can have more than one handle to the same file). 当然,如果n个进程打开了/ dev / urandom,则将至少有n个匹配项(一个进程可以对同一个文件拥有多个句柄)。

Memory mapped files may not have a file descriptor, but such files are still listed. 内存映射文件可能没有文件描述符,但仍列出了此类文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM