Next File Locking 8

Trick #3: Warning when Waiting

        #!perl
        use Fcntl ':flock';
        my $file = shift or die ...;
        open F, "< $file" or die ...;
        flock F, LOCK_EX or die ...;
        system($ENV{EDITOR}, $file);
        unless (flock F, LOCK_EX | LOCK_NB) {
          warn "File $file already locked; waiting...\n";
          flock F, LOCK_EX or die ...
        }
        unless (flock F, LOCK_EX | LOCK_NB) {
          warn "File $file already locked; waiting...\n";
          alarm 60;
          flock F, LOCK_EX or die ...
        }


Next Copyright © 2003 M. J. Dominus