Catch Timeout for system calls in Windows?

Discussion in 'Perl Misc' started by peterkayatwork@yahoo.com, Dec 8, 2004.

  1. Guest

    I'm using ActiveState Perl on a Windows XP platform, and want to kick
    off some scripts from one central location. However, I want to make
    sure these scripts exit, and would like to timeout if they don't.
    Ideally, I want to grab the output as well, but I can handle that by
    redirecting to output files if I need.

    Can anyone suggest a way to do this? Can anyone suggest what to look
    for?

    If I were doing this in a *nix environment, I'd try signals, but I
    suspect that cygwin just isn't going to handle them; if anyone knows
    better, let me know :)

    Example of what won't work:
    foreach my $script (@scripts) {
    system($script); # no timeout!
    }

    Thanks,

    --Peter
     
    , Dec 8, 2004
    #1
    1. Advertising

  2. Chris Cole Guest

    On Wed, 08 Dec 2004 07:14:45 -0800, peterkayatwor wrote:

    > I'm using ActiveState Perl on a Windows XP platform, and want to kick
    > off some scripts from one central location. However, I want to make
    > sure these scripts exit, and would like to timeout if they don't.
    > Ideally, I want to grab the output as well, but I can handle that by
    > redirecting to output files if I need.
    >
    > Can anyone suggest a way to do this? Can anyone suggest what to look
    > for?
    >
    > If I were doing this in a *nix environment, I'd try signals, but I
    > suspect that cygwin just isn't going to handle them; if anyone knows
    > better, let me know :)
    >
    > Example of what won't work:
    > foreach my $script (@scripts) {
    > system($script); # no timeout!
    > }
    >

    How about using an eval block with an alarm? Someething like:

    foreach my $script (@scripts) {
    eval {
    alarm(360); # set time limit to 6 mins
    system($script);
    alarm(0); # if $script finishes in <6min reset alarm
    }
    if ($@) {
    # do stuff if eval fails (eg timeout)
    }

    Chris.
     
    Chris Cole, Dec 8, 2004
    #2
    1. Advertising

  3. Guest

    I got "Alarm clock" on the cygwin prompt and the script died.

    I played around with it and came up with:

    eval {
    # from http://www.rocketaware.com/perl/perlfunc/alarm.htm
    local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required
    alarm(5); # set time limit to 5 sec
    system($script);
    alarm(0); # if $script finishes in <5sec reset alarm
    };
    die if $@ && $@ ne "alarm\n"; # propagate errors
    if ( $@ ) {
    print "Timeout! [$@]\n";
    # do stuff if eval fails (eg timeout)
    }

    Thanks for the suggestion :)

    --Peter
     
    , Dec 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karl Seguin
    Replies:
    1
    Views:
    5,575
    Arun M
    Sep 4, 2007
  2. Ersin Gençtürk
    Replies:
    1
    Views:
    7,256
    jmohanty2006
    Sep 25, 2007
  3. John Black
    Replies:
    8
    Views:
    4,186
    Xenos
    Aug 20, 2004
  4. Richard Tobin
    Replies:
    24
    Views:
    813
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,310
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page