Erroring Out When Creating A Hung Process

Discussion in 'Perl Misc' started by tpurl, Oct 31, 2005.

  1. tpurl

    tpurl Guest

    There's a process that I open in a script using the following code:

    my $cmd = "myproc -l |";
    open(MYPROC, $cmd) or croak("Error $?: Couldn't execute $cmd: $!");
    my @lines = <MYPROC>;
    close(MYPROC);

    This code works pretty well *unless* the process hangs, which is does
    occasionally. If myproc hangs, then my script hangs.

    Is there a way to open a process and raise an error if it runs for more
    than, say 15 seconds?

    Thanks in advance for any help!

    Tom Purl
     
    tpurl, Oct 31, 2005
    #1
    1. Advertising

  2. tpurl

    Guest

    tpurl wrote:
    > Is there a way to open a process and raise an error if it runs for more
    > than, say 15 seconds?


    You can fork a child process and let the parent monitor it.

    perldoc -q fork
    perldoc -q background
     
    , Oct 31, 2005
    #2
    1. Advertising

  3. tpurl

    tpurl Guest

    Thanks David!
     
    tpurl, Oct 31, 2005
    #3
  4. tpurl

    Anno Siegel Guest

    <> wrote in comp.lang.perl.misc:
    > tpurl wrote:
    > > Is there a way to open a process and raise an error if it runs for more
    > > than, say 15 seconds?

    >
    > You can fork a child process and let the parent monitor it.
    >
    > perldoc -q fork
    > perldoc -q background


    He's already forking,

    open ..., "myproc -l |";

    implies a fork. Monitoring by the parent would have to be done
    concurrently with reading from the child process, otherwise the
    child may block (and appear to be running for a long time) because
    it can't deliver its output.

    The code can remain as it is, but the parent should set an alarm timer
    and a handler that kills the child process. Look in perlipc under
    signals for the non-trivial details.

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
     
    Anno Siegel, Nov 1, 2005
    #4
    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. Kenneth.Grubb

    upgraded project to VS2008 erroring in design view

    Kenneth.Grubb, Jan 7, 2008, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    741
    Kenneth.Grubb
    Jan 7, 2008
  2. Replies:
    2
    Views:
    104
  3. Philliam Auriemma

    TCPSocket.send is erroring

    Philliam Auriemma, Dec 16, 2009, in forum: Ruby
    Replies:
    1
    Views:
    101
    Roger Pack
    Dec 16, 2009
  4. Alex Rast
    Replies:
    6
    Views:
    135
    Dr John Stockton
    Feb 29, 2004
  5. Dan Stromberg
    Replies:
    0
    Views:
    139
    Dan Stromberg
    Sep 16, 2006
Loading...

Share This Page