Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by bliako (Abbot)
on Dec 05, 2022 at 23:25 UTC ( [id://11148591]=note: print w/replies, xml ) Need Help??


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

why re-invent the wheel when there is already Proc::ProcessTable which you can enquire about your current processes? (and this approach was already mentioned in your previous question, see Re: Mechanism for ensuring only one instance of a Perl script can only run?)

Secondly, you hardcode /usr/bin/perl in the shebang and also in the script but those who will inherit the script will know that? And you assume that who runs the script will do it without appending it with a perl interpreter executable.

Thirdly, "simpler" may be but does it work under all conditions and circumstances? Hmmm. I would say, stick either with flock/highlander or with the shared-memory approach of Script::Singleton (my preference is with the memory-based approach which is more universal than the file-system approach).

Btw, if( index($line,$dirPerl) != -1  &&  index($line,$name) != -1 ) can be replaced with a regex

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:17 UTC
    Thanks bliako, Appreciate all that you say. I couldn't get the Proc::ProcessTable approach to work, sadly. My flock/highlander attempt ran into problems, too, which is why I'm back with more desperate ideas. I like the look of Script::Singleton, perhaps I'll try that next.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-07-24 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.