Beta Shell
v2.0 ยท web2.us.cloudlogin.co
[FM]
[CMD]
[PHP]
[DB]
[INFO]
[SEC]
File Manager
~
/
usr
/
share
/
doc
/
perl-File-NFSLock
/
examples
Upload
3 items
Name
Size
Perms
Modified
Actions
[ .. / .. ]
lock_test
950 B
-rw-r--r--
2014-07-26 15:00:26
Edit
Del
Editing: lock_test
(950 B)
Path: /usr/share/doc/perl-File-NFSLock/examples/lock_test
Back
#!/usr/bin/perl -w ### Written by Rob Brown ### This script is designed to be ran on multiple boxes ### by multiple processes with a high increment number. ### The processes should all compete, but a successful ### test occurs if all of the specified inc's add up to ### the final number in the specified file. use strict; use File::NFSLock (); use Fcntl qw(O_RDWR O_CREAT LOCK_EX); my $datafile = shift; my $inc = shift || do { print "Usage: $0 <filename> <increment>\n"; exit; }; while ( $inc -- > 0 ) { my $lock = new File::NFSLock ($datafile, LOCK_EX) or print "Ouch1\n"; # blocking lock (Exclusive) sysopen(FH, $datafile, O_RDWR | O_CREAT) or die "Cannot open [$datafile][$!]"; ### read the count and spit it out my $count = <FH>; $count ++; print "[$$] I win with [$count] \r"; seek (FH,0,0); print FH "$count\n"; close FH; # $lock leaves scope and unlocks automagically } print "\n\n";