I want to control the logging of all child processes in the file.
Code Snippet (file1.pl):
my @sitesForScr = ("abc_10","def_5","ghi_16");
foreach my $siteToRunOn (@sitesRun) {
my $jkpid;
if ($jkpid = fork()) {
$SIG{CHLD} = 'DEFAULT';
}
elsif (defined ($jkpid)) {
&linkFunc ("$siteToRunOn");
exit 0;
}
}
sub linkFunc {
print "$_[0]\n";
my @ert=split("_",$_[0]);
print "Waiting on $_[0] for $ert[1] sec\n";
sleep $ert[1];
print "Done for $_[0]\n";
}
What I want is that first, the logging of the first child process completes, then the logging of the second child process starts and when it completes, then the logging of the next child process starts, and so on.
As per the above code, output inside file (fileoutput.txt) on running "perl file1.pl >> /pan/sedrt/fileoutput.txt" is:
abc_10
Waiting on abc_10 for 10 sec
def_5
Waiting on def_5 for 5 sec
ghi_16
Waiting on ghi_16 for 16 sec
Done for def_5
Done for abc_10
Done for ghi_16
Expected Output on running command "perl file1.pl >> /pan/sedrt/fileoutput.txt":
abc_10
Waiting on abc_10 for 10 sec
Done for abc_10
def_5
Waiting on def_5 for 5 sec
Done for abc_10
ghi_16
Waiting on ghi_16 for 16 sec
Done for ghi_16
How can this be done?
Thanks!