This all depends on what you mean by "being written". On POSIXy systems, syswrite, mtime & friends should be regarded as atomic (but probably not recovering from errors), so any OS-level write should update mtime, filesize etc - regardless of if the write is actually written to disk yet.

OS-level caching is completely transparent to these operations. Which also means that there's no such thing as "being written" - the data has either been written (given no errors occurred), or none of it has. From the POV of these operations there is no in between.

For instance:

#!/usr/local/bin/perl -w use strict; open F,">/tmp/test" or die $!; for (1 .. 1000) { syswrite F,"."; my $s = -s F; warn "$s != $_" if $s != $_; }
The code above reports no anomalies on my system.

Confusion may set in because perl does some additional caching by itself (when using the canonical print(f) function):

#!/usr/local/bin/perl -w use strict; open F,">/tmp/test" or die $!; for (1 .. 1000) { print F "."; my $s = -s F; warn "$s != $_" if $s != $_; }
Gives:
0 != 1 at test.pl line 7. 0 != 2 at test.pl line 7. 0 != 3 at test.pl line 7.
etc etc.

See also syswrite.

updated to fix typo in second example

update 2: bottom line:

If your remote program sends write()s to the system often enough, and/or your peeking of mtime etc is infrequent enough, your strategy should work. But any program doing fairly heavy caching by itself (and I would guess many interesting programs do) may throw it off. So be conservative when choosing your intervals.


In reply to Re: Do the File::Stat values Update While a File is Being Written? by Joost
in thread Do the File::Stat values Update While a File is Being Written? by Anonymous Monk

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.