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

Discussion in 'Perl Misc' started by divyajacob, Jun 30, 2010.

  1. divyajacob

    divyajacob Guest

    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
    divyajacob, Jun 30, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nvp
    Replies:
    0
    Views:
    104
  2. nvp
    Replies:
    2
    Views:
    166
    Luc Heinrich
    Dec 31, 2009
  3. Replies:
    0
    Views:
    219
  4. it_says_BALLS_on_your forehead

    Parallel::ForkManager and Net::FTP problem?

    it_says_BALLS_on_your forehead, Oct 7, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    433
    it_says_BALLS_on_your forehead
    Oct 10, 2005
  5. chaitu
    Replies:
    2
    Views:
    144
    chaitu
    Sep 21, 2006
Loading...

Share This Page