Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Erroring Out When Creating A Hung Process

Reply
Thread Tools

Erroring Out When Creating A Hung Process

 
 
tpurl
Guest
Posts: n/a
 
      10-31-2005
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

 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      10-31-2005
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

 
Reply With Quote
 
 
 
 
tpurl
Guest
Posts: n/a
 
      10-31-2005
Thanks David!

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      11-01-2005
<(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TCPSocket.send is erroring Philliam Auriemma Ruby 1 12-16-2009 11:57 PM
upgraded project to VS2008 erroring in design view Kenneth.Grubb ASP .Net Building Controls 0 01-07-2008 06:44 PM
Building a perl C extension module erroring out on Ubuntu 5.10 Dan Stromberg Perl Misc 0 09-15-2006 11:02 PM
Detecting a hung/stalled child process junk5@microserf.org.uk Ruby 2 09-04-2005 03:11 PM
Service Pack 4 Erroring RAS / VPN Lorie Computer Support 1 04-29-2005 03:29 AM



Advertisments