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(10.15.51.208, '1300', 'ping -n 15 10.15.51.20 +8'); my ($pid2, @resp2) = rpc(10.15.51.208, '1301', 'ping -n 15 10.15.51.20 +8'); my ($pid3, @resp3) = rpc(10.15.51.208, '1302', 'ping -n 15 10.15.51.20 +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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Forking Clients
by BrowserUk (Patriarch) on Oct 15, 2008 at 16:19 UTC | |
by gepapa (Acolyte) on Oct 15, 2008 at 17:27 UTC | |
by BrowserUk (Patriarch) on Oct 15, 2008 at 17:32 UTC | |
by gepapa (Acolyte) on Oct 15, 2008 at 17:55 UTC | |
by BrowserUk (Patriarch) on Oct 15, 2008 at 18:31 UTC | |
| |
Re: Forking Clients
by Fletch (Bishop) on Oct 15, 2008 at 15:43 UTC | |
by suaveant (Parson) on Oct 15, 2008 at 16:29 UTC | |
by gepapa (Acolyte) on Oct 15, 2008 at 16:49 UTC | |
Re: Forking Clients
by mr_mischief (Monsignor) on Oct 15, 2008 at 15:38 UTC | |
Re: Forking Clients
by JavaFan (Canon) on Oct 15, 2008 at 16:11 UTC | |
Re: Forking Clients
by AnomalousMonk (Archbishop) on Oct 15, 2008 at 23:09 UTC | |
by AnomalousMonk (Archbishop) on Oct 17, 2008 at 04:25 UTC | |
by gepapa (Acolyte) on Oct 17, 2008 at 14:27 UTC | |
by gepapa (Acolyte) on Oct 16, 2008 at 12:34 UTC |