chb has asked for the wisdom of the Perl Monks concerning the following question:
If this sub returns true, you have got the lock, it is nonblocking. My Question is: Is this really the way to do it if you have to deal with NFS, or is there a more elegant way ?sub lock { my $lockhelper="lockhelper-$ENV{HOSTNAME}-$$.LCK"; my *LOCK; my $nlink; open(LOCK, ">$lockhelper") or die "Couldn't open() $lockhelper: $!"; + print LOCK "$ENV{HOSTNAME};$$\n"; close(LOCK); link($lockhelper, "lockfile.LCK"); (undef,undef,undef,$nlink,undef,undef,undef,undef, undef,undef,undef,undef,undef) = stat($lockhelper); unlink($lockhelper); return $nlink==2; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File locking on NFS
by lhoward (Vicar) on Apr 04, 2001 at 17:52 UTC | |
by tye (Sage) on Apr 04, 2001 at 21:18 UTC | |
by tilly (Archbishop) on Apr 05, 2001 at 00:43 UTC | |
by tye (Sage) on Apr 05, 2001 at 09:59 UTC | |
by tilly (Archbishop) on Apr 05, 2001 at 15:17 UTC | |
|
Re: File locking on NFS
by Anonymous Monk on Apr 04, 2001 at 22:39 UTC | |
by Anonymous Monk on Apr 04, 2001 at 22:43 UTC |