Standard I / O streams

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.

Content

  • 1 Standard Input
  • 2 Standard output
  • 3 Standard error output
  • 4 Other
  • 5 See also
  • 6 Notes
  • 7 Additional Information

Standard Input [edit]

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.

Standard output [edit]

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.

Standard error output [edit]

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.

Others [edit]

In DOS, you could also use the number 4 (stdprn) and 5 (stdaux) [1] .

See also [edit]

  • Console (computer science)
  • Posix
  • Redirection (UNIX)

Notes [edit]

  1. Ray Duncan Advanced MS-DOS Programming. - 2nd edition. - Microsoft Press, 1988. - p. 309. - ISBN 1-55615-157-8.

Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Operating Systems and System Programming

Terms: Operating Systems and System Programming