in reply to Forking two processes in parallel

Your fork_bot doesn't return until it has slept.

You need to fork both off, and manage the sleep events in the parent. And the parent has to wait around for the children to finish, else the parent exiting may also terminate its children.

Personally, I've found that using an event manager simplifies this greatly. Completely untested code:

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
Now, I'm sure you can do this equally as well with other event handlers, or with threads. This is just what I'm used to.

Coro can simplify this a bit further, but at this point it's not enough to warrant, IMO. (It would invert the timeout into a Coro-version of sleep, but I don't think that's a huge benefit here.)

Also, we can use this to also clean up the $w watcher, to eliminate that timer if the child exits before the timer runs out.

Hope that helps.