Results 1 to 4 of 4

Thread: standard I/O streams

  1. #1
    Join Date
    Apr 2020
    Location
    where the work takes me
    Beans
    243
    Distro
    Ubuntu 20.04 Focal Fossa

    standard I/O streams

    Hello all,

    I'm a little confused by the concept of stdin, stdout, stderr and their file descriptors.

    On the whole I understand but what I can't work out is this; if each process gets three streams when it's initialised, and by default they point to the controlling terminal, how is it that they are able to be represented by the file descriptors 0, 1 and 2?

    I would think each stream for each individual process would need it's own file descriptor because they could connect to different terminals?

    Are stdin, out and err basically three streams that are shared by multiple processes?

    I hope that makes sense

  2. #2
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,220
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: standard I/O streams

    I found this - hope it helps. The file descriptor is local to a process, and somewhere, there is a lookup from the process's descriptor to the real file structure.
    https://en.wikipedia.org/wiki/File_descriptor

  3. #3
    Join Date
    Oct 2005
    Location
    Lab, Slovakia
    Beans
    10,329

    Re: standard I/O streams

    You can change the file descriptors - it doesn't have to be 0, 1 and 2. By doing that, you can do quite complex things with IO streams.

    You can change the descriptors with the exec command for example.

    See this: https://wiki.bash-hackers.org/howto/...ction_tutorial

    and maybe see serial port redirection described here:
    https://www.aeronetworks.ca/2015/10/...om-serial.html

  4. #4
    Join Date
    Apr 2020
    Location
    where the work takes me
    Beans
    243
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: standard I/O streams

    Quote Originally Posted by HermanAB View Post
    You can change the file descriptors - it doesn't have to be 0, 1 and 2. By doing that, you can do quite complex things with IO streams.

    You can change the descriptors with the exec command for example.

    See this: https://wiki.bash-hackers.org/howto/...ction_tutorial

    and maybe see serial port redirection described here:
    https://www.aeronetworks.ca/2015/10/...om-serial.html
    Quote Originally Posted by The Cog View Post
    I found this - hope it helps. The file descriptor is local to a process, and somewhere, there is a lookup from the process's descriptor to the real file structure.
    https://en.wikipedia.org/wiki/File_descriptor
    Thanks to you both! what I now understand is that the terms stdin, stdout and stderr refer to the data streams themselves, and not the source / destination of those streams. All programs get three streams by default and because everything is handled like a file, each stream gets it's own file descriptor on a per process basis. 0 = stdin, 1 = stdout and 2= stderr. Your first link HermanAB probably does the best job of explaining it that I've seen anywhere on the web.

    Thanks again to you both!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •