The number is not the file
A file descriptor is a nonnegative integer used by a process to refer to an open resource. Regular files, pipes, and sockets can all be accessed through this interface. The number selects an entry in a process-local descriptor table; it is not the file contents or a globally unique resource identifier. Descriptor zero conventionally refers to standard input, but its actual destination depends on how the process was launched or redirected. Identical descriptor numbers in unrelated processes need not refer to the same resource.
Where shared state lives
On Linux, an open file description holds state such as the current file offset and file status flags. A descriptor refers to that description. Independently opening the same pathname twice normally creates two descriptions with separate offsets. Duplicating a descriptor with dup instead creates another reference to the same description. This extra level explains why two handles for one underlying file can behave differently. Sharing depends on how the references were created, not merely on whether the displayed pathname happens to be identical.
| Creation method | Open file description | Ordinary offset |
|---|---|---|
| Two independent opens | Separate | Separate |
| dup | Shared | Shared |
| Inheritance through fork | Can be shared | Shared by the corresponding descriptors |
A shared-offset example
Suppose fd is duplicated into fd2 before either is read. A successful ten-byte read through fd advances the shared open file description offset, so an ordinary subsequent read through fd2 starts from the updated position. No copying of the complete file is required to produce this behavior. Inherited descriptors after fork can also share the description. An independent open or an interface such as pread, which supplies an explicit offset, can be appropriate when the application must not couple operations through the implicit shared position.
Lifetime and number reuse
Closing one descriptor removes that particular reference; another descriptor may still keep the same open resource alive. The released integer can later be reused for a different open resource. Retaining an old number and using it after close can therefore target something entirely different from the original file. Treat descriptor ownership and lifetime explicitly, especially around duplication, process inheritance, and error handling. A small plausible-looking integer is not evidence that the resource originally associated with it still exists or belongs to the caller.