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);

Remember, when you stare long into the abyss, you could have been home eating ice cream.

Replies are listed 'Best First'.
•Re: File Based Throttling
by merlyn (Sage) on Oct 17, 2003 at 16:21 UTC

      For the canonical definition of Unix, it's a required utility. atcroft is probably correct about the pathing issue.

      But then, you already knew that.


      Remember, when you stare long into the abyss, you could have been home eating ice cream.

      My guess is that it may be on the system, but just not in the path. Tried it as well, and on my home linux machine, I found it as /sbin/fuser ; on Solaris 7 and 8 machines I have access to, it was /usr/sbin/fuser. YMMV, however.

        Nope, it's nowhere.
        [localhost:~] merlyn% man fuser No manual entry for fuser
        This is Mac OSX, which is Mach/BSD based, arguably more "unix" than Linux is, because there are parts that were sold under the Unix label, unlike Linux.

        fuser is definitely definitely not-portable. And there's really nothing portable to replace it, either.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

      Even if you were to find fuser it is usually only available to root.

        Even if you were to find fuser it is usually only available to root.

        Er, that's not strictly true, any user can run fuser. I'm just a joe schmo user on a Solaris 9 box:

        [vek@alyssa - /home/vek]% fuser -u . .: 2053c(vek) 2017c(vek) 1351c(vek)
        -- vek --