if ($pid > 0) { flock($fh,LOCK_EX); print "got the lock" } else { sleep(20) }