D
dn_perl
I run a perl script in which I call an interactive process which is
automated via a HERE document. But if something goes wrong with the
called process, say password has changed and my perl script is passing
the old, now-wrong password, it gets stuck and sort-of hangs. I would
like my code to address this situation. Smooth execution of the process
normally takes less than a second, at worst it could take 15 seconds. I
would like to add a while loop which keeps checking after a two-second
pause whether the called process has terminated. If it is still running
after 15 seconds, I would like to kill it.
Sample HERE-document (a shell-script named : exec_this.tmp) contents :
call_app << TO_HERE
username
password
option_number
more_inputs
TO_HERE
Perl Code (untested, to give the reader an idea of the flow) :
#!/bin/perl
use strict ;
`my_dir/exec_this.tmp` ; # (I may want to capture the pid of the
exec_this.tmp proc
# started via these back-tics. There are other ways to guess the
pid with
# reasonable accuracy, but capturing it would be fool-proof.)
# How to capture pid of the process started from within those
back-ticks?
# Please advise.
my $time_count = 0;
while (1) {
sleep 2 ;
$time_count = $time_count + 2;
if PID/PROC combo no longer active { last ; } ;
if( $time_count > 15 ) {
` kill -9 PID ` ;
last ;
}
}
How to read PID of the process started from within the backticks,
though?
Please help. Thanks in advance.
automated via a HERE document. But if something goes wrong with the
called process, say password has changed and my perl script is passing
the old, now-wrong password, it gets stuck and sort-of hangs. I would
like my code to address this situation. Smooth execution of the process
normally takes less than a second, at worst it could take 15 seconds. I
would like to add a while loop which keeps checking after a two-second
pause whether the called process has terminated. If it is still running
after 15 seconds, I would like to kill it.
Sample HERE-document (a shell-script named : exec_this.tmp) contents :
call_app << TO_HERE
username
password
option_number
more_inputs
TO_HERE
Perl Code (untested, to give the reader an idea of the flow) :
#!/bin/perl
use strict ;
`my_dir/exec_this.tmp` ; # (I may want to capture the pid of the
exec_this.tmp proc
# started via these back-tics. There are other ways to guess the
pid with
# reasonable accuracy, but capturing it would be fool-proof.)
# How to capture pid of the process started from within those
back-ticks?
# Please advise.
my $time_count = 0;
while (1) {
sleep 2 ;
$time_count = $time_count + 2;
if PID/PROC combo no longer active { last ; } ;
if( $time_count > 15 ) {
` kill -9 PID ` ;
last ;
}
}
How to read PID of the process started from within the backticks,
though?
Please help. Thanks in advance.