Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: communication between forked processes

by JamesNC (Chaplain)
on Feb 24, 2003 at 18:56 UTC ( [id://238200]=note: print w/replies, xml ) Need Help??


in reply to communication between forked processes

Here is an example using threads and threads::shared, I am on Win32 and ActiveState 5.8.0
You could use pipe without much effort for a parent and single child communication.. but things get really messy when you try to fork off 10 or 20 processess, and have the children all communicate async with the parent or even each other, I think merlyn or one of the other "gods" has a solution for communication and even directing multi-forked processes. You should also check out Parallel::ForkManager for a very neat way to manage forked processes:
use strict; use threads; use threads::shared; my @list = qw ( www.apple.com www.ibm.com www.oracle.com www.sun.com ); my @good: shared; my @bad: shared; my $thread; my @thread; foreach(@list){ push @thread, threads->new("ping", "$_"); } foreach $thread( @thread){ $thread->join; } print "Good: @good\n"; print "Bad: @bad\n"; sub ping { my $ip = shift; my @rv = `ping -n 1 -w 100 $ip`; foreach(@rv){ if (/(\d+\.\d+\.\d+\.\d+)/){ $ip = $1 }; push @good, $ip if /\(0% loss\)/g; push @bad, $ip if /\(100% loss\)/g; } }
Cheers, JamesNC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-25 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found