[erlang-questions] size of an open file

Bengt Kleberg bengt.kleberg@REDACTED
Wed May 14 14:38:43 CEST 2008


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

On Wed, 2008-05-14 at 18:15 +1000, jm wrote:
> 
> Bengt Kleberg wrote:
> > Greetings,
> >
> > You have 2 possibilities according to the manual of the file module:
> > 1) file:position/2 should return the file size, if called with 'eof' as
> > Position
> > 2) if this is for debugging you can use file:pid2name/1 and get the file
> > name (for subsequent use in file:read_file_info/1).
> >
> >   
> 
> Thanks. Last question I hope. In attempting to tail a log file:  How do 
> you detect that the file has rolled over, ie a new log file has been 
> created?
> Is there a smarter way than comparing the size of the open file and the 
> size of the file by name? I can see a couple of problems with this method.
> To begin with if the new log file grows larger than the old log file 
> before there is a chance to switch files. I suppose you could do
> 
>  SizeOfOpen =:= SizeofNamedFile
> 
> but this doesn't seem right. Really, a comparison should be done on the 
> filenames, ie compare the name of the currently open file with that of 
> the requested filename to detect a roll over, but I don't see a 
> file:read_file_info/1 for open files.
> 
> Jeff.
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list