----- Original Message ----- 
From: "Jon Bjornstad" <[email protected]>

> 1 - How to ensure that there are not two versions of my script running?

One way is to have your script do something that prevents multiple instances 
of it from being run.
Something like:

##################################
use warnings;

my $remove = 1;

if(-f 'script.lockfile') {
  $remove = 0; # prevents removal of lockfile
  die "lockfile exists\n";
}

open(WR, '>', 'script.lockfile') or die $!;
close WR or die $!;

# Do the stuff you want to do here

END {
  if($remove) {
     warn "lockfile not removed" if !unlink 'script.lockfile';
  }
};
##################################

Of course, if you're worried that someone might manually remove the lockfile 
so that they can run multiple instances of the script, then that solution 
won't do. (Or maybe someone might manually create a 'script.lockfile' file 
so that *no* instances of the script can be run.)

And if there's a system crash while the script is running then the lockfile 
may not get removed automatically.

Another thing you can do is have the script connect to a socket. That way, a 
second instance of the script will try to connect to the same socket ... and 
fail as the socket is already in use. (Of course, if there's another 
entirely different process using the same port then you won't be able to run 
even one instance of the script.)

There are probably more sophisticated solutions, if needed.

Cheers,
Rob

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to