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

Re: Timing out backquoted executions

by Trizor (Pilgrim)
on Aug 02, 2007 at 19:51 UTC ( [id://630373]=note: print w/replies, xml ) Need Help??


in reply to Timing out backquoted executions

You want an alarm, however with backticks this does leave the process hanging and there's no easy way to get its pid, but it is your child so you can do things to your process group to take it down, perhaps an END that sigkills the process group?

eval { local $SIG{ALRM} = sub { die "Alarma" }; alarm 10; `perl -e 'while(1) {};'`; alarm 0; }; if ($@ eq 'Alarma') { warn "alarm'd"; } elsif ($@) { die $@; }

Replies are listed 'Best First'.
Re^2: Timing out backquoted executions
by Anonymous Monk on Aug 02, 2007 at 20:10 UTC
    Thanks guys. Now I'm noticing though that when I do this, the process continues running. How can I be sure to terminate this process?

    > cat perl.pl #!/usr/bin/perl eval { $SIG{ALRM} = sub { die "Timed out\n"; }; alarm(5); `perl -e 'while(1){sleep 1;}'`; alarm(0); }; print "Died with: $@\n"; > ./perl.pl Died with: Timed out > ps PID TTY TIME CMD 11551 pts/0 00:00:00 bash 11648 pts/0 00:00:00 perl 11651 pts/0 00:00:00 ps

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-24 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found