On my linux system (GNU coreutils 8.12), I was able to check (using strace
) that tail -f
¹ uses the lseek
system call to skip over most of the file quickly:
lseek(3, 0, SEEK_CUR) = 0
lseek(3, 0, SEEK_END) = 194086
lseek(3, 188416, SEEK_SET) = 188416
This means that the size of the tracked file should not matter in anyway.
Maybe you can check if the same applies on your system. (Obviously, it should be the case.)
—
1. I also tried disabling inotify support with the undocumented ---disable-inotify
, just in case.
You don't need to tail -f
a tty. If it's sending you EOF, or, if it is line-buffering, then you need to configure it.
stty -F/dev/ttyAPP2 raw
Now you can...
cat /dev/ttyAPP2
...as needed...
You might try...
</dev/ttyAPP2 \
dd bs=16 conv=sync | od -vtx1
...which will sync out every successful read()
from your device into 16-byte, null-padded blocks, and so will write line-buffered output (such as to your terminal) in real-time regardless of throughput, though any trailing nulls might distort your stream.
With GNU stdbuf
and a dynamically linked od
:
stdbuf -o0 od -vtx1 </dev/ttyAPP2
...would write output in real-time regardless.
You might also buffer to a temp file like...
f=$(mktemp)
exec 3<>"$f"; rm -- "$f"
while dd >&3 of=/dev/fd/1 bs=4k count=1
[ -s /dev/fd/3 ]
do od -An -vtx1 /dev/fd/3
echo
done </dev/ttyAPP2 2>/dev/null
...which, though likely not nearly as efficient as the other recommendations, might be worth considering if you wanted to delimit reads from your device by EOF. I find the technique useful sometimes when working with ttys, anyway.
It is also possible to force hexdump
to print out less bytes by using the custom print format. The example below will print every time there are 4 bytes available:
hexdump -e '4/1 "%02x " "\n"' < /dev/ttyAPP2
Best Answer
This may also not be what you want, but how about:
Once both jobs are done, you get the non-waiting
tail
of both log files.