[Tutor] tail -f

dman dman@dman.ddts.net
Wed, 27 Mar 2002 10:09:54 -0600


On Tue, Mar 26, 2002 at 08:13:38PM -0800, Danny Yoo wrote:
| > So basically, they open the file, and just stare at it's size, forever (or
| > until the user gets tired).  Whenever the file size changes, it just
| > prints the remainder out to screen.  They do something like a time.sleep()
| > to make the busy waiting look less bad.  *grin* By default, they poll
| > every 1 second:
| >
| > /***/
| > static unsigned int sleep_interval = 1;
| > /***/
| 
| Here's an example of how we might do it in Python:
...

Thanks Danny!  I guess I did my searching the wrong way.  I started
with the argument parsing to see what flags would be different when
'-f' is passsed, and then seeing where those flags are used.  I also
assumed it wasn't busy-waiting since it puts almost no load on the
system.  I think the size thing is important since asking for the size
of an open file is likely faster than trying to read from it and
hitting EOF.  Hmm, it's also probably important to _not_ hit EOF when
reading the stream so that when the size increases the fread() won't
fail.

Seeing the essence of the algorithm without all the other "noise"
around it makes it much clearer.

-D

-- 

Only two things are infinite, the universe and human stupidity, and I'm
not sure about the former.
        Albert Einstein