[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 20020110: 20010821: Gempak, Perl, and Gemplt errors



Hey there (yet again) Steve,

This time, for sure is the last time.  There were two bugs that delayed my recognizing that something was wrong because they worked together to make it look like everything was good.  Anyway, I've fixed it and it now seems to run really well.

##################################################################
#[previous stuff]

#should only have to configure the location of the lock directory
#but you should make sure this doesn't overwrite any of your own
#variables.
$lockdir = "/home/hokukea/rknabb/gempak/gemlock/tutt19";

#create process lock file
$count = 0;
$pid = $$;
$gemlock=".inuse.$pid";
$PROCLOCK=">$lockdir/$gemlock";
open(PROCLOCK);
close(PROCLOCK);

#test if I am oldest lock file.
opendir DIRECTORY, $lockdir;
@filelist = grep { /^\.inuse/ && -f "$lockdir/$_" } readdir DIRECTORY;
closedir DIRECTORY;
$count2=0;
foreach $file(@filelist) {
  $filedate[$count2] = (stat("$lockdir/$file"))[9].$file;
  $count2++;
}
@filedate = sort(@filedate);
while ( substr($filedate[0],10) ne $gemlock ) {
  sleep 1;
  if ( $count > 60 ) { unlink("$lockdir/$gemlock") ; die; }
  @filelist = 0 ; @filedate = 0;
  opendir DIRECTORY, $lockdir;
  @filelist = grep { /^\.inuse/ && -f"$lockdir/$_"} readdir DIRECTORY;
  closedir DIRECTORY;
  $count2 = 0;
  foreach $file(@filelist) {
    $filedate[$count2] = (stat("$lockdir/$file"))[9].$file;
    $count2++;
  }
  @filedate = sort(@filedate);
  $count++;
}

#gempak system call goes here!
#

#clear process lock file
unlink("$lockdir/$gemlock");

#[later stuff]
####################################################################

I guess I am sending this script segement to you because I think there are a lot of perl users out there.  Perl really works great for gempak scripting and is easier than csh.  The issue of gplt and gpends clobbering each other as they attempt to use the same x frame was a big problem for me.  The 5.6 update of Gempak really improved the situation but didn't solve it.  Of course, you didn't ever claim that it was supposed to.  The person who created the scripts for our web page completely ignored this fact about Gempak.  There are times on a system where as many as 8 or 9 perl scripts are running, each calling gempak programs.  I don't know how he ever got consistent output to reach the webpage.  I figure there is a good chance you will get future questions about this problem.  I think this is a perfect solution which of course is nothing more than the perlized form of your csh lock script.  The other big benefit is that you can run the scripts out of cron because the processes forked by a cron-run csh script have unique PID's.  If you already had a perl version of this lock script than I guess....disregard all of this.  =)

There is a chance that this is faster than the csh version.  Though this perl script segment is longer and needs to do more than the csh scirpt, perl is runtime compiled.

I should have let the code stew for a week before sending it off to you.  =)

Cheers,
Sean Daida
MKWC
University of Hawaii
address@hidden