[boulder.pm] while{while{ ?

Robert L. Harris Robert.L.Harris at rdlg.net
Thu Mar 22 13:39:44 CST 2001



I'm playing with forks and pipe() now.  Here's a scenario:

  I have a parent that will get the names of some files to process.  
I will spawn children to do the processing and could have up to 4 children
running at a time, with a number in the queue waiting, depending how fast
the parent can prepare the files.  Here's the rough structure:



pipe(READER, WRITER) || die "$!";

(%Names)=&GetFileNames;
my ($MaxProcess)="3";
my ($Processed)="0";
my ($PreProcessed)="0";
my ($Reading)="F";
my ($Keepgoing)="T";
while ($KeepGoing eq "T") {
  if (($Reading eq "F") && ($@Number >= $Pre-Processed)) {
    #
    # Make this fork a sub so we can do the processing as they're ready.
    #
    #$ReadyToProcess[$#ReadyToProcess]=&PrepareFile($Names{$Processed});
    #
    $Reading="T";
    $Pre-Processed++;
  }

  if ($#ReadyToProcess > 0) {
    $pid = fork {}
    if ($pid == 0) {
      close(READER);
      &DoProcess ($ReadyToProcess[0]);
      print WRITER "Done processing $ReadyToProcess[0].  Child Exiting.\n";
      exit 0;
    } elsif ($pid > 0) {
      close(WRITER);

      *****************************************

      $Processed++ if (Child exits based on content of $Reader)...
  
      *****************************************
  
  }
  sleep 5;
}

(Debug, error catching, etc trimmed for readability)

Now here's the delima.  I need to have the parent read the filehandle 
reader, but not block, waiting on EOF so it can spawn more pre-process
and processing files, but still read off of READER when data is there?
Something like have the parrent check each itteration for data in the
buffer, if there is some, do the processing, if not, continue on the
loop.


:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'




More information about the Boulder-pm mailing list