Subject: Re: bug#8490: dd reads random number of records from pipes - named or otherwise - coreutils 8.9

From: John Reiser <[email-masked]>
Date: Wed, 13 Apr 2011 08:02:06 -0700

> dd, when reading from stdin or from a named pipe sometimes (but not always) reads a random number of records a bit less then what it should.

> yes|dd bs=1000 count=1000|wc -c
> cat /dev/zero |dd bs=1000 count=1000 |wc -c

dd does "read(fd,buf,bs)" for 'count' times, and writes whatever it gets each time.
If the operating system does not deliver 'bs' bytes each time, then the total output
will be less than bs*count bytes.  Because neither /usr/bin/yes nor /dev/zero
generates records with a blocksize of 1000 bytes (nor divisible by 1000 bytes)
then you are at the mercy of multiprocessing delays and pipe buffering.  read()
on a pipe waits only for non-empty, not necessarily for the size requested.

--