I am confused with the concept of file position as used in lseek. Is this file position maintained at inode level or a simple variable which could have different values for different process working on the same file?
Per the lseek docs , the file position is associated with the open file pointed to by a file descriptor, ie the thing that is handed to your by open . Because of functions like dup
and fork
, multiple descriptors can point to a single description , but it's the description that holds the location cursor.
Think about it: if it were associated with the inode, then you would not be able to have multiple processes accessing a file in a sensible manner, since all accesses to that file by one process would affect other processes.
Thus, a single process could have track many different file positions as it has file descriptors for a given file.
It's not an 'inode', but FILEHANDLE inside kernel.
Inode is a part of file description of the *nix specific file system on the disk. FAT32, for example, has no inodes, but supported by Linux.
For know the relation between file descriptors and open files, we need to examine three data structures.
For each process kernel maintains a table of open file descriptors. Each entry in this table records information about a single file descriptor including
The kernel maintains a system wide table of all open file descriptors. An open file description stores all information related to an open file including:
Reference-Page 94,The Linux Programming Interface by Michael Kerrisk
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.