Since I can't really rely on a fix time run time basis, this doesn't make too much sense either, Instead of that i thought i'd rather execute a littler bash script from the crontab that's like:
#!/bin/bash if [ -e /var/run/myPIDfile ] then echo "script still running"; else execute my perl script fi exit 0 How would that be? But then again, i don't see the difference to the snippet in my perl script... :o One step further would be to check the process list with "ps ax | grep 'HOWEVER/THE/CALL/FROM/CRON/LOOKS'| wc -l" and verify that only one line is being returned (from the actual call)... - any suggestions/ comments? Thanks, Ron 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? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/