How can I check if a lock is held by someone else while using IPC::Shareable in perl. I have the below code:
my $resource = 0;
my $resource_handle = tie $resource, 'IPC::Shareable', undef , { destroy => 1 };
my $child = fork;
unless ($child) {
$resource_handle -> shlock();
sleep 10;
$resource_handle -> shunlock();
exit(0);
}
sleep 2;
if ($resource_handle -> shlock(LOCK_EX)) {
print "Got lock in parent\n";
$resource_handle -> shunlock();
} else {
print "The shared resource is locked\n";
}
This prints "Got lock in parent" after 10 seconds while I want it to print "The shared resource is locked".