On Dec 10, 11:31 pm, jimsgib...@gmail.com (Jim Gibson) wrote:
> 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 ifPIDfilealready 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 thefileor trying to delete its contents? If the
> latter, try just deleting (unlinking) thefile. Maybe you are not
> zeroing out thefilecorrectly. Presence or absence of afilemay 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 thefile. When that
> happens, you can look at the modification time of thefileand 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?

It is scheduled to run every 10minutes and i do not log start &
execution time as this is for no use - other than debugging.
The script doesn't have an "abnormal" time of execution. It could take
hours or just a few seconds, it totally depends on the reachablility
of pears that roam in and out and through the network cloud
autonomously...


--
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