[RFC] Force stdio output streams to line-buffered mode
Jeremie Le Hen
jeremie at le-hen.org
Sat Feb 19 19:10:38 UTC 2011
Hi,
I've been annoyed multiple time when running a command such like
iostat -x 1 | grep -v ad10 | cat -n
The problem stems from two factors:
- grep's stdio sees that its stdout is not a terminal, so stdout is
full buffered and not line-buffered;
- iostat produces output too slowly so the aforementioned buffer takes
numerous seconds to be filled and flushed to the last command.
This problems is not specific to FreeBSD, it is actually a consequence
of POSIX specification. I've checked this on Solaris and Linux.
I've attached a small patch for stdio, so if the environment variable
STDIO_IOLBF is set, the output streams will be line-oriented by default.
iostat -x 1 | env STDIO_IOLBF=1 grep -v ad10 | cat -n
Before send it as a PR, I would like to hear your comments about this,
especially:
- the variable name (no bikeshed please, I just ask this if there is a
naming convention I'm not aware of);
- the documentation: I've put a hint in stdio(3) manpage and put the
full explanation in setvbuf(3).
Thanks.
Regards,
--
Jeremie Le Hen
Humans are born free and equal. But some are more equal than others.
Coluche
-------------- next part --------------
A non-text attachment was scrubbed...
Name: STDIO_IOLBF.diff
Type: text/x-diff
Size: 2018 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20110219/cdd87874/STDIO_IOLBF.bin
More information about the freebsd-current
mailing list