G'day amitsq,
I suspect your problems are related to the additional $pm->finish and next statements.
Your instantiation of the Parallel::ForkManager object
may also be an issue.
What you have is different from every example shown in the documentation;
also see "perlobj: Invoking Class Methods"
(including its "Indirect Object Syntax" subsection).
Using exactly the same message to identify your different cases is pointless: use meaningful messages.
I rewrote your code like this (pm_1199760_parallel_forkmgr_link_checker.pl):
#!/usr/bin/env perl -l
use strict;
use warnings;
use LWP::Simple;
use Parallel::ForkManager;
my @urls = qw{
http://us.a1.yimg.com/us.yimg.com/i/ww/m5v9.gif
http://hooboy.no-such-host.int/
http://www.yahoo.com
http://www.ora.com/ask_tim/graphics/asktim_header_main.gif
http://www.guardian.co.uk/
http://www.pixunlimited.co.uk/siteheaders/Guardian.gif
};
my $max_processes = $ARGV[0] || 8;
my $pm = Parallel::ForkManager::->new($max_processes);
print 'Start link checking.';
for my $url (@urls) {
$pm->start and next;
my ($type, undef, $mod) = head($url);
if (defined $type) {
print "PASS: $url";
print ' MOD: ', $mod || 0;
}
else {
print "FAIL: $url";
}
$pm->finish;
}
$pm->wait_all_children;
print 'Link checking completed.';
Here's the output with no argument:
$ pm_1199760_parallel_forkmgr_link_checker.pl
Start link checking.
FAIL: http://hooboy.no-such-host.int/
PASS: http://us.a1.yimg.com/us.yimg.com/i/ww/m5v9.gif
MOD: 1354074654
PASS: http://www.guardian.co.uk/
MOD: 0
FAIL: http://www.ora.com/ask_tim/graphics/asktim_header_main.gif
PASS: http://www.yahoo.com
MOD: 0
FAIL: http://www.pixunlimited.co.uk/siteheaders/Guardian.gif
Link checking completed.
I then ran it with arguments of 8, 5, 3, 2 and 1.
Lke the first run (with no argument), all ran to completion: no crashes!
With the exception of 1, they produced the same results (although the order of output varied).
Running with an argument of 1 rather defeats the purpose of running processes in parallel;
however, as you said you'd used it, I tried it also.
Here's what I got:
$ pm_1199760_parallel_forkmgr_link_checker.pl 1
Start link checking.
PASS: http://us.a1.yimg.com/us.yimg.com/i/ww/m5v9.gif
MOD: 1354074654
FAIL: http://hooboy.no-such-host.int/
PASS: http://www.yahoo.com
MOD: 0
FAIL: http://www.ora.com/ask_tim/graphics/asktim_header_main.gif
FAIL: http://www.guardian.co.uk/
FAIL: http://www.pixunlimited.co.uk/siteheaders/Guardian.gif
Link checking completed.
I ran that a second time: the result was the same.
I'll leave you to investigate that further.
-
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.