Inifinite Loop on fork


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inifinite Loop on fork
# 1  
Old 08-24-2010
Inifinite Loop on fork

I am trying to ping through a list of devices in parallel.
When the code below is executed, I enter a infinite loop.
I want to used the number of lines in the file as my boundry.

I am a perl rookie and just cant see whats wrong.
would appreciate help ...

Code:
use Net::Ping;
#
$filename = <@ARGV>;
open(CONT, $filename) or die "can't open $file: $!";
$bndry++ while <CONT>;
print $bndry;
close(CONT);
#
open(FILE, $filename) or die "can't open $file: $!";
while(<FILE>) {
 $ip = $_;
  chomp $ip;
  if (fork() == 0) {
$pingo = Net::Ping->new();
 if ($pingo->ping("$ip")) {print "Pinging $ip:\t Status:\tOk\n";}
 else {
     print ("Pinging $ip:\t Status:\tNot Ok\n");
 }
 $pingo->close();
    exit;
  }
  $children++;
 # if ($children >= $bndry) {
  if ($children >= 51) {
    wait();
    $children--;
  }
}
while ($children > 0) {
  wait();
  $children--;
}
exit 0;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Fork!

I understand that fork create a child but I need very simple example that make child useful.... I mean how will make the program faster anyone explain with code plz using C plz (2 Replies)
Discussion started by: fwrlfo
2 Replies

2. UNIX for Dummies Questions & Answers

fork()

I'm trying to run a simple test on how to use fork(), i'm able to execute the child process first then the parent, but how can I execute parent then child..? Thanks! (1 Reply)
Discussion started by: l flipboi l
1 Replies

3. Programming

C Socket Client/Server Fork Loop

Hello people. I'm trying to do something like a search engine. Server runs in the background by using ./server & which has data from a textfile stored in an array. Client then runs by using ./client It will then prompt "Search for:" For example, if I searched for Products called Instant... (0 Replies)
Discussion started by: andylbh
0 Replies

4. Programming

IPC-using fork() in a loop

I need to write a program which creates some n number of processes first and also creates a fifo for each of them, then it connects to the server and.. I tried creating these processes with fork() in a for loop but it doesn't print out what i write inside the child.. for(int count = 0; count... (7 Replies)
Discussion started by: saman_glorious
7 Replies

5. Programming

fork() help

Hi everybody, I wanna write a code to understand how fork works. my target -------------- -Parent creates a file(called temp) and writes into this file "1".Then it closes the file. -Then parent creates a child and wait until execution of this child ends. -Then child opens the same... (3 Replies)
Discussion started by: alexicopax
3 Replies

6. Programming

Fork ()

hi all About this code for (i = 1; i < n; i++) if ((childpid = fork()) <= 0) break; I really can't understand the output . and the way fork () return the value . how about the process Id ,the child process Id and the parent ID in this case so please answer me soon (5 Replies)
Discussion started by: iwbasts
5 Replies

7. Programming

fork() in for loop

hello, Every time i use fork() in the for loop, my college network(which i work in) either gets slow or hangs up.Can any 1 explain why it is so? Of course there is no use of doing it though. But still i want to clear my doubt. Thanks (2 Replies)
Discussion started by: cyno
2 Replies

8. Programming

fork() fd

I run this code, actually I want to both processes print the message from "data". But only one does. What happens? Anyone can help? #include <stdio.h> main(){ int fd, pid; char x; fd = open("data",0); /* open file "data" */ pid = fork(); if(pid != 0){ wait(0); ... (2 Replies)
Discussion started by: Herman
2 Replies

9. Shell Programming and Scripting

Endless loop - Fork function failed?

I need a quick script that will serve as a sort of "real time monitor" for watching some log files. I am using Bourne shell in HP-UX 10.20. I have basically created a script that never ends, unless of course I manually terminate it. Here's the script (it's called qhistory): clear echo "REAL... (3 Replies)
Discussion started by: cdunavent
3 Replies

10. UNIX for Dummies Questions & Answers

Fork

What is a fork? Why would one create a fork? What are the advantages and disadvantages of using a fork? Please advise. Thank You. Deepali (5 Replies)
Discussion started by: Deepali
5 Replies
Login or Register to Ask a Question
IO::Async::DetachedCode(3pm)				User Contributed Perl Documentation			      IO::Async::DetachedCode(3pm)

NAME
"IO::Async::DetachedCode" - execute code asynchronously in child processes SYNOPSIS
This object is used indirectly via the "IO::Async::Loop"'s "detach_code" method. use IO::Async::Loop; my $loop = IO::Async::Loop->new; my $code = $loop->detach_code( code => sub { my ( $number ) = @_; return is_prime( $number ); } ); $code->call( args => [ 123454321 ], on_return => sub { my $isprime = shift; print "123454321 " . ( $isprime ? "is" : "is not" ) . " a prime number "; }, on_error => sub { print STDERR "Cannot determine if it's prime - $_[0] "; }, ); $loop->run; DESCRIPTION
This object class provides a legacy compatibility layer for existing code that tries to construct such an object. It should not be used for new code; see instead the IO::Async::Function object, for which this is now a wrapper. CONSTRUCTOR
$code = $loop->detach_code( %params ) This function returns a new instance of a "IO::Async::DetachedCode" object. The %params hash takes the following keys: code => CODE A block of code to call in the child process. stream marshaller These arguments are no longer used; any values passed will be ignored. workers => INT Optional integer, specifies the number of parallel workers to create. If not supplied, 1 is used. exit_on_die => BOOL setup => ARRAY Passed through to the underlying "IO::Async::Function" object. METHODS
$code->call( %params ) Calls one invocation of the contained function code block. See the "call" method on "IO::Async::Function" for more detail. $code->shutdown This method requests that the detached worker processes stop running. $n_workers = $code->workers This method in scalar context returns the number of workers currently running. @worker_pids = $code->workers This method in list context returns a list of the PID numbers of all the currently running worker processes. AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-10-24 IO::Async::DetachedCode(3pm)