Hi,

    I was wondering if someone can shed some light on a problem I am
having.  I have a sub routine that forks each variable in an array one
at a time.  But after the last element in the array the program exists
from the sub routine, it does not  continue after the the last element
in the array is done forking.

<code>

sub tarusers {

foreach my $user (@home) {
      #creating fork for each user to free memory when the child dies.
      my $pid;      
      unless ($pid = fork) {
            while (fork) {
                  # in here I have code that tar users on a remote box
and gzips them on l;ocal machine.  Plus logs everything to a mysql
db.                  
                  exit 0;
                  }  
                  exit 0;
            }
            waitpid($pid,0);
      }      
      # start tarring home2 users.
      if (@home2) {
            foreach my $user2 (@home2) {
                  my $pid;      
                  unless ($pid = fork) {
                        while (fork) {
                              # here I have code that tars users on a
remote box and gzip locally.  The @home2 may or may not exists         
                              exit 0;
                        } 
                        exit 0;
                  } 
                  waitpid($pid,0);
            }
      }
}      

</code>

   The problem is when it exits the sub routine before the if(@home2). 
I am not to sure how to change the code to continue.  I know the @home2
exists because I can print it out.  I am just having a hell of a time
with forking and returning to the parent.

    Can anyone offer any suggestions?

thanks,
--chad


Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to