简体   繁体   English

手动获取有关Linux文件描述符表的信息

[英]Manually obtaining information about Linux File Descriptor Table

How can I obtain the file descriptor flags 'fd flags' residing in the File Descriptor Table associated with any open file descriptor? 如何获取与任何打开的文件描述符关联的文件描述符表中的文件描述符标志'fd标志'? I would like to know to write the code manually or at least what functions and structures to research further while not using the fcntl function or viewing the /proc entries. 我想知道手动编写代码,或者至少在不使用fcntl函数或查看/ proc条目的同时至少要研究哪些函数和结构。

The image below shows that the file descriptor table for a given process has a flags field and a file pointer field. 下图显示了给定进程的文件描述符表具有标志字段和文件指针字段。 How can I programatically access these fields? 如何以编程方式访问这些字段?

在此处输入图片说明

You can access /proc/PID/fdinfo/FD file which contains flags in octal: 您可以访问/proc/PID/fdinfo/FD文件,其中包含以八进制表示的flags

$ cat /proc/$$/fdinfo/0
pos:    0
flags:  0100002
mnt_id: 20

In this example, 0100002 = O_LARGFILE|O_RDWR 在此示例中, 0100002 = O_LARGFILE|O_RDWR

fcntl() is a system call, not "a library". fcntl()是系统调用,而不是“库”。 It is the way you retrieve the flags associated with a file descriptor. 检索与文件描述符关联的标志的方式。

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

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