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
In reply to parallel functions by micmac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |