File System Access

Processes can interact with the file system by navigating directories, and opening files for reading and writing. Every process has a current working directory (cwd), which it inherits from its parent. Relative file system paths are interpreted relative to this directory, and the process can change its current directory as needed.

File Descriptors

Each process can have multiple open files; the kernel tracks all of the open files for a process in a file descriptor table, which contains information such as the physical location of each file, the offset into the file where reads and writes should occur, error status flags, and several other data. Each of these file descriptors is assigned a file descriptor number which processes reference when requesting file operations (read, write, seek, etc) through kernel system calls.

There are three special file descriptors, numbered 0, 1, and 2, which are called standard in(put), standard out(put), and standard error, respectively. All programs expect to inherit these three streams from their parent process. They expect standard in to be open for reading (and, for obscure historical reasons, writing), and standard output and standard error to be open for writing. Many programs that only need one input stream and which produce one output stream never explicitly open any files themselves. Instead read input directly from standard in, produce output directly to standard out, and write any diagnostic information to directly to standard error.