[erlang-questions] size of an open file
Thu May 15 17:19:40 CEST 2008
I occasionally check the 'file modified' timestamp (file:read_file_info/1)
and if it is later than the last time I saw data from a read, I close/open
the file for further reads. I use a timer (timer:apply_after/4) which gets
reset each time I read data. If timer expires (i.e. have not read data in
N amount of time) a fun is run which does the check. Good enough for my
current use, maybe not for yours (you have to know how often you are
expecting new data).
On Thu, May 15, 2008 at 11:06:07AM +0200, Bengt Kleberg wrote:
> If I understand you correctly you have the resources to do the
> open the file and start to read from it. When you hit eof you wait a
> while and try again. After some time of getting nothing but eof you can
> test if the current position is bigger than the file size of the
> original file name. When this happens you close the current file and
> open the original file name. Repeat.
> This will fail if the current file is (re)moved at position 1000, and
> the new file with the original name manages to fill up to exactly 1000
> before you test its size. Given a program that rapidly fills many small
> files with exactly the same content that is not unlikely.
> If you have that scenario you need to know how fast the file fills so
> that you can test its size before it manages to become full.
> On Thu, 2008-05-15 at 16:55 +1000, jm wrote:
> > Bengt Kleberg wrote:
> > > Greetings,
> > >
> > > What are your requirements?
> > > Do you have enough time/cpu/etc to open/close the file when reading the
> > > tail part of it?
> > >
> > >
> > > bengt
> > >
> > >
> > This started as a programming exercise while I had nothing better to do
> > waiting for a quote from a vendor. The idea was to get more experience
> > with erlang by writing something which normally has side effects and to
> > use some of the functions which I've not used in erlang yet. I decided
> > to try and imitate unix's "tail -F" to some extent, ie tail with follow
> > file. There isn't any requirements beyond that. What I have at the
> > moment reads in from a file and breaks it into lines. There are two
> > version one which returns the lines and continutation info and another
> > which uses lists:foreach to call a passed in function on each line.
> > The next step is to add the follow file functionality. Speed is not
> > important. I may us it later in a program. If that happens then I'd be
> > reading from multiple files similtaneously, so concurrentency may be.
> > Jeff.
> > _______________________________________________
> > erlang-questions mailing list
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> erlang-questions mailing list
More information about the erlang-questions