atul sharma
atul sharma

Reputation: 1

child fork process return values

In using Parallel::ForkManager, i have few doubts. As if i am calling child process in for loop, then who will execute the next statement , parent or child. Code:

   my $pm = Parallel::ForkManager->new($forks);  foreach my $q (@numbers) {
    my $pid = $pm->start and next;
    my $res = calc($q); 
    if($res == error )
    {return};  
    if (#res == some_no)
    {do something and next;
    }
    $pm->finish(0, { result => $res, input => $q });

}....i want to know about fork return outputs and want parent process to execute 1st next and 2nd next. Also want to know if child process end in middle, will parent be able to know it and how?

Upvotes: 0

Views: 276

Answers (1)

Sobrique
Sobrique

Reputation: 53478

The two major sources of parallelism in perl are threading - use threads; and forking. For the latter, Parallel::ForkManager is probably the best bet out there.

However, for copying? This may not help nearly as much as you think. Your limiting factor isn't going to be CPU, it'll be IO to disk.

Parallelising IO doesn't help nearly as much as you think, and in many cases can be counter-productive - by making the disk thrash, having to write to two locations, you lower overall throughput.

Upvotes: 2

Related Questions