Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: how to exit if tool is already running

by sflitman (Hermit)
on Aug 12, 2010 at 05:58 UTC ( [id://854586]=note: print w/replies, xml ) Need Help??


in reply to how to exit if tool is already running

Check out the excellent CPAN module Sys::RunAlone, it should help fix this problem. It cleverly locks your scripts DATA handle to prevent another invocation of the same script doing so. It's cross-Unix, but you'd need something fancier on Windows.

HTH,
SSF

  • Comment on Re: how to exit if tool is already running

Replies are listed 'Best First'.
Re^2: how to exit if tool is already running
by JavaFan (Canon) on Aug 12, 2010 at 09:18 UTC
    Considering flocking the data handle only takes a single line, there isn't much to gain from using a module (the module does more, but the OP doesn't need that). After ending the script with __DATA__ (or __END__), just add:
    flock DATA, 6 or die "Duplicate instance";
    Or use the Fnctl module and use LOCK_EX|LOCK_NB instead of 6.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found