help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wait until the file is done


From: Seth David Schoen
Subject: Re: wait until the file is done
Date: Fri, 30 Oct 2020 12:21:11 -0700
User-agent: Mutt/1.9.4 (2018-02-28)

Mike Jonkmans writes:

> On Fri, Oct 30, 2020 at 11:10:18AM -0700, Russell Lewis wrote:
> 
> > Idea:
> > Instead of checking file size every thirty seconds and trying to be
> > precise, you could just wait 10m at a time, and terminate when you see
> > *any* window with no change.  Worst case, you end up waiting 19.99 minutes,
> > but that's probably acceptable for this application.

> Larger intervals leads to more energy use.
> But so does frequent polling.

If you're on Linux, you could also use inotifywait in order to have the
kernel proactively tell you when the file changes.

while inotifywait -t "$a" -e modify "$file"
do
    sleep "$b"
done

This will alternate waiting $a seconds for the file to change (notified
by the kernel, not polling) with sleeping for $b seconds (to ignore,
instead of tracking, potential sequential reads).  To actively monitor
all writes, you could replace the sleep "$b" with a : so that the loop
repeats immediately.  (It's still not as intense polling as checking the
file size with fstat, because inotifywait is sleeping during intervals
when the kernel isn't telling it about a filesystem event.)

If the file fails to be modified for $a seconds during a window in which
the script is looking for such a modification, the loop will terminate
and control will pass to the subsequent part of the script.

Unfortunately, the use of inotify isn't portable to other operating
systems.

-- 
Seth David Schoen <schoen@loyalty.org>      |  Qué empresa fácil no pensar
     http://www.loyalty.org/~schoen/        |  en un tigre, reflexioné.
  8F08B027A5DB06ECF993B4660FD4F0CD2B11D2F9  |        -- Borges, "El Zahir"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]