File descriptors in Linux

fd is a non-negative integer, an index value, pointing to the record table of the process's open files maintained by the kernel for each process .

A program opens an existing file or creates a new file , and the kernel returns a file descriptor to the process.

Each Unix process has three standard POSIX file descriptors, corresponding to three standard streams:

(ref:https://zh.wikipedia.org/wiki/%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6

integer value name < unistd.h > symbolic constants [1] < stdio.h > file stream [2]
0 Standard input STDIN_FILENO stdin
1 Standard output STDOUT_FILENO stdout
2 Standard error STDERR_FILENO stderr

 

Standard input : is the data (usually a file) input to the program. The program requires a read operation to transfer data.

C++ <iostream> variable is std::cin

Not all programs require input, such as ls

Unless redirected, input is expected to be obtained by the keyboard.

Standard output : C++ <iostream> variable is std::cout

Output to terminal (screen) unless redirected

Not all programs require output, like mv

Standard error : C++ <iostream> variables are std::cerr and std::clog

Default output to terminal (screen)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325344989&siteId=291194637