in reply to File Locking w/wo NFS
note that the arguments to fcntl (in the pack statement) are system-specific.#!/usr/bin/perl -w use strict; use Fcntl qw(F_WRLCK SEEK_SET F_SETLKW); open(F,"+< $ARGV[0]") or die "Couldn't lock myself: $!\n"; my $args = pack("sslli",F_WRLCK,SEEK_SET,0,0,$$); fcntl(F,F_SETLKW,$args) or die "Couldn't lock: $!\n"; print "File locked\n"; sleep(1000);
IIRC, compiling Perl with its own flock (instead of using the OS-provided one) will use an implementation built on top of fcntl, which should be NFS-safe, simpler to use, and more portable.
|
|---|