Linux Stdin – Line-Buffered Option with Stdbuf

bufferlinuxstdin

The man page for the stdbuf command states that line-buffered mode is invalid as a standard input buffering option.
What is the reason for this?

tail -f access.log | stdbuf -iL cut -d' ' -f1 | uniq

stdbuf: line buffering stdin is meaningless
Try `stdbuf --help' for more information.

Best Answer

Simplified, stdbuf is a wrapper around stdio functionality. Line buffering of input streams is undefined in stdio; I can find no standards document that says what it means, so it is literally meaningless as far as the standards go.

Assuming behavior analogous to stdout line buffering, the line buffering of stdin would require calling read() once for each character read, because there is no other way to guarantee that you don't read past a newline on a descriptor. Since the point of buffering is to reduce the number of system calls, it is unsurprising that the stdio library doesn't implement this.

Related Question