gepapa has asked for the wisdom of the Perl Monks concerning the following question:

So I have what I believe is a different question than the norm.

I have a server which has a distinct listener running on multiple ports. What I want to do is be able to make calls to these distinct listeners whenever I want, including simultaneously. So I don't want to necessarily wait on each pid, because I want to be able to do other stuff including making connections to other open listeners. Each call will make the server do something, and I need to get the output back from whatever it is doing.

Here is some sample code I put together to give you a basic idea of what I need to do:

use strict; use Carp; use ClarRPC; #In house module my ($pid1, @resp1) = rpc(, '1300', 'ping -n 15 +8'); my ($pid2, @resp2) = rpc(, '1301', 'ping -n 15 +8'); my ($pid3, @resp3) = rpc(, '1302', 'ping -n 15 +8'); print ("RESP1: @resp1\n"); print ("RESP2: @resp2\n"); print ("RESP3: @resp3\n"); sub rpc { my ($ip, $port, $command) = @_; my @resp; my $pid; my @pids; if ($pid = fork()) { push(@pids, $pid); #waitpid($pid, 0); } elsif (defined $pid) { my $connection = ClarRPC->connect($ip, $port); ($pid, @resp) = $connection->rpc('ClarRPCService::system_call' +, $command); $connection->disconnect(); exit; } return $pid, @resp; }

What I need is the information from @resp. I don't care if it is out of order, and I know the print statements I have won't work. I know I need to wait for a particular pid to complete before having data, but what I need is to be able to wait for that pid without blocking the possibility of the other pid's completing before it. So essentially I need the ability to just get the info from whatever call is complete, at any time.

Any help would be greatly appreciated Thanks