Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Forking and running all child processes at the same time

by reneeb (Chaplain)
on Jun 06, 2005 at 12:25 UTC ( #463887=note: print w/replies, xml ) Need Help??


in reply to Forking and running all child processes at the same time

my @files = qw(file1 file2 file3); # your log-files for (1..scalar(@files)){ next unless(-e $files[$_-1]); my $pid=fork(); if($pid==-1){ warn($!); last; } if($pid){ $pids{$pid}=1; } else{ # do what you want with $files[$_-1] exit(0); } } while(keys %pids){ my $pid=waitpid( -1, WNOHANG ); die "$!" if $pid == -1; delete $pids{$pid}; }

Replies are listed 'Best First'.
Re^2: Forking and running all child processes at the same time
by tlm (Prior) on Jun 06, 2005 at 12:45 UTC

    Why the test for $pid==-1 ? From perldoc -f fork:

    returns the child pid to the parent process, 0 to the child process, or "undef" if the fork is unsuccessful.

    the lowliest monk

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://463887]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2022-12-05 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?