sub Sem_P { my $x; open(LOCK, ">$lockfile"); #Attempt to get a lock for($x = 0; ($x = $Lock_Tries) && !flock(LOCK, LOCK_EX | LOCK_NB); $x++) { #Sleep using select for a granularity #of less than 1 second select(undef, undef, undef, $Lock_Timeout); } return ($x =< $Lock_Tries); }