micmac has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I'm trying to run two functions in parallel thusly:
Output:#!/usr/bin/perl use 5.014; my @child_pids; for my $cmd (\&test1, \&test2) { defined(my $child_pid = fork()) or die "Couldn't fork: $!"; if ($child_pid == 0) { exec $cmd->(); } else { push @child_pids, $child_pid; } } for my $pid (@child_pids) { waitpid($pid, 0); } sub test1 { sleep 3; say "in test1"; } sub test2 { sleep 2; say "in test2"; }
Say what? Why is it running test2 twice?in test2 in test1 in test2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parallel functions
by kcott (Archbishop) on Nov 07, 2012 at 21:58 UTC | |
by micmac (Acolyte) on Nov 07, 2012 at 22:11 UTC | |
|
Re: parallel functions
by tobyink (Canon) on Nov 07, 2012 at 21:40 UTC | |
|
Re: parallel functions
by chromatic (Archbishop) on Nov 07, 2012 at 21:41 UTC | |
|
Re: parallel functions
by marioroy (Prior) on Nov 25, 2012 at 06:26 UTC | |
|
Re: parallel functions
by Anonymous Monk on Nov 07, 2012 at 21:53 UTC |