buzzcutbuddha has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Net::Ping here at work, and I get the following error:
C:\Perl\eg\Scripts>perl pingythingy.pl The Unsupported function alarm function is unimplemented at C:/Perl/li +b/Net/Ping .pm line 308.
Here is the code for the program, a copy of the Camel book:
use Net::Ping; my $hostname = '10.17.1.60'; $timeout = 10; print "Printer is up\n" if pingecho($hostname, $timeout);
I cannot find any documentation stating that Alarm is not supported in the
Win32 Environment. Has anyone else encountered this problem? And what did
you do to get around it?
Thanks in advance

Replies are listed 'Best First'.
Re: Alarm Implemented in Win32?
by elwarren (Priest) on May 18, 2000 at 23:47 UTC

    I use the Net::Ping in NT everyday. I wrote a small system monitoring package that checks hosts via ping, telnet, http, and dbi. The script just runs a loop and checks different hosts with different methods, logs any failures, and pages me if it's down more than once.

    Here is the relevant ping code. This works on NT with the activestate perl and the Net::Ping package installed with the ppm tool. I had no problems with alarm. The only problem I've had with Net::Ping is that it requires root when running in unix...

    #!/usr/bin/perl @pinglist=("www.yahoo.com", "www.thisisntreal.com", "wlindsey.bbcg.com +"); use Net::Ping; sub test_ping; foreach $h (@pinglist) { if (test_ping($h)) { print "[p (ok) $h]"; } else { print "[p <NO> +$h]"; } print "\n"; } sub test_ping { # test_ping($hostname) my $hostname=shift; my $p=Net::Ping->new(icmp,5); return $p->ping($h,5); $p->close; } # end test_ping
      Elwarren, I implemeneted your code and then I looked at it and realized that I could get
      the same functionality at half the speed.

      UPDATE: errr...I should say at twice the speed...oops, typing faster than my brain
      I thought you might be interested.
      Here is the code:
      #!/usr/bin/perl @pinglist=('10.17.1.60', '10.17.1.61', '10.17.1.62', '10.17.1.63'); use Net::Ping; my $p = Net::Ping->new(icmp, 5); foreach $h (@pinglist) { if ($p->ping($h, 5)) { print "[p (ok) $h]"; } else { print "[p <NO +> $h]"; } print "\n"; } $p->close;
      And the benchmarking results:
      H:\>benchingping.pl Benchmark: timing 5000 iterations of inline, modular... inline: 63 wallclock secs (22.26 usr + 8.72 sys = 30.98 CPU) @ 16 +1.37/s (n= 5000) modular: 104 wallclock secs (38.02 usr + 23.94 sys = 61.95 CPU) @ 8 +0.71/s (n= 5000)
      Cool, huh? Thanks again!

        That's good to know. I never really went back to optimize the code, I was happy enough that I could run it on my NT machine at work. We had a server that kept crashing at different times, usually when nobody was looking :-) I threw this together to ping it every 5 minutes and it sort grew into a tool that did a few different checks. I put all the code into functions that handle creating the objects, connecting, checking the results, cleaning up and then returning a pass or fail. Each connection type has it's own special quirks hidden behind the function, so I can just as easily drop in a test_ping($hostname) as I could test_http($hostname)

        For a script that sits idle and wakes up every 5 minutes it's an acceptable slowdown ;-)

        Oh, and it ended up being a bad ups on the server...

      Hot Damn! That did it. I guess the PingEcho function still uses Alarm, but if
      you use the Ping Object Method, then it works. Good to know for future reference!
      Thanks!
Re: Alarm Implemented in Win32?
by btrott (Parson) on May 18, 2000 at 22:40 UTC
    alarm is not implemented on Win32 Perl, at least in my version of such. From perlwin32faq5:
    Here is a complete list of unimplemented functions: Functions for processes and process groups alarm() ...
      Thanks BTrott, I didn't even think to look there. I looked in the Camel Book, and here
      online, but I forgot to check my FAQ....DOH!
RE: Alarm Implemented in Win32?
by buzzcutbuddha (Chaplain) on May 18, 2000 at 23:01 UTC
    I did some more digging in the HTML Docs that come with ActiveState, and it says that
    Ping is supported in Windows. I guess I should go send them an email....