in reply to How to detect if file is in use?

How about you make a copy of the file, wait one second, then check the size of the copy against the original? If the sizes are different, the original is still being written to, and you should wait x number of seconds and then repeat the procedure.

Replies are listed 'Best First'.
Re^2: How to detect if file is in use?
by 5mi11er (Deacon) on Mar 17, 2005 at 22:50 UTC
    But then you've transformed the problem into something completely different, but not necessarily more easily solved. The new question becomes how long must you wait to ENSURE that log file is not being appended to? One second may not be long enough, nor 10, 100, 1000 etc.

    -Scott

Re^2: How to detect if file is in use?
by gloryhack (Deacon) on Mar 18, 2005 at 23:22 UTC
    Ignoring for a moment that some logfiles can remain open for several days without seeing a new entry -- what's the point in making a copy? Just do -s $file or (stat($file))[7] at t0 and t1..tn and save some disk space. It won't tell you if the file is open, but it will tell you if it's changing while you're looking at it.