in reply to Re^3: Ensuring only one copy of a perl script is running at a time
in thread Ensuring only one copy of a perl script is running at a time
I find extremely rude posts that do nothing but contradict the parent when the poster could have verified that the parent was correct.
You're wrong. flock does NOT use its own advisory locking. If flock implemented some kind of advisory locking, Windows's type command would know nothing of it, yet it can't read a file locked using flock.
use Fcntl qw( :flock );
open(my $fh, '>', 'file')
or die("Unable to open file: $!\n");
print $fh ("ok\n");
print("type without lock:\n");
or die("Unable to lock file: $!\n");
print("type with lock:\n");
type without lock:
type with lock:
The process cannot access the file because another process has locked
+a portion of the file.
Tested with 5.6.0, 5.6.1, 5.8.0 and 5.8.8.
Update: Updated to show that type works when the file isn't locked by flock.