in reply to Timeout on STDIN

Signal handling varies greatly from OS to OS, and you don't mention what you're running on, but I'll take a stab at it.

The problem is that you're trying to call the routine from the signal handler. In turn, that routine expects to continue to receive SIGALRM, although in most cases, the signal won't be delivered while you're in the handler (otherwise the handler might get called recursively).

A better strategy would be to let the handler throw an exception, and then let the outer loop control the logic. Here's a modification of your program that does what (I think ;-) you want.

#!/usr/bin/perl -w $SIG{ALRM} = sub { die "timeout"; }; while (1) { eval { command(); }; if ($@) { if ($@ =~ /timeout/) { redo; } else { alarm(0); die; } } else { last; } } print "Done\n"; sub command { my $date = `date`; chomp($date); alarm(5); print "\n"; print "prompt $date > "; <>; alarm(0); }

HTH. The usual disclaimers apply: I'm not sure exactly what behavior you wanted, nor what OS you're on, yada, yada, yada.