Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Aug 2010 14:16:25 +0000
From:      Alexander Best <arundel@freebsd.org>
To:        freebsd-hackers@freebsd.org
Subject:   tiny patch to prevent head from closing pipes
Message-ID:  <20100828141625.GA69240@freebsd.org>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100828141625.GA69240>