Quais são os três arquivos sempre abertos por um processo?

8

Alguém mencionou que há três arquivos diferentes que um processo sempre abre. O que isto significa? Quais arquivos são eles?

    
por unix_newbie 25.04.2015 / 06:29

1 resposta

11

Os arquivos abertos não são arquivos no disco. Eles são os streams (pseudo files), stdin (0), stdout (1) e stderr (2). Aqui está o trecho relevante do padrão POSIX :

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.

    
por 25.04.2015 / 06:38