Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Killing a shell script from within a perl script

by jettero (Monsignor)
on Mar 03, 2010 at 16:49 UTC ( #826454=note: print w/ replies, xml ) Need Help??


in reply to Killing a shell script from within a perl script

use fork, exec, alarm, and kill ... or maybe check out POE.

IPC::Open2 and IPC::Open3 may help do the job as well.

-Paul


Comment on Re: Killing a shell script from within a perl script
Re^2: Killing a shell script from within a perl script
by strider88 (Initiate) on Mar 03, 2010 at 17:12 UTC

    I tried doing this:

    eval { local $SIG{ALRM}=sub{die "alarm\n"}; alarm 600; $shell_out = system("./sh1.sh"); alarm 0; }; if($@) { die unless $@ eq "alarm\n"; }
    It turns out that the shell script is not even executed.

      The problem with this code is that the shell script isn't being killed.

      alarm just arranges for a signal to be delivered to the Perl process, upon which the signal handler throws an exception (die "alarm\n") which in turn causes the Perl script to continue after the eval {} block. The shell script doesn't know anything of this and happily keeps running.

      It turns out that the shell script is not even executed.

      This is most likely an unrelated problem. Makes me wonder how/why it did run before with the identical system command...

        I too am wondering the same. Meanwhile, I tried executing the following line of code on shell, and it worked:

        perl -e 'alarm shift @ARGV; exec @ARGV' 100 ./sh1.sh
        But I am not able to run this command from my perl script using the system function, within the while loop. That is weird! Any idea why this would happen? Also, the above command does not kill the process, it just suspends it. Is there a way to kill it?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (22)
As of 2014-12-18 18:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (59 votes), past polls