Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Help with multiple forks

by Neighbour (Friar)
on May 31, 2012 at 08:46 UTC ( #973466=note: print w/replies, xml ) Need Help??

in reply to Help with multiple forks

Looking at your pseudocode, perhaps Forks::Super is something you could use here:
sub OnTaskEnd { my ($forksuperjob, $jobid) = @_; if (ref($forksuperjob) ne 'Forks::Super::Job') { die("OnTaskEnd called with argument of type [" . ref($forksupe +rjob) . "] instead of expected Forks::Super::Job"); } print("TaskEnd: JobID [$jobid] Job pid [" . $forksuperjob->{real_p +id} . "] starttime [" . int($forksuperjob->{start}) . "] name [" . $f +orksuperjob->{name} . "] status [" . $forksuperjob->{status} . "]\n") +; # Do other stuff here, like starting new jobs to process files $forksuperjob->dispose; } foreach my $val1 (@array1) { my $forkresult = Forks::Super::fork { dir => 'dir_here', cmd => '', name => 'unique_name_of_task', callback => { start => \&OnTaskStart, finish => \&OnTaskEnd }, }; } print("Waiting for child jobs to finish\n"); my $jobs_waited = waitall(); print("[$jobs_waited] jobs were scheduled/running and have now finishe +d\n");
Alternatively, instead of executing external programs with the cmd-option, you could use sub to fork subroutines instead.

Replies are listed 'Best First'.
Re^2: Help with multiple forks
by Anonymous Monk on May 31, 2012 at 14:21 UTC

    Thanks. I hadn't noticed the package in CPAN because it's not common to find the package you want so far down the list. However in this case I don't need to limit the number of processes, so I will forgo both Parallel::ForkManager and Forks::Super

    So in the end, I am opting for plain standard fork as in the 1st example from kennethk, but, as suggested by mbethke with the inner loop and fork moved to the child of the outer fork (which is what happens in Eliya's example, I think)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973466]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2018-05-21 01:32 GMT
Find Nodes?
    Voting Booth?