Hi,

We need to run test in multiple test cycles and in each test cycle
multiple operations need to be performed. Currently one test cycle is
taking 10 seconds and we need to reduce the time to 4 seconds. I have
used fork() to do this as follows (only one operation is given here).
I will update the global associative array (%upTime) in each of the
operation to capture the result. Finally i will traverse through the
array and print the test result.

Issue here is: The global associative array is not getting updated in
the child process. Please suggest me how to do this.
Note that I can make use of file & file handler and push the values to
the file handler. It will work. But the problem is that the result
will not be in a sequential order (1-to-6) in the file.

Below is the sample code:

#!/usr/bin/perl -w
use strict;
use warnings;

use Net::Telnet;
use NTTools;

sub getUpTimeOfBlade ($$);

my %ipAddress = ( 1  => '10.100.19.120',
                  3  => '10.100.19.146',
                  4  => '10.100.19.145',
                  5  => '10.100.19.248',
                  6  => '10.100.19.250',
                );

my %pid;
my %upTime;

foreach my $slot ( keys %ipAddress )
{
    $pid{$slot} = fork();
    if ( $pid{$slot} == 0 )
    {
        print "Child process for slot $slot: $pid{$slot}\n";
        my $tn = new Net::Telnet();
        NTOpenRoot( $tn, $ipAddress{$slot} );
        $upTime{$slot} = getUpTimeOfBlade ( $tn, $slot );  ## <<< It
has to update the globle associative array %uptime
        exit(0);
    }
}

# Wait for the child processess to complete
foreach ( keys %pid )
{
    waitpid( $pid{$_}, 0 );
}

# print the values of associative array
foreach ( keys %upTime )
{
    print "## $_:$upTime{$_}\n";   ## <<< No value here
}

sub getUpTimeOfBlade ($$)
{

    # parameters: telnetSession
    my $telnetSession = shift;
    my $s = shift;

    # Read uptime
    my @lines = $telnetSession->cmd("cat /proc/uptime");
    foreach my $line (@lines)
    {
        next if ( $line !~ /([0-9.]+) [0-9.]+/ );
        $line =~ /([0-9.]+) [0-9.]+/;
        print "Uptime of blade of slot $s is:$1\n";
        return $1;
    }
    return undef;
}

Please suggest.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to