CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Threading Script does not terminate

 



puladancer
New User

May 29, 2009, 10:42 AM

Post #1 of 3 (369 views)
Threading Script does not terminate Can't Post

I am trying to write a program that will ping a list of hosts (could be up to 3000 hosts). Rather than synchronously ping each host and process each ping, I want to thread off the pings so the script excecutes a lot faster.

I have written a test script to get me started with any database functionality to be added later. The script does not always terminate, i.e. return to the command prompt. I have to press enter.

If the hosts are all off the script terminates. However, if at least one host is on the script needs and enter to finish. Also, if all ping threads have the same host name only one 'Reply from ...' output appears not 3. It's been a while since I worked with Perl and something is telling me I am making a basic error.

Would appreciate any help.

use Thread;

$thr = new Thread \&sub1, "host1";
$thr = new Thread \&sub1, "host2";
$thr = new Thread \&sub1, "host3";


sub sub1
{
print "In the thread\n";

my @InboundParameter = @_;

$command = 'ping ' . $InboundParameter[0] . ' -n 1 | find /i "TTL="';

$result = open(PING, "| $command");

printf(PING);


}


Output no hosts are on:


>C:\Perl>perl test5.pl
>In the thread

>C:\Perl>


Output if one host on:


>C:\Perl>perl test5.pl
>In the thread

>C:\Perl>Reply from 192.168.1.70: bytes=32 time<1ms TTL=128

and I have to press enter to get to the cmd prompt.

Output if ping threads are for the same host three times:


>C:\Perl>perl test5.pl
>In the thread

>C:\Perl>Reply from 192.168.1.70: bytes=32 time<1ms TTL=128

and I have to press enter to get to the cmd prompt.


(This post was edited by puladancer on May 29, 2009, 10:44 AM)


FishMonger
Veteran / Moderator

May 29, 2009, 11:19 AM

Post #2 of 3 (364 views)
Re: [puladancer] Threading Script does not terminate [In reply to] Can't Post

Don't go to the shell and execute a piped command.

Use one of Perl's ping modules.

http://search.cpan.org/search?query=net%3A%3Aping&mode=all


puladancer
New User

May 29, 2009, 5:13 PM

Post #3 of 3 (356 views)
Re: [FishMonger] Threading Script does not terminate [In reply to] Can't Post

Thanks Fishmonger for the quick reply. I have not tried out your advice in a threading context but I have at least seen the quicker response from Perl ping module versus shell/exec/system ping in a synchronous context

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives