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


In reply to Forking Clients by gepapa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.