CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

Post #1 of 4 (1762 views)
Someone please help, I am absolutely stuck on this simple issue Can't Post

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

Post #2 of 4 (1755 views)
Re: [kavkazi] Someone please help, I am absolutely stuck on this simple issue [In reply to] Can't Post

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

Post #3 of 4 (1720 views)
Re: [wickedxter] Someone please help, I am absolutely stuck on this simple issue [In reply to] Can't Post

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

Post #4 of 4 (1657 views)
Re: [kavkazi] Someone please help, I am absolutely stuck on this simple issue [In reply to] Can't Post

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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives