If you mean simply putting a timeout on the read, then you can do it like this using the standard method for timeouts (alarm, $sig{ALRM}, die). I didn't actually test it, though.
my @pslist = (); while (!@pslist) { local $SIG{ALRM} = { die "TIMEOUT" }; my $pid; eval { alarm 5; # arrange for a wake-up call in 5 seconds $pid = open(PSLIST, " ssh -2 $user\@ $peer ./pslist | ") || die "Remote process list gathering error:\n$!.\n"; while(<PSLIST>){ chomp($_); push(@pslist, $_); } close(PSLIST); alarm 0; # clear the alarm, if we got this far ok } if ($@ =~ /TIMEOUT/) { # abort the attempt, and try again kill 'TERM' => $pid; @pslist = (); } elsif ($@) { die $@; } } foreach (@service){ # .. check the existence of a process }

There is also at least one module on cpan for doing timeouts... but it's the sort of thing that is simple enough that you usually just wanna do it inline, rather than bringing in a module for it.


------------
:Wq
Not an editor command: Wq

In reply to Re: Read a process output asynchronously by etcshadow
in thread Read a process output asynchronously by redbrick

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.