stdin stdout stderr - standard I / O stream

Fd #include <stdio.h> Fd extern FILE *stdin; Fd extern FILE *stdout; Fd extern FILE *stderr;

DESCRIPTION Description

Typically, each program will be opened when Unix startup three streams, one for input and one for output, or a diagnostic error message for printing. Typically, they are connected to the user's terminal (see tty (4)) but may also point to files or other devices, depending on what the parent process to select settings (see sh (1) redirection ( `` Redirection '' ) section.)

The input stream is referred to as `` standard input ''; the output stream is referred to as `` standard output ''; error stream is referred to as `` standard error ''. The term is usually abbreviated notation used to refer to these files, they are stdin stdout and stderr

These symbols, in (3) are each the stdio a macro, FILE pointer is a pointer type, can be used for similar fprintf (3) or fread (3) and the like functions.

Since FILE is buffered to a Unix file descriptor to be packaged, the lower the original document may be used to access the Unix file interface. That is similar to read (2) and lseek (2) function. Flow stdin stdout and stderr file descriptor associated with the integer 0, 1 and 2 respectively. Preprocessor symbol STDIN_FILENO, STDOUT_FILENO STDERR_FILENO respectively, and their values as defined in the in <unistd.h>.

Note FILE mix and raw file descriptors might bring unpredictable results, it should generally be avoided. (For people who like to get to the bottom: POSIX.1 specification 8.2.3 describes in detail how such a mix can not go wrong.) A simple rule is that file descriptors controlled by the kernel, while stdio is just a library. It means, for example, when calling exec, the child process can inherit all open file descriptors, but any existing streams can no longer access the.

Since the symbol stdin stdout and stderr is specified as a macro, the assignment will result in them not portable. Using the library function freopen (3), it can be used to point to a different standard stream file. This function is designed to introduce stdin stdout and stderr reassigned. Standard stream is closed when calling exit (3) and suspend normal procedures. 

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11100862.html