how to limit system() execution time?

Discussion in 'Perl Misc' started by Adrian, May 23, 2005.

  1. Adrian

    Adrian Guest

    Hi,

    I'm shelling out to a unreliable 3rd party utility that
    is supposed to spit some stuff out to STDOUT and exit.

    It always spits out the right data but sometimes it just
    doesn't exit properly and the system() call is left
    hanging there..

    is there any easy way (through threads perhaps?) of
    giving the system() call say 10 seconds to do it's thing,
    capturing the STDOUT as usual, but then killing it off if
    it hasn't exited?

    Thanks,
    Adrian.
     
    Adrian, May 23, 2005
    #1
    1. Advertising

  2. Adrian wrote:
    [...]
    > is there any easy way (through threads perhaps?) of
    > giving the system() call say 10 seconds to do it's thing,
    > capturing the STDOUT as usual, but then killing it off if
    > it hasn't exited?


    Did you check "perldoc -q timeout"?

    jue
     
    Jürgen Exner, May 23, 2005
    #2
    1. Advertising

  3. Adrian

    Damian James Guest

    On Mon, 23 May 2005 05:21:25 GMT, Jürgen Exner said:
    > Adrian wrote:
    > [...]
    >> is there any easy way (through threads perhaps?) of
    >> giving the system() call say 10 seconds to do it's thing,
    >> capturing the STDOUT as usual, but then killing it off if
    >> it hasn't exited?

    >
    > Did you check "perldoc -q timeout"?
    >


    Hmm. The first thing that occurred to me was "Do the fork()
    and exec() manually, capture the pid of the child, kill it
    in a SIGALRM handler."

    Interestingly, the FAQ your refer to itself refers to perlipc,
    which in turn talks about SIGALRM being caught in an eval block,
    and says:

    If the operation being timed out is system() or qx(), this technique is
    liable to generate zombies. If this matters to you, you'll need to
    do your own fork() and exec(), and kill the errant child process.

    Now I don't know if zombies matter to the OP, nor do I quite
    understand how he is capturing STDOUT using system rather than,
    for instance qx// or open.

    Anyhow, I'd suggest the OP look at the "Safe Pipe Opens" section
    in perlipc, look at the various examples and consider setting a
    SIGALRM handler and calling alarm(10) at the appropriate place.

    --damian
     
    Damian James, May 23, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tarun Mistry

    Limit execution of custom validator?

    Tarun Mistry, Feb 20, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    385
  2. flamesrock
    Replies:
    8
    Views:
    473
    Hendrik van Rooyen
    Nov 24, 2006
  3. Replies:
    1
    Views:
    1,087
    Victor Bazarov
    Jun 28, 2005
  4. Steven Cheng [MSFT]
    Replies:
    1
    Views:
    354
    Frederik Van Lierde
    Aug 22, 2008
  5. Replies:
    9
    Views:
    390
    Michael DOUBEZ
    Feb 5, 2009
Loading...

Share This Page