Relationship between file descriptors and open files in Linux
file Descriptor: is a non-negative integer in form. In fact, it is an index value that points to the record table in which the kernel opens a file for each process maintained by the process.
File types in Linux
The Linux system sees everything as files, including ordinary files.-
, catalog filesd
, character device filesc
, Block device filesb
, Symbolic Link filel
。 File descriptors are indexes created by the kernel to efficiently manage files that have been opened (a nonnegative integer) used to refer to files that have been opened, and system calls to all I/O operations under Linux are performed through file descriptors. For example0
Represents standard input,1
Represents standard output,3
Indicates a standard error
, the file descriptor is incremented on that basis.
The relationship between file descriptors, files, and processes
- Each file descriptor points to an open file that corresponds to the
- Different file descriptors may point to the same open file
- The same file may be opened by a different process, or it can be opened multiple times by the same process
File descriptor Table: The process level list, which is part of the user area, creates a new file descriptor for each file opened, and can only be accessed through a function of the file descriptor, or the process cannot access it directly.
System Files Table: A system-wide list that is shared with all processes of the current system, each entry containing the file offset, access mode, and count of entries to its file descriptor
File System index node table: inode index node table (UID, GID, CTime, Mtime, Atime, read and write execution permissions, number of links, block location)
Record content
Example
Relationship between file descriptors and open files in Linux