Check if file is being modified by another process

  • Thread starter kyle.halberstam
  • Start date
K

kyle.halberstam

Hi,

I have an application that creates and writes to an output file I need
to process. I need to process the file when it is completely written
to. I do not initially know how big the file will be in the end.
Further, the application does NOT put a write lock on the file while
it is writing it. because of the buffering, the program wirtes to the
file in random chunks not continuously. And what is worse, the file
format itself could vary so there is nothing in the actual file that
signals the end of it. Everything is on a linux server.

What's the most efficient way of checking this? - one way is perhaps
inifinite loop checking mmtime until it is stable for a certain amount
of time?? I am not sure.

Any help will be greatly appreciated. Thanks


Kyle
 
A

anno4000

Hi,

I have an application that creates and writes to an output file I need
to process. I need to process the file when it is completely written
to. I do not initially know how big the file will be in the end.
Further, the application does NOT put a write lock on the file while
it is writing it.

Start the application from a Perl script that does hold a lock.
Roughly:

use Fcntl qw( :flock);

my $out = shift;
$^F = 10_000;
open my $o, '>', $out or die "Can't create '$out': $!";
flock $o, LOCK_EX;
exec '/the/application', '-o', $out;

(Assuming -o sets the output file of the application.)

Setting $^F makes sure the filehandle isn't closed across exec(),
see perlvar. If you use system() instead of exec() you don't need
it.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top