neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
Greetings,
I'm trying to write a test program for an irc bot. My plan is to create a second bot, have the two bots talk to each other, and then check the results. So, I wrote some test code to start each bot and run them toether for a brief amount of time. It seems that rather than running in parallel the bots run in sequence. What have a done wrong or is there a better way?
#!/usr/bin/env perl use strict; use warnings; use Carp; fork_bot({ bot => './cfbot.pm --debug', runtime => 60 }); fork_bot({ bot => './cfbot_tester.pm', runtime => 20 }); sub fork_bot { my ( $arg ) = @_; my $pid = fork(); if ( $pid == 0 ){ exec( $arg->{bot} ) or croak "Cannot start [$arg->{bot}] [$!]"; } else{ sleep $arg->{runtime}; kill 1, $pid or croak "Cannot kill pid [$pid]"; } return; }
Neil Watson
watson-wilson.ca
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Forking two processes in parallel
by Tanktalus (Canon) on Mar 06, 2016 at 02:25 UTC | |
|
Re: Forking two processes in parallel
by andal (Hermit) on Mar 07, 2016 at 08:16 UTC |