#! /user/bin/perl -w use strict; use Fcntl qw/:DEFAULT :flock/; my $filename = "/test.lock"; if (sysopen(FH, $filename, O_RDWR | O_CREAT | O_EXCL)) { print "Process locked.\n"; sleep(10); } else { print "Waiting for lock.\n"; while (!sysopen(FH, $filename, O_RDWR | O_CREAT | O_EXCL)) {}; print "Got the lock.\n"; } unlink($filename); close(FH);