in reply to Ensure Only One Instance of Your Script is Running... with 'ps -ef' ?

I implemented this idea, but ran into management issues with the lock file. (The lock file was not deleted properly, it was overwritten, etc.)

Neither of these situations is a problem. The lockfile is only there to be locked. If it is absent, then there is no lock. If it is present a lock should be attempted. The contents of the file (if any) are irrelevant.

You have presented an alternative which is, by comparison, brittle. It relies on shelling out a lot and we know from experience that this can lead to problems.

If managing your own lockfiles with flock is too tricky then why not simply use Script::Singleton as stevieb suggested here? That's a simple, reliable solution.


🦛

  • Comment on Re: Ensure Only One Instance of Your Script is Running... with 'ps -ef' ?

Replies are listed 'Best First'.
Re^2: Ensure Only One Instance of Your Script is Running... with 'ps -ef' ?
by redapplesonly (Sexton) on Dec 06, 2022 at 15:10 UTC
    Thanks hippo, Appreciate you ruling that my second solution is "brittle"; that's the kind of expertise I lack and why I like this site so much. Appreciate the advice! I'm looking into Script::Singleton, as that sol'n looks perfect...