[TAG] Question about file mtime on linux

Pete Jewell pete at phraxos.nildram.co.uk
Thu Apr 14 00:27:54 MSD 2005


On Wednesday 13 Apr 2005 20:29, Suramya Tomar wrote:
> Hi Everyone,
> I have a question for you about file mtime(modify
> time) on linux. Does the mtime stamp of a file change
> as soon as a process starts modifying the file or does
> it change it after the change is done?
>
> The reason I am interested in this is that I am
> writing a perl script which is supposed to monitor a
> file for changes and as soon as the change is done run
> another script which processes the changed file. I
> don't want
> the second script to run before the file change is
> complete(Which would happen if the mtime changes as
> soon as the modification starts).

>From past experience I seem to remember that the only 'pure perl' way to 
ensure that a file is not being modified, without relying on file locks, 
is to check the size/mtime of the file, wait a bit, and then check it 
again, repeat until the two size/mtimes are the same.

The reason I ran into this was because I was writing a routine to process 
a file after it had been uploaded to an ftp server.  In the end, because 
we had control over the ftp server, we configured it so that the uploader 
and my routine both logged into the ftp server using the same username, 
and restricted the number of times a user could concurrently login to 1.  
This did the trick quite nicely.

A good resource for perl questions is the Perl Monks website 
http://www.perlmonks.org - in fact I would go so far as to say that it is 
*the* best resource for perl information on the web.

-- 
Pete Jewell





More information about the TAG mailing list