Need to capture Log of each thread --Parallel::ForkManager;


D

divyajacob

Hi All,
In one of my application,i am cloning a process to 4 different
threads,using Parallel::ForkManager module.
Can anyone tell me how can i track each thread ,and is it possible to
create separate log files for each thread.

My Program is something like this....

my $child_proc_mgr=new Parallel::ForkManager($maxprocesses);
for(my $i = $from; $i <=$to; $i++)
{ my $sourcefname=$tmpfname;
my $targetfname=$targetdir;
$sourcefname .= "/".sprintf('%03s',$i);
$targetfname .= "/".sprintf('%03s',$i).".gz";
next if (-e "$targetfname");
next if (-e "$sourcefname.sorting");
next if (-e "$sourcefname.sorted");
$child_proc_mgr->start and next;
my ($src,$sorting,$sorted);
die "\nFile $sourcefname does not exists" if (! -e
"$sourcefname");
open ($src,"< $sourcefname") || die "\nCannot open
$sourcefname for reading $!";
open ($sorting,"> $sourcefname.sorting") ||
die "\nCannot open temp file $sourcefname.sorting for
writing $!";
close $src;
close $sorting;
print "\nSorting file $sourcefname";
sort_file("$sourcefname.sorting","$sourcefname.sorted");
my $sortstatus= $? >> 8;
if ($sortstatus != 0)
{ unlink $targetfname;
die "\n $sourcefname.sorting -- Sort was failed $!";
}
else
{
print "Sorting successful for file
$sourcefname.sorting to $sourcefname.sorted";
}
$child_proc_mgr->finish;
}
$child_proc_mgr->wait_all_children;


Right now proper logging is not happening,many of the print statements
i have given are not getting captured for each thred.
Any pointers to this will be highly appreciated.

Thanks,
Divya
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top