Asynchronous pipe I/O

rihad rihad at
Wed Nov 5 11:10:40 PST 2008

Nate Eldredge wrote:
> On Wed, 5 Nov 2008, rihad wrote:
>> Imagine this shell pipeline:
>> sh prog1 | sh prog2
>> As given above, prog1 blocks if prog2 hasn't yet read previously written
>> data (actually, newline separated commands) or is busy. What I want is
>> for prog1 to never block:
>> sh prog1 | buffer | sh prog2
> [and misc/buffer is unsuitable]
> I found an old piece of code laying around that I wrote for this 
> purpose. Looking at it, I can see a number of inefficiencies, but it 
> might do in a pinch.  You're welcome to use it; I hereby release it to 
> the public domain.
> Another hack that you could use, if you don't mind storing the buffer on 
> disk rather than memory, is
> sh prog1 > tmpfile &
> tail -f -c +0 tmpfile | sh prog2
Thanks, but I was looking for how to get some port do that useful 
functionality for me. Strange as it is, there doesn't seem to be such a 
tool handy, despite the "small tool doing one thing good" philosophy of 
Unix! It's invaluable for optimizing certain tasks and isn't coupled to 
anything: as generic as could be. Perhaps I should also email buffer's 
author <jonny at> for his opinion, and ask him why -p 0 
(default) doesn't do the Right Thing.

> Here's my program.
Thanks again, I'm sure I'll use your code if I can't get the port 
version to work.

More information about the freebsd-hackers mailing list