Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Re: Determine if script is already running

by Nitrox (Chaplain)
on Mar 03, 2003 at 14:01 UTC ( [id://240026]=note: print w/replies, xml ) Need Help??

in reply to Re: Determine if script is already running
in thread Determine if script is already running

Abigail also suggested a persistent lock in her post and it's the direction I'm headed. Which brings me to another question:

Are there any pitfalls to holding a lock for an extended period of time? (we're talking weeks here)


  • Comment on Re: Re: Determine if script is already running

Replies are listed 'Best First'.
Re: Re: Re: Determine if script is already running
by paulbort (Hermit) on Mar 03, 2003 at 17:28 UTC
    Only one comes to mind: IMNSO, the only OSes I've seen that don't do better with weekly restarts are VMS and MVS (maybe OS/390, I haven't worked with it much.)

    Holding a lock for a week at a time and doing a controlled restart should be entirely safe under Windows NT 4.0 or later, any modern Linux, SCO, etc.

    Rather than re-inventing the wheel, are there parts of Big Brother or Nagios that could save you some coding time?

    Abigail: Thanks for the good idea, I've got a problem similar to Nitrox's in my current project and I like your solution an awful lot better than what I'm doing now. ++.

    Spring: Forces, Coiled Again!
Re: Re: Re: Determine if script is already running
by Limbic~Region (Chancellor) on Mar 03, 2003 at 20:51 UTC
    As I indicated in my first post. Using a lock file by itself, regardless of type, will not guarantee only a single copy of a script is running in Unix. This is because it is possible to delete a file that is locked. Using the /tmp directory most likely increases the odds of deletion by its nature. The subsequent instance of the script is able to create and lock the new file - and now you have two copies running. You really need to have multiple methods for validation and checking the process table is a good place to start.

    Cheers - L~R

      This bugs me, why does *nix allow deletion of an open and locked file? On Win32 a file can't be deleted until the ref count == 0, is there a way to explicitly set this in *nix?


        Not that I know of. There are things you can do to reduce the probability that the file will be accidentally deleted - security through obscurity. These things include:

      • Changing the directory where the file resides permissions to 000.
      • Use non-typical characters in the file name such as a space, asterick, or worse.
      • Use alarm for the original script to check if the file has been deleted and re-create. * This requires a lot of overhead to try and compete with the race condition.
      • Use hard links (not symbolic) so that more than one file combined equal your lock file

        Even with these suggestions, there is not the 100% guarantee. Sometimes you need decide that the probability is an acceptable risk and move on. If you are totally against checking the process table - semaphores may be the way to go.

        Cheers - L~R

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://240026]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-23 01:44 GMT
Find Nodes?
    Voting Booth?

    No recent polls found