Three - is there a better way to go about doing this?
Yes. You are duplicating the functonality of Parallel::ForkManager. All you need is the following:
use strict;
use warnings;
use Parallel::ForkManager ();
use constant $MAX_PROCESSES => 3;
{
my $pm = Parallel::ForkManager->new($MAX_PROCESSES);
foreach my $fw (qw(fw1 fw2 fw3 fw4 fw5)) {
my $pid = $pm->start and next;
exec "remotelogfile $fw logfile > /var/$fw.log"
or die("Unable to launch \"remotelogfile $fw\": $!\n");
# Will never reach this, but that's ok since it only calls exit.
$pm->finish; # Terminates the child process
}
}
or just
use Parallel::ForkManager ();
my $pm = Parallel::ForkManager->new(3);
foreach my $fw (qw(fw1 fw2 fw3 fw4 fw5)) {
$pm->start and next;
exec "remotelogfile $fw logfile > /var/$fw.log";
die("Unable to launch \"remotelogfile $fw\": $!\n");
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|