[erlang-questions] size of an open file
Wed May 14 15:02:51 CEST 2008
jm <> wrote:
>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
>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.
It's not in general possible to find the name for an open file on *nix,
even outside Erlang - e.g. an open file may not have a name, or it can
have multiple names. What you want to check on *nix is the inode number
(and major/minor device number if you're really paranod, since inode
numbers are per-device). This is provided by file:read_file_info/1 -
again not for open files, but if you are opening the files, you can of
course call it before you open... Windows is another story of course.
More information about the erlang-questions