Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Alarm Timer Win32

by cutter (Acolyte)
on Sep 19, 2005 at 18:23 UTC ( [id://493233]=perlquestion: print w/replies, xml ) Need Help??

cutter has asked for the wisdom of the Perl Monks concerning the following question:

Not getting the desired behavior from the alarm function on WinXP Activestate Perl 5.8.6. It alarms at 1 sec, nothing greater. Reading the release notes I see where signals are handled after a operation is complete. So I guess this is expected behaviour or is something else going on here? Any sugestions on how to make a timer on my ssh session without using alarm()?
use strict; use Net::SSH::Perl; #Use this perl mod to create the SSH session. use Net::SSH::W32Perl; my $host = ""; my $user = ""; my $pw = ""; sub error { die "ERROR! ERROR! ERROR! @_"; } sub ssh_cmd{ my $ssh = new Net::SSH::W32Perl($host); $ssh->login($user, $pw); my $cmd = "./test_alarm.pl > test_alarm.out 2>&1"; my ($out, $err, $exit) = $ssh->cmd($cmd,"\n"); } my $TIMEOUT = 2; # seconds eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $TIMEOUT; ssh_cmd(); alarm 0; }; if ($@) { if($@ eq "alarm\n") { error("OPERATION TIMED OUT!"); } else { error("your_code() generated errors: $@"); } }

Replies are listed 'Best First'.
Re: Alarm Timer Win32
by puploki (Hermit) on Sep 19, 2005 at 18:46 UTC

    Despite Windows NT variants claiming to be POSIX compliant (laughs) SIGALRM is not supported under Windows. Well, rather, it claims it is, but doesn't work as you've found out.

    Perhaps an approach might be to fork() an external watcher process that looks for an established tcp connection with netstat which returns after x seconds if it doesn't find it or something - vile and horrible I know... Bloody Windows ;)

      Agree with you on the vile and horrible. I was hoping it was just me doing something stupid but I guess not.

      Bloody Windows....

Re: Alarm Timer Win32
by polypompholyx (Chaplain) on Sep 19, 2005 at 18:53 UTC
    alarm never used to work on Windows/Activeperl (winfaq5), so you may not have much luck with this.
Re: Alarm Timer Win32
by PodMaster (Abbot) on Sep 20, 2005 at 14:35 UTC
    Try unsafe signals (set PERL_SIGNALS=unsafe).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      You da man!! That seems to do the trick.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://493233]
Approved by socketdave
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-25 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found