Hi List
The below mentioned code will run at the same time ( symaltaneously)  from 2
or more  separate locations  and it will write its execution(absolute path)
path and its PID.
But when ever I am trying to run this code only one program's information is
written to the common file and other program's information is not being
written.I have tried a lot to rectify this problem but not able to
understand why this is happening.Also tell me where I am making the mistake.

Please help me to solve this problem


my ( $scriptname, $home ) = File::Basename::fileparse( realpath($0) );

my $progname_abs_path = "$home$scriptname";

my $clusterservice_info =
"/home/merge/testcode/cluster/sharedbox/cluster_service_status.txt";

if ( ! -s $clusterservice_info ) {

open my $WFH, '>', $clusterservice_info

or die "Cant'open $clusterservice_info $! \n" ;

flock( $WFH,2);

print $WFH "$progname_abs_path:-:$$\n";

close($WFH);

}

else {

open my $WFH1, '+<', $clusterservice_info

or die "Cant'open $clusterservice_info $! \n";

flock( $WFH1,2);

while (my $line = <$WFH1>) {

chomp $line;

next if $line =~ /^$/;

my($firstval,$secondval) = $line =~ /^(.*?):-:(.*?)$/;

print "firstval = $firstval \n";

if ($firstval ne /^$progname_abs_path$/) {

seek($WFH1, 0, 2);

print $WFH1 "$progname_abs_path:-:$$\n";

}

}

close($WFH1);

}



Thanks & Regards

Anirban Adhikary

Reply via email to