#!/usr/bin/perl -w

# reader.pl
# Reads from myfile.dat

use Fcntl ':flock';

open(FILE, "<myfile.dat") or die "Cannot open myfile.dat!\n";

print "[$$] Requesting shared read lock for myfile.dat.\n";
flock(FILE, LOCK_SH); 
print "[$$] Requested shared read lock for myfile.dat.\n";

print "[$$] Reading from myfile.dat.\n";
while (<FILE>) {
	sleep 1;
	print $_;
}

flock(FILE, LOCK_UN);	# release lock
print "[$$] Released shared read lock for myfile.dat.\n";
close FILE;
