LiTinOveWeedle has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use File::Cache; $address_path = "C:/Temp/address.txt"; $command = "ping.exe"; $max_processes = 2; $cache = new File::Cache( { namespace => 'ping', expires_in => 3600, filemode => 0666 } ); if ( not open(ADDRESS, $address_path) ) { die "Cannot open source file"; die; } $i = 0; while ( $temp = <ADDRESS> ) { chomp($temp); push( @address, $temp ); $i++; } $processes = 0; $i = 0; while ( $i < @address ) { if ( $processes < $max_processes ) { if ( $pid = fork() ) { $processes++; $i++; } elsif ( defined $pid ) { $command .= " $address[$i]"; @list = qx/$command/; if ( $list[10] =~ /\s(\d+)\%/ ) { $temp = $1; } $cache->set( $i, $address[$i]. ";" . $temp ); exit; } } else { wait(); $processes--; } }
As you can see it's very simple. After start script will read config file - each line is one ip address, and then it will fork to child ping to address. If there are more than max procceses running it will wait to children death and than it will continue.
Unfortunately this script don't do what I suppose. :-) have anybody idea how to get it to work? I also visit this node to get isnpired but I need litle bit more efficient way.
Thanks for help. Litin.
Li Tin O've Weedle
mad Tsort's philosopher
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Forking - max number of procceses at each time
by Zaxo (Archbishop) on Feb 27, 2002 at 19:18 UTC | |
by LiTinOveWeedle (Scribe) on Feb 27, 2002 at 23:59 UTC | |
|
Re: Forking - max number of procceses at each time
by dhable (Monk) on Feb 27, 2002 at 18:45 UTC | |
by LiTinOveWeedle (Scribe) on Feb 27, 2002 at 19:23 UTC |