Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Feb 2011 09:49:22 -0500
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-current@freebsd.org
Cc:        Jeremie Le Hen <jeremie@le-hen.org>
Subject:   Re: [RFC] Force stdio output streams to line-buffered mode
Message-ID:  <201102220949.22736.jhb@freebsd.org>
In-Reply-To: <20110219185043.GA6573@felucia.tataz.chchile.org>
References:  <20110219185043.GA6573@felucia.tataz.chchile.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201102220949.22736.jhb>