use strict; use warnings; use AnyEvent; use AnyEvent::Util; sub fork_bot { my $arg = shift; my $pid; my $cv = AnyEvent::Util::run_cmd( $arg->{bot}, '$$' => \$pid, ); my $w; $w = AE::timer( $arg->{runtime}, 0, sub { print "Killing $arg->{runtime} - timeout\n"; kill INT, $pid; $w = undef; } ); $cv } my $bot1 = fork_bot({ bot => ['./cfbot.pm', '--debug'], runtime => 60 }); my $bot2 = fork_bot({ bot => ['./cfbot_tester.pm'], runtime => 20 }); $bot1->recv; $bot2->recv; # continue with program