As you have it right now, you're stopping execution of your program while the command executes because of the backticks. You want them both to happen at the same time, and to me that suggests either threads or fork; I'd personally use fork, but that's because I know the model better.

Outlining this vaguely, I'd fork off the command, using a socketpair to communicate back to the main program. The main program could use select to simultaneously sleep a while and check for any output from the forked command. If it didn't find any after an appropriate delay, it could then kill the forked-off command and take whatever recovery actions were necessary. If it was getting output and decided to let the command continue, or the command completed, then it would simply read input from the socket while select said there was input available, and either go back to sleep, waiting for more input, or read to EOF then close the socket and waitpid on the PID returned by the fork.


In reply to Re: killing command if it takes too much time by pemungkah
in thread killing command if it takes too much time by perlassassin27

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.