Skip to content

Instantly share code, notes, and snippets.

@hdp
Created October 14, 2010 02:56
Show Gist options
  • Save hdp/625457 to your computer and use it in GitHub Desktop.
Save hdp/625457 to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
use Reflex::POE::Wheel::Run;
my $log = IO::File->new('log', 'w') or die $!;
my %w;
for my $id (1..20) {
$w{$id} = Reflex::POE::Wheel::Run->new(
Program => q{for x in 1 2 3 4 5; do tr -dc A-Za-z0-9 < /dev/urandom | head -c 32; echo $x; sleep 1; done},
on_stdout => sub {
my $args = pop;
my $pid = $args->{_sender}->wheel->PID;
my $timestamp = localtime;
$log->print("[$timestamp] ($pid): $args->{output}\n");
},
on_signal => sub {
my $args = pop;
print "child $args->{pid} exited: $args->{exit}\n";
delete $w{$id};
},
);
}
Reflex->run_all;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment