#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0

    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);
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    I believe it's because the 'system' function has already done a fork(), then wait() for the result.
    Check out this info:
    http://www.perlmonks.org/?node_id=324176
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    6
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo