Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Using IPC::Run to kill stuck process

by zentara (Archbishop)
on Dec 13, 2013 at 16:15 UTC ( #1067036=note: print w/ replies, xml ) Need Help??


in reply to Using IPC::Run to kill stuck process

How about something like this piece of standard timeout code:

#!/usr/bin/perl use warnings; use strict; my $script = 'ps auxww'; eval { # from http://www.rocketaware.com/perl/perlfunc/alarm.htm local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required alarm(5); # set time limit to 5 sec system($script); alarm(0); # if $script finishes in <5sec reset alarm }; die if $@ && $@ ne "alarm\n"; # propagate errors if ($@) { print "Timeout! [$@]\n"; # do stuff if eval fails (eg timeout) }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh


Comment on Re: Using IPC::Run to kill stuck process
Download Code
Replies are listed 'Best First'.
Re^2: Using IPC::Run to kill stuck process
by runrig (Abbot) on Dec 13, 2013 at 19:06 UTC
    I don't think the timeout is the problem (the problem seems to be running the command in the first place), but IPC::Run's timeout mechanism should work, and should terminate the process if it does timeout.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067036]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2015-07-08 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls