[ale] attaching an array to a hash

Christopher Fowler cfowler at outpostsentinel.com
Fri Dec 31 10:30:05 EST 2004


Here is how I did it.

  $pids{$pid}{'name'} = $name;
  $pids{$pid}{'pid'} = $pid;
  $pids{$pid}{'cmd'}  = $cmd;
  $pids{$pid}{'args'} = "@args";

Child handler:
    if($CHILD == 1) {
      my $child_pid = wait;
      my $status = $?;
      foreach my $ref (sort keys %pids) {
        if($child_pid == $ref) {
          print "Process $pids{$ref}{'name'} exited!\n";
          print "  CMD: $pids{$ref}{'cmd'} $pids{$ref}{'args'}\n";
          print "  Restarting $pids{$ref}{'cmd'}\n";
          my @args = split(/\s/, $pids{$ref}{'args'});
          start_program "/opt/SAM/logs/$pids{$ref}{'name'}.log",
            "$pids{$ref}{'name'}", "$pids{$ref}{'cmd'}", @args;
        }
      }
      $CHILD = 0;
    }

I simply use split to rebuild an array then execute the start_program
function with the correct arguments;



On Fri, 2004-12-31 at 09:28, Christopher Fowler wrote:
> What is the best way to attach an array to a hash.  I know I've asked
> this question before but I just can not remember how to do it.  
> 
> Here is sample:
> 
>   $pids{$pid}{'name'} = $name;
>   $pids{$pid}{'pid'} = $pid;
>   $pids{$pid}{'cmd'}  = $cmd;
>   $pids{$pid}{'args'} = @args;
> 
> This is part of an init.d program that stays running to make sure that
> some programs never terminate.  If they do it will be responsible for
> logging an error and then restarting that proggie.  It will keep Java
> RMI program running.
> 
> Child Handler:
> 
>     if($CHILD == 1) {
>       my $child_pid = wait;
>       my $status = $?;
>       foreach my $ref (sort keys %pids) {
>         if($child_pid == $ref) {
>           print "Process $pids{$ref}{'name'} exited!\n";
>           print "  CMD: $pids{$ref}{'cmd'} $pids{$ref}{'args'}\n";
>         }
>       }
>       $CHILD = 0;
>     }
> 
> 
> 
> Thanks,
> Chris
> 
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list