 | | File descriptors are allocated from a table maintained for each process by the operating system, and each file descriptor is simply an index into that table. Most older versions of UNIX limit the maximum number of files a process can have open at once to approximately 20. Newer versions have larger limits such as 32 or 64, and SVR4 allows up to 256. One of the features of this table-based implementation is that opening a file always returns the lowest-numbered available file descriptor. Thus, because a process starts out with three open files (0, 1, and 2), the first file it opens is attached to file descriptor 3. If the program later closes its standard input (file descriptor 0), then the next file it opens is attached to file descriptor 0, not file descriptor 4. This behavior is found in all versions of UNIX, and is also specified by the POSIX standard. | |
|