Home: Perl Programming Help: Intermediate:
Someone please help, I am absolutely stuck on this simple issue



kavkazi
New User

Oct 15, 2012, 1:46 PM


Views: 3435
Someone please help, I am absolutely stuck on this simple issue

I have a simple perl script that calls a shell script which for whatever reason "hangs". I want to simply force a time out after 20 seconds. I did a lot of research and was brought to perl Alarms. It works when I test with sleep(), but when running the shell script the alarm doesn't kick in. Can someone please help???? Here is my code. Thanks in Advance.


Code
 
#!/bin/perl

use strict;
use warnings;

use CGI;

my $q = new CGI;

print $q->header;

eval {
local %SIG;
$SIG{ALRM}=
sub{ die "timeout reached, after 20 seconds!\n"; };
alarm 20;

#sleep (60);
system("/opt/bea/domain/fsa/scripts/start.sh");

alarm 0;
};

alarm 0;

if($@) { print "Error: $@\n"; }

exit(0);



wickedxter
User

Oct 15, 2012, 3:05 PM


Views: 3428
Re: [kavkazi] Someone please help, I am absolutely stuck on this simple issue

I tried your code but since i dont have the shell script i used something else... it reported after 20 seconds.... I think its the shell script is returning isnt not finished yet and is waiting for it to, so its just hanging.

this might shed some light on some things http://stackoverflow.com/questions/799968/whats-the-difference-between-perls-backticks-system-and-exec


(This post was edited by wickedxter on Oct 15, 2012, 3:06 PM)


kavkazi
New User

Oct 16, 2012, 6:22 AM


Views: 3393
Re: [wickedxter] Someone please help, I am absolutely stuck on this simple issue

This is a CGI script. The web server is waiting for the shell script to finish, because the shell script still has an open file handle to the standard output. How do I force a timeout, alarms doesn't seem to work.


wickedxter
User

Oct 17, 2012, 9:48 AM


Views: 3330
Re: [kavkazi] Someone please help, I am absolutely stuck on this simple issue

look in to this module this seems to be an easier way....
http://search.cpan.org/~bzajac/Proc-Background-1.10/lib/Proc/Background.pm