At 11:43 AM -0800 12/9/09, cerr wrote:
Hi There,

I use below code to make sure i have only one instance of my script
running at a time. But weirdly enough i sometimes seem to have running
two instances. This script is getting called on a regular basis by a
cron job and may take a long time (30+min)to complete but still...I
can't figure out what would be wrong with this code, anyone?

#[PID]
  #Check if PID file already exists
  if ( -s $PIDloc){
    print "THERE IS ALREADY AN INSTANCE OF UPDATESERVER RUNNING\n
check \"".$PIDloc."\"\n";
    syslog('info',"THERE IS ALREADY AN INSTANCE OF UPDATESERVER RUNNING
\n check \"".$PIDloc."\"");
    exit(999);
  }
  #if it doesn't exist, create it (gets ereased atr the bottom of MAIN
on completion)
  my $pid = $$;
  open my $fd,'>', $PIDloc or die $!;
  print $fd $pid;
  close $fd or die $!;
#[/PID]

Thanks for any hints or suggestions!

Are you deleting the file or trying to delete its contents? If the latter, try just deleting (unlinking) the file. Maybe you are not zeroing out the file correctly. Presence or absence of a file may be a more reliable test than the number of bytes of content.

There is also the possibility that an instance of your program terminated prematurely without cleaning up the file. When that happens, you can look at the modification time of the file and its contents to see which execution did not terminate cleanly.

There is, of course, the possibility that your program took an abnormally time to execute. How often is your program scheduled to run? Are you logging start and stop time for each execution?



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to