[arch-general] broken pipe

Ralph Corderoy ralph at inputplus.co.uk
Thu Dec 19 10:59:04 UTC 2019


Hi Pascal,

> file_info(){
>     echo -n ${1:=/dev/stdin}$'\t'
>     (
>         tee < "${1}" \
>             >( file --mime-type -b -e compress -e tar -e elf - >&3 ) \
>             >( md5sum >&3 ) \
>             >( sha1sum >&3 ) \
>             >/dev/null
>     ) 3>&1 |
>     tr '\n' '\t'
>     echo
> }
>
> it no longer works because the data flow is quickly interrupted by tee
> which does not consume all the data.

You're missing the reason why.  tee(1) receives a SIGPIPE because it
writes to a pipe that's closed.  Adding a cat(1) is a waste of CPU, as
is discarding tee's stdout instead of using it for one of the workers.

Examine these differences.

    $ seq 31415 | wc
      31415   31415  177384
    $ seq 31415 | tee >(sed q) >(wc) > >(tr -d 42 | wc); sleep 1
    1
      14139   14109   62130
      12773   12774   65536
    $ seq 31415 | (trap '' pipe; tee >(sed q) >(wc) > >(tr -d 42 | wc)); sleep 1
    1
      31415   31369  142504
      31415   31415  177384
    $

Note the output of the commands can be in any order, and intermingle if
they're long enough.

tee(1) has -p and --output-error but they're not as specific as stating
SIGPIPE is expected for just one worker.

-- 
Cheers, Ralph.


More information about the arch-general mailing list