File descriptors are recycled in ascending order. Managing File Descriptors Because files can be shared by many users, it is necessary to allow related processes to share a common offset pointer and have a separate current offset pointer for independent processes that access the same file. The open file table entry maintains a reference count to track the number of file descriptors assigned to the file. The File Sharing figure demonstrates what happens in the file descriptor and system file tables when two processes open the same file. Each open operation creates a system table entry.
Independent offsets protect the integrity of the data.
When a file descriptor is duplicated, two processes then share the same offset and interleaving can occur. Interleaving means that bytes are not read or written sequentially. The duplicate is created at an empty space in the user file descriptor table that contains the original descriptor. A dup process increments the reference count in the file table entry by 1 and returns the index number of the file-descriptor where the copy was placed. See Duplicate File Descriptors Created by the dup Subroutine figure .