The problem with fuser (or lsof) is that it'll tell you the process has an open descriptor for the file, but that doesn't say anything about if it's actively writing to it. You could use something like SGI::FAM to tell if the file's being modified and then do your work when a long enough window of non-activity's passed, but that's not much better.

If the logging program can handle it (i.e. you can establish some window you can shut it down without worrying about losing records) it may be simpler to just: stop the logger, do whatever processing you're wanting to (or make a copy of the file), and then restart the logger.


In reply to Re: How to detect if file is in use? by Fletch
in thread How to detect if file is in use? by blazar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.