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

Re: 20010821: Gempak, Perl, and Gemplt errors



Hi there Steve,

Ok last time I hope.

I was thinking about how the PID's were handed out and watched the processes some.  I realized that most of the time the PID's were generally higher for those created later and lower for those created earlier.  But this was not always the case.  I saw instances where a new process had a lower PID than an older one.  If I understand the logic of my initial scripts sent to you, this would fool the script into allowing more than one gempak instance to run.  For this to happen, the older PID would have to pass the "while" statement and let the gempak program run.  While that gempak system call is processing, the newer request is made with a lower number PID.  It, seeing itself at the top of the list, happily starts running a second instance of a gempak program.  Even with this hole, I have found the scripts run from the cron are much more stable.  Still, I felt that I should make it stronger.  The modification I added to the process lock script checks for the lock file modification time and sorts on that so that the processes are only allowed to run in the order of lock file creation, not by the order that the PID's happen to be handed out in.  Using the PID is still useful in maintaining uniqueness of each process.  Does that make any sense?  =)

Anyway here is hopefully the last version of my perl scriptlette:

#[previous stuff]

#create process lock
$count = 0;
$lockdir = "/home/hokukea/rknabb/gempak/gemlock/tutt19";
$pid = $$;
$gemlock=".inuse.$pid";
$PROCLOCK=">$lockdir/$gemlock";
open(PROCLOCK);
close(PROCLOCK);
opendir DIRECTORY, $lockdir;
@filelist = grep { /^\.inuse/ && -f "$lockdir/$_" } readdir DIRECTORY;
closedir DIRECTORY;
$count2=0;
foreach $file(@filelist) {
  $filedate[$count2] = (stat($file))[9].$file;
  $count2++;
}
@filedate = sort(@filedate);
while ( substr($filedate[0],10) ne $gemlock && $count < 61 ) {
  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($file))[9].$file;
    $count2++;
  }
  @filedate = sort(@filedate);
  $count++;
}

#gempak program goes here!

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

#[later stuff]

Thanks again Seve and happy new year!
Sean