Re: [RFC] Force stdio output streams to line-buffered mode

From: John Baldwin <jhb_at_freebsd.org>
Date: Tue, 22 Feb 2011 09:49:22 -0500
On Saturday, February 19, 2011 1:50:43 pm Jeremie Le Hen wrote:
> 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).

Many people would find this useful I think.

-- 
John Baldwin
Received on Tue Feb 22 2011 - 15:20:01 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:11 UTC