What part of the system sets up the buffering of the three standard streams when a program is started?
Is this part of linux, or glibc, or maybe bash? Does POSIX define the behaviour, or is it part of C?
Posix has some answers:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_05
At program start-up, three streams are predefined and need not be opened explicitly: standard input (for reading conventional input), standard output (for writing conventional output), and standard error (for writing diagnostic output). When opened, the standard error stream is not fully buffered; the standard input and standard output streams are fully buffered if and only if the stream can be determined not to refer to an interactive device.
So if the system can determine that streams are NOT interactive, they CAN be fully buffered (except stderr), but in practice what part of the system does this determining?
stdio
tag. Notice that many programs don't do any userland buffering (eg.cat
), and other programs do their own, different from and bypassingstdio
(eg.PerlIO
inperl
). – Apr 23 '19 at 03:14