Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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]
[1nickt]: Petroza to answer your question, no, no special permission is needed to post a question.
[LanX]: did you spam before? :)
LanX has to go/
[ambrus]: I hope we didn't mess up the spam filter rules again.
[ambrus]: Our spam filter rules disallow links to certain domains, and some suspicious pharses that have appeared in previous spam advertising cheap online whatevers.
[LanX]: some servers were lagging today, so I suppose the root cause
[LanX]: ambrus no recent patches
[Petroza]: no i haven't posted anything before. It was a more or less long question with a specific issue. I did post a title and the links i added where only part of the element i was searching within the code (so no purpose other than the question itself).
[1nickt]: Petroza can you go back in your browser to the preview screen, redact the links, and try to submit again?
[LanX]: copy and paste the text into your Petroza's scratchpad please

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2017-10-17 15:21 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (233 votes). Check out past polls.