Discussion:
Annihilating data
(too old to reply)
Paul-Jürgen Wagner
2018-11-02 18:56:09 UTC
Permalink
Dear Bashers,

I have a pipe who's last command ('analyse') should throw away the data
for a specified amount of time ('end') and then start processing it. My
current solution is

function analyse {
local count=<some sensible number>
while (( $(date '+%s') < end ))
do
dd bs=1024 count=$count status=none iflag=fullblock of=/dev/null
done
<now the magic starts>
}

This works reasonably, but I am pretty sure that there is a much smarter
solution to this, probably by using cat, putting it in the background,
sleeping for the skip-duration and then killing it? Any comments or
tips?

Thanks a lot,

Paul
Quentin L'Hours
2018-11-02 20:38:48 UTC
Permalink
Post by Paul-Jürgen Wagner
This works reasonably, but I am pretty sure that there is a much smarter
solution to this, probably by using cat, putting it in the background,
sleeping for the skip-duration and then killing it?  Any comments or tips?
I would have done this as you described (cat + sleep + kill), though I
think this isn't the best solution either:

analyze() {
cat <&0 > /dev/null &
sleep "$end"
kill "$!"
<process the rest>
}
--
Quentin
Loading...