8

Someone mentioned that there are three different files that a process always opens. What does this mean? What files are they?

11

The files that are opened are not files on disk. They are the streams (pseudo files), stdin (0), stdout (1), and stderr (2). Here is the relevant excerpt from the POSIX standard:

A file with associated buffering is called a stream and is declared to be a pointer to a defined type FILE. The fopen() function shall create certain descriptive data for a stream and return a pointer to designate the stream in all further transactions. Normally, there are three open streams with constant pointers declared in the header and associated with the standard open files.

At program start-up, three streams shall be predefined and need not be opened explicitly: standard input (for reading conventional input), standard output (for writing conventional output), and standard error (for writing diagnostic output). When opened, the standard error stream is not fully buffered; the standard input and standard output streams are fully buffered if and only if the stream can be determined not to refer to an interactive device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.