Created
November 10, 2016 07:58
-
-
Save qgp9/9933da50f46ca4806ab5a63dd6a3ab38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.18; | |
use Time::HiRes 'time'; | |
use Parallel::ForkManager; | |
my $pm = new Parallel::ForkManager(4); | |
my @links = 1..60; | |
my $btime = time; | |
foreach my $link (@links) { | |
$pm->start and next; # do the fork | |
say ((time-$btime),"\t",$link); | |
$pm->finish; # do the exit in the child process | |
} | |
$pm->wait_all_children; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.18; | |
use Time::HiRes 'time'; | |
my @links = 1..60; | |
my $btime = time; | |
my $nfork = 0; | |
foreach my $link (@links) { | |
my $pid = fork(); | |
die if not defined $pid; | |
if ( $pid ){ | |
$nfork++; | |
if ($nfork > 4){ | |
wait; | |
$nfork--; | |
} | |
}else{ | |
sleep 2; | |
say ((time-$btime),"\t",$link); | |
exit; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment