#! /usr/bin/perl -w

use Fcntl qw(LOCK_SH LOCK_EX LOCK_UN);

$child = fork();

open(TESTLCK, ">testlock");

if ($child == 0) { # in child

	print "locking ex\n";
	flock(TESTLCK, LOCK_EX);

	print "holding ex lock for 3 seconds\n";
	sleep 3;
	flock(TESTLCK, LOCK_UN);
	print "done\n";

} else {

	print "locking shared\n";
	flock(TESTLCK, LOCK_SH);
	
	print "holding sh lock for 3 seconds\n";
	sleep 3;

	flock(TESTLCK, LOCK_UN);
	print "done, waiting for child to finish\n";
	wait;
}
