[Discuss] bash output buffering

Daniel Hagerty hag at linnaean.org
Wed Jun 13 08:55:20 EDT 2012


John Abreau <abreauj at gmail.com> writes:

> On Wed, Jun 13, 2012 at 7:06 AM, Edward Ned Harvey <blu at nedharvey.com> wrote:
>
>> A command inside of bash generates output every second (ping) redirected to
>> a file.
>> If you run the command on an interactive shell, then you can tail -f the
>> file, and see the output "live" as it happens.
>> But if you run the command inside an "at" script, or a cron script, you tail
>> -f the file... And nothing appears for a few minutes, and then it all
>> appears suddenly.
>>
>> This is bash buffering the output of ping, before redirecting to file. All
>> of which is a level above the OS filesystem buffering.
>
> What you're describing is the difference between OS tty buffering vs
> OS filesystem buffering. This has nothing at all to do with bash; both
> occur below bash at the OS level.
>
> The difference is that OS filesystem buffering is block-oriented, and
> OS tty buffering is character-oriented.

    Just to add something to google for, Ed is probably dealing with
stdio buffering.  setvbuf(3).  Technically libc, rather than the OS.  I
don't know if bash exposes anyway to fiddle with it, a brief google
mentioned an LD_PRELOAD hack.



More information about the Discuss mailing list