It's not clear to me why you are using fork here but that certainly seems to be the root of your troubles. The doc for alarm says:

If you want to use "alarm" to time out a system call you need to use an "eval"/"die" pair.

... but you haven't done that in 6.fork.pl and therefore the ping processes are not reaped which is presumably why you see high icmp_seq counts on subsequent runs. Why use alarm at all instead of ping's built-in timeout?

Here are 2 examples with neither fork nor alarm. First, using system to execute the ping command:

#!/usr/bin/env perl use strict; use warnings; for my $dest ('www.google.com', 'www.perlmonks.org', 'microsoft.com', +'foo.bar') { system ("ping -nqc1 -w 3 -W 3 $dest > /tmp/ping.log") and print "### $dest is unreachable\n"; }

and now the same with Net::Ping:

#!/usr/bin/env perl use strict; use warnings; use Net::Ping; my $pinger = Net::Ping->new ('icmp', 3); for my $dest ('www.google.com', 'www.perlmonks.org', 'microsoft.com', +'foo.bar') { $pinger->ping ($dest) or print "### $dest is unreachable\n"; } $pinger->close;

Note that in both cases, microsoft.com is unreachable because it doesn't respond to pings and foo.bar is unreachable because it doesn't exist. The magic number 3 is the timeout to enforce in each case. As per the documentation the second script must be run as root to use ICMP pings.


In reply to Re^6: using online translation engines with perl (ping) by hippo
in thread using online translation engines with perl by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.