in reply to Locking/unlocking program execution using a queue
If you run multiple instances of this script like so...#!/usr/bin/perl -w use strict; use Fcntl ':flock'; # import LOCK_* constants my $lockfile_path = "./lockfile"; open(LOCKFILE, ">$lockfile_path") or die "Can't open $lockfile_path: $ +!"; flock(LOCKFILE,LOCK_EX); print "got lock @ARGV\n"; sleep(10); print "finished sleeping @ARGV\n"; flock(LOCKFILE,LOCK_UN);
...you'll see them running in the correct order. As you point out, this does break if the flock fails and you need to get back in the queue though../test.pl 1 & ./test.pl 2 & ./test.pl 3 & ./test.pl 4 &
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Locking/unlocking program execution using a queue
by RazorbladeBidet (Friar) on Mar 31, 2005 at 13:17 UTC | |
by reasonablekeith (Deacon) on Mar 31, 2005 at 13:44 UTC | |
by RazorbladeBidet (Friar) on Apr 01, 2005 at 02:53 UTC |