Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Check if file is being modified by another process

Reply
Thread Tools

Check if file is being modified by another process

 
 
kyle.halberstam@gmail.com
Guest
Posts: n/a
 
      07-04-2007
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

 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      07-04-2007
<(E-Mail Removed)> wrote in comp.lang.perl.misc:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 2 11-29-2006 04:30 AM
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 0 11-28-2006 09:13 AM
Process Cannot access file "file_name" because it is being used by another process Rithesh Pai ASP .Net 1 08-22-2005 03:02 PM
delete file failed, The process cannot access the file because it is being used by another process guoqi zheng ASP .Net 3 04-13-2005 06:17 PM
The process cannot access the file because it is being used by another process. Jerry ASP .Net 4 12-15-2003 06:07 PM



Advertisments