Thread

Posted on Wed Nov 14 09:25:35 2007 by gnuey
alarms don't work on vms
See attached perl script. It creates a network port and waits for connections. It is suppose to time out in 30 seconds. The program works on Linux and on HPUX. But doesn't work on VMS. It never times out on VMS.
On Linux: # perl setalarm.pl setting alarm 1. process timed out at setalarm.pl line 10. closing socket On VMS (perl 5.8.6 with ECO1): $ perl setalarm.pl setting alarm Perl script: use IO::Socket::INET; my $server = IO::Socket::INET -> new ( LocalPort => 5556, Type => SOCK_STREAM, Reuse => 1, Listen => 30); eval { local $SIG{ALRM} = sub { die "process timed out"; }; print "setting alarm\n"; alarm 10; eval { my $client => $server -> accept(); }; alarm 0; print "1. $@\n" if ($@); }; alarm 0; print "2. $@\n" if ($@); print "closing socket\n"; close ($server);
Direct Responses: 6456 | Write a response
Posted on Wed Nov 14 22:31:27 2007 by cberry in response to 6452
Re: alarms don't work on vms

Yes they do. See longer response at:


https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1177355

The gist of it is that you have two unrelated problems. If you want want the accept() to time out you have to set a timeout before calling it, like so:


$server->timeout(30);

Whether an alarm causes a syscall to return is implementation defined and unrelated to the timeout problem, though you can shorten the timeout and requeue the accept if you want and thus have no need for the alarm. Perl's deferred signals prevent signal delivery until the current opcode completes; you can avoid signal deferral by using POSIX::sig_action, but it's not recommended.

Write a response