in reply to $SIG{'ALRM'} on FreeBSD

Did you copy and paste that code, or attempt to retype it?

$ perl temp.pl String found where operator expected at temp.pl line 13, near "d 'Time +out on read'" (Do you need to predeclare d?) syntax error at temp.pl line 13, near "d 'Timeout on read'" Missing right curly or square bracket at temp.pl line 16, at end of li +ne syntax error at temp.pl line 16, at EOF Execution of temp.pl aborted due to compilation errors.

update: Ah, now (with your sub d) I get 100% CPU utilization, for much longer than a second, which I guess is probably similar to what you're getting, and which is presumably not what you want. So yeah, it appears the problem is not just something weird with your local setup, which is what I was trying to confirm. I threw in an extra warn and confirmed that $paddr is always undef, but I imagine what you're trying to do is limit execution time when there's no connection. Hmmm... select undef,undef,undef,$delay can measure fractional parts of a second, but I don't know how small its resolution goes. That would also stop you from consuming 100% CPU, though: just loop through $n tries with $totaltimelimit/$n delay each time. Would that work?

$ perl -v This is perl, v5.8.7 built for i386-freebsd-64int (with 2 registered patches, see perl -V for more detail) Copyright 1987-2005, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.

I wanted to help you out by testing your code on another FreeBSD system, but I think there's more wrong than $SIG{ALRM} only.


Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. Why, I've got so much sanity it's driving me crazy.

Replies are listed 'Best First'.
Re^2: $SIG{'ALRM'} on FreeBSD
by b888 (Beadle) on Feb 24, 2006 at 13:38 UTC

    Well, i thought the mistake is in my approach of usage of alrm signal, that's why i pasted only part where i used it. Sorry :) In fact i can't simulate that situation myself. But it happend on 3 servers already (all under freebsd) and not even on 1 from 4 under Linux.

    Maybe you can suggest me another way of usage of timeout-ed operations? Means when need to limit time of execution of some subs. And limit for time smaller then second.

    p.s. my "d" sub :)

    sub time_stamp { my $time = shift; $time = time() if ! defined $time; my ($sec, $min, $hour, $mday, $mon, $year) = localtime($time); return sprintf("%02d:%02d:%02d %02d/%02d/%04d", $hour, $min, $sec, $mday, $mon+1, $year+1900); } sub d { print "[".time_stamp()."] ".(caller(0))[0].", "; print shift; print "\n"; }

      After some experimentation, I have concluded that on my system the resolution of select undef,undef,undef,$fractionalsecond goes down to something on the order of 1/300 of a second, give or take. This is an estimate, and I haven't done proper benchmarks, and YMMV.

      perl -e ' my $times = 5000; print "Starting: " . localtime() . "\n"; for (1..$times) { select undef,undef,undef,1/$times; } print "Done: " . localtime() . "\n"; ' Starting: Fri Feb 24 10:54:56 2006 Done: Fri Feb 24 10:55:06 2006

      About ten seconds to do 5000 iterations, would lead me to say 500 iterations per second would be the limit (on this system), but if I set $times to 300 it takes a full second or slightly more, so there's some overhead making the calculation imprecise. HTH.HAND.