From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 5 19:10:40 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3FBEC1065678 for ; Wed, 5 Nov 2008 19:10:40 +0000 (UTC) (envelope-from rihad@mail.ru) Received: from mx33.mail.ru (mx33.mail.ru [194.67.23.194]) by mx1.freebsd.org (Postfix) with ESMTP id EECA48FC0C for ; Wed, 5 Nov 2008 19:10:39 +0000 (UTC) (envelope-from rihad@mail.ru) Received: from [217.25.27.27] (port=18691 helo=[217.25.27.27]) by mx33.mail.ru with asmtp id 1Kxnm2-000F7y-00; Wed, 05 Nov 2008 22:10:38 +0300 Message-ID: <4911EFAC.7090909@mail.ru> Date: Wed, 05 Nov 2008 23:10:36 +0400 From: rihad User-Agent: Icedove 1.5.0.14eol (X11/20080724) MIME-Version: 1.0 To: Nate Eldredge References: <4911A23B.7050104@mail.ru> In-Reply-To: Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Spam: Not detected X-Mailman-Approved-At: Wed, 05 Nov 2008 19:16:33 +0000 Cc: freebsd-hackers@freebsd.org Subject: Re: Asynchronous pipe I/O X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Nov 2008 19:10:40 -0000 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 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.