Question about pipes - Linux

This is a discussion on Question about pipes - Linux ; I have a problem with pipes being rather slow to update. I just want to see if this is due to the program I'm using, or just a caveat of pipes in linux. My distro is debian etch on a ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Question about pipes

  1. Question about pipes

    I have a problem with pipes being rather slow to update. I just want to
    see if this is due to the program I'm using, or just a caveat of pipes
    in linux. My distro is debian etch on a very fast server.

    I'm using bwm-ng to output bandwidth statistics in CSV. It outputs new
    statistics twice a second. If I just use the command line:

    user@host:~$ bwm-ng -o csv

    I get the output at the proper rate.

    However, if I pipe the output to anything, or to a file, the output only
    comes every 5 seconds or so. It stores up 5 seconds worth of output and
    outputs it all at once. If I use a very simple shell script that just
    outputs its input (just to test what's going on):

    #!/bin/bash
    while read line
    do
    echo "$line\n"
    done

    and I pipe the program's output into this script:

    user@host:~$ bwm-ng -o csv | ./test_script.sh

    then I still get the slow output. At first I thought the program might
    not be adding proper linebreaks after each output, so I changed the
    script to output the input character for character instead of line for
    line - same issue. Is this a caveat of pipes, or is it the fault of
    bwm? Is there anything I can do to counter this?

    Thanks,
    Jeremy

  2. Re: Question about pipes

    On 2008-09-08, Jeremy wrote:
    > I have a problem with pipes being rather slow to update. I just want to
    > see if this is due to the program I'm using, or just a caveat of pipes
    > in linux. My distro is debian etch on a very fast server.
    >
    > I'm using bwm-ng to output bandwidth statistics in CSV. It outputs new
    > statistics twice a second. If I just use the command line:
    >
    > user@host:~$ bwm-ng -o csv
    >
    > I get the output at the proper rate.
    >
    > However, if I pipe the output to anything, or to a file, the output only
    > comes every 5 seconds or so. It stores up 5 seconds worth of output and
    > outputs it all at once. If I use a very simple shell script that just
    > outputs its input (just to test what's going on):
    >
    > #!/bin/bash
    > while read line
    > do
    > echo "$line\n"
    > done
    >
    > and I pipe the program's output into this script:
    >
    > user@host:~$ bwm-ng -o csv | ./test_script.sh
    >
    > then I still get the slow output. At first I thought the program might
    > not be adding proper linebreaks after each output, so I changed the
    > script to output the input character for character instead of line for
    > line - same issue. Is this a caveat of pipes, or is it the fault of
    > bwm? Is there anything I can do to counter this?


    The problem is that bwm-ng does not send any linebreaks; it uses
    ANSI escape sequences to position the cursor.

    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

+ Reply to Thread