idsfa has asked for the wisdom of the Perl Monks concerning the following question:
I was challenged (in the CB) to come up with a file based locking mechanism that would solve atcroft's throttling problem. Additionally, I was asked that it
The following is my best stab. It looks a little too short to be correct ... can anyone see problems (and ideally, solutions)? You may want to cf. LockFile::Simple.
$LOCK = $0; $MAX_RUNNING = 10; sub lock_count { return scalar split /\s+/, `fuser $LOCK 2>/dev/null`; } die ("Too many running processes") if (&lock_count >= $MAX_RUNNING); open(LOCK) or die("Failed to acquire lock"); die ("Too many running processes") if (&lock_count > $MAX_RUNNING);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: File Based Throttling
by merlyn (Sage) on Oct 17, 2003 at 16:21 UTC | |
by idsfa (Vicar) on Oct 17, 2003 at 16:44 UTC | |
by atcroft (Abbot) on Oct 17, 2003 at 16:32 UTC | |
by merlyn (Sage) on Oct 17, 2003 at 17:46 UTC | |
by sweetblood (Prior) on Oct 17, 2003 at 17:11 UTC | |
by vek (Prior) on Oct 17, 2003 at 21:16 UTC |