in reply to locking over the network
If windows supports hard links you could try something like this.
#!/usr/bin/perl use strict; use warnings; open my $fh, ">", "mylock.$$" or die "open mylock.$$: $!"; sleep 2 until get_lock(); print "locked> "; <>; unlink "mylock"; # releases the lock unlink "mylock.$$"; # just cleaning up sub get_lock { link "mylock.$$", "mylock" and return 1; return (stat "mylock.$$" )[3] == 2; }
The above is based on the discussion of portably locking with link(2) as found on the Linux man page for open(2) in the O_EXCL discussion.
Edit: added comments because one unlink matters and the other doesn't.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: locking over the network
by rovf (Priest) on Feb 01, 2011 at 10:14 UTC | |
by rowdog (Curate) on Feb 02, 2011 at 01:46 UTC | |
by tye (Sage) on Feb 02, 2011 at 03:20 UTC | |
by rowdog (Curate) on Feb 02, 2011 at 17:30 UTC | |
by tye (Sage) on Feb 02, 2011 at 18:09 UTC |
In Section
Seekers of Perl Wisdom