File Descriptor Management

File Descriptors

The POSIX file access APIs (e.g. read(2) and write(2)) operate on file descriptors. A file descriptor is an integer*.
Normally, when a process starts, it has (at least) three already-open file descriptors: As additional files are opened (e.g. with open(2), creat(2) or pipe(2)) each is assigned the lowest unused file descriptor.

(*If you want a little more truth, these integers are indexes into a table of open files that the Operating System maintains for each process)

Input/Output Redirection

Two other operations can be used to manipulate file descriptors: Input/output redirection is accomplished by:

Example: input redirection

Example: output redirection