Since, as a rule, when a program is called from an interactive terminal, without redirection, both standard input and standard output are connected to the same terminal device, for example /dev/tty (the actual device name changes depending on the current system).
The terminal device is a reader / writer. Reading from a terminal device reads the terminal output. Writing to a terminal device generates output on the terminal.
You still have discrete file descriptors, 0 and 1, but they are connected to the same device.
Think of it as a single bidirectional channel, which is dup ed for both file descriptors 0 and 1.
Linux behaves the same way (you can echo Foo >/dev/stdin and see the output):
$ ls -al /proc/self/fd/[01] lrwx------. 1 mrsam mrsam 64 Nov 22 21:34 /proc/self/fd/0 -> /dev/pts/1 lrwx------. 1 mrsam mrsam 64 Nov 22 21:34 /proc/self/fd/1 -> /dev/pts/1
So, for this process, file descriptors 0 and 1 are connected to /dev/pts/1 , the same pseudo-terminal device. Regardless of whether you read from file descriptor 0 or file descriptor 1, you end up reading from the same base device /dev , so it doesn't matter what actual file descriptor you use.
This, of course, depends on the operating system. Other POSIX-based operating systems can implement their standard input and output in other ways when you cannot write to standard input and read from standard output.
Sam varshavchik
source share