Skip to content

Instantly share code, notes, and snippets.

@leobalter

leobalter/a.pm Secret

Last active June 11, 2018 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leobalter/779cbaa8a4da1e7a0148c475ab822d65 to your computer and use it in GitHub Desktop.
Save leobalter/779cbaa8a4da1e7a0148c475ab822d65 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use 5.8.8;
use IO::Handle;
use FindBin;
use Config;
my $Bin;
BEGIN {
$ENV{DBIC_OVERWRITE_HELPER_METHODS_OK} = 1;
unshift @INC, "$FindBin::Bin";
unshift @INC, "$FindBin::Bin/lib";
unshift @INC, "$FindBin::Bin/local/lib/perl5";
unshift @INC, "$FindBin::Bin/local/lib/perl5/$Config{archname}";
$ENV{LOAD_ROUTES} = 1;
}
use Parallel::ForkManager;
use Socket;
use DDP;
my $processes = 4;
my $pm = Parallel::ForkManager->new($processes);
my @files = ('a'..'z');
# Almost there, but hell don't ever execute this
socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
sub getFile {
my $file = shift @files;
if ($file) {
return $file . "\n";
}
}
while (my $file = getFile()) {
print $wtr $file;
}
# Open each process
FILES:
for (my $i = 0; $i < $processes; $i++) {
my $pid = $pm->start() and next FILES;
while (chomp(my $line = <$rdr>)) {
sleep(.1);
print "$i: $line\n";
}
$pm->finish;
}
$pm->wait_all_children;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment