On 29 December 2010 c. 13:12:21 Paul de Weerd wrote:
> On Wed, Dec 29, 2010 at 11:03:22AM +0300, Vadim Zhukov wrote:
> | On 29 December 2010 c. 04:12:34 Jeremy C. Reed wrote:
> | > tail -r
> |
> | tail(1) saves all data in memory. So if you want to reverse very big
> | file (say, some sort of log) you'll have to construct monsters with
> | help of awk/perl/etc.
>
> It does that for non-regular files, sure (how else would you do it ?
> You use a swapfile in your patch. So you assume (probably quite
> fairly, but not always valid I suppose) that there's more diskspace
> available than memory but you do so at significant cost in terms of
> disk access).
Yes, I thought about it, so I gave two different options: using
either "memory" or "swap". User of utility can choose one that best
suits his needs. I thought about some sort of automatic decisions, like
using memory until ENOMEM, but came to conclusion that this will produce
more harm, and require much more work from user to avoid it (like
setting up ulimits).
> But see /usr/src/usr.bin/tail/reverse.c:r_reg for regular files, this
> basically does what you do in print_swap.
Yes, a few people already told me about this. It does more seeking than
mine version: I do fread() x 3 + fseek() x 2 per line. "tail -r" does
fseek() + getc() per character. I'll try to do some benchmarking here.
Also, note that rev(1) will reverse whole input, while r_reg() in tail(1)
works on per-file basis.
Anyway this was good expirence for me: I was caught by difference between
off_t and size_t, and now will be more careful with them. :)
--
Best wishes,
Vadim Zhukov
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?