Lecture
Standard I / O streams on UNIX-like systems (and some others) are process flows that have a number (handle) reserved for performing some “standard” functions. As a rule (although not necessarily), these descriptors are already open when the task (executable file) is launched.
Stream number 0 (stdin) is reserved for reading user commands or input.
When interactively launching the program, the default is to read from a text-based user interface (keyboard) device. The UNIX command shell (and the shells of other systems) allow you to change the target of this stream using the “ <
” character. System programs (demons, etc.), as a rule, do not use this stream.
Stream number 1 (stdout) is reserved for data output, usually (though not necessarily) textual.
When interactively launching the program, the default is to record on a display device (monitor). The UNIX command shell (and the shells of other systems) allow you to redirect this stream using the “ >
” symbol. Tools for running programs in the background (for example, nohup) usually reassign this stream to a file.
Stream number 2 (stderr) is reserved for displaying diagnostic and debug messages in text form.
Most often, the purpose of this stream is the same as stdout, however, unlike it, the purpose of the stderr stream does not change when “ >
” and creating pipelines (“ |
”). That is, the debug messages of the process, the output of which is redirected, will still get to the user. The UNIX command shell allows you to change the purpose of this stream using the “ 2>
” construct. For example, to suppress the output of this stream, it is often written "2> / dev / null ".
The perror error handling POSIX function is used in the C and C ++ programming languages to display an error message in stderr based on the last error number stored in errno.
In DOS, you could also use the number 4 (stdprn) and 5 (stdaux) [1] .
Comments
To leave a comment
Operating Systems and System Programming
Terms: Operating Systems and System Programming