in reply to Checking for multiple instances

My favorite trick is ensuring that the file contains __END__, and then flocking DATA, which is open on the program file itself. No need to create a sentinel file that way.

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

Replies are listed 'Best First'.
Re^2: Checking for multiple instances
by Your Mother (Archbishop) on Sep 24, 2004 at 22:06 UTC

    That is very cool. Not to pester but would you give a snippet (or point to one) showing it in action?

      I can't find my working example right now, but from memory, something like this:
      #!/usr/bin/perl use Fcntl qw(LOCK_EX LOCK_NB); flock DATA, LOCK_EX | LOCK_NB or die "Already executing!"; ... rest of code ... # do not remove this __END__! __END__

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

        Thanks, that's plenty, I'm sure. I was just a'scared there might be a trick to it that was different from vanilla flock'ing.