in reply to Re^5: using online translation engines with perl (ping)
in thread using online translation engines with perl
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: using online translation engines with perl (ping)
by Aldebaran (Curate) on Nov 29, 2018 at 00:50 UTC | |
by hippo (Archbishop) on Nov 29, 2018 at 10:13 UTC | |
by Aldebaran (Curate) on Nov 30, 2018 at 00:28 UTC | |
by haukex (Archbishop) on Nov 30, 2018 at 08:48 UTC |