简体   繁体   中英

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? 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.

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:

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

In this example, 0100002 = O_LARGFILE|O_RDWR

fcntl() is a system call, not "a library". It is the way you retrieve the flags associated with a file descriptor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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