From owner-freebsd-hackers@FreeBSD.ORG Sat Aug 28 14:16:25 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 1233) id EBE541065675; Sat, 28 Aug 2010 14:16:25 +0000 (UTC) Date: Sat, 28 Aug 2010 14:16:25 +0000 From: Alexander Best To: freebsd-hackers@freebsd.org Message-ID: <20100828141625.GA69240@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: tiny patch to prevent head from closing pipes 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: Sat, 28 Aug 2010 14:16:26 -0000 hi there, i just had subversion complain about a broken pipe while piping its output through awk straight to head [1]. i decided to add a switch to head which will tell it to never close a pipe unless the input has stopped [2]. of course this will produce massive overhead, but some people might find this behaviour usefull. here's a simple benchmark: `time hd test_file | head`: => hd test_file 0,00s user 0,00s system 89% cpu 0,004 total head 0,00s user 0,00s system 55% cpu 0,004 total vs. `time hd test_file | head -k`: => hd test_file 3,28s user 0,03s system 95% cpu 3,465 total head -k 0,04s user 0,02s system 1% cpu 3,465 total test_file was created using: `dd if=/dev/random bs=1m count=5 of=test_file` there's probably a much more efficient way of discarding the input without closing the pipe unless the input ceased. it's just a 5 minute hack in order to see if people find the idea useful or not. ;) cheers. alex [1] `http://people.freebsd.org/~arundel/scripts/whodid2.sh ls` [1] http://people.freebsd.org/~arundel/patches/head.diff -- a13x