nested alarm signals (fwd)

The Chazman chaz at
Thu Jun 15 18:34:44 CDT 2000

> Why not spawn helper programs before you look for input?  Or why not just
> set a flag in the sig handler and in whatever loop you have around the
> STDIN loop launch your alternate process.

That's the ticket.  I highly recommend that approach.

> use vars qw($ALARM_SIGNALED);
> $SIG{ALRM} = sub { $ALARM_SIGNALED++ }
> while (<STDIN>) {
> 		launch_other_proc();
> 	}
> 	... Continue processing STDIN.
> }

This illustrates the basic idea.  But as I said in my other post, you
need to take care of a few little details that Perl hides from you.  One
is to make sure your alarm handler get registered so as not to restart
an interrupted system call by itself.  The other is to differentiate
a failure of the read() in the while loop from reading a valid EOF
condition.  I'm not sure how to do this in Perl, but that's the key
point that's missing.  If it's a real EOF, you want to break out of
the loop.  If it's an error and the error is EINTR, you want to check
the alarm signalled variable, launch_other_proc() and reset the
variable if it was set, then drop back into the loop with another read
from STDIN.  (i.e. you really want a "next;" statement after the call
to launch_other_proc(), inside the if-then)

                         Carl N Miller
                         chaz at

The posting address is: san-diego-pm-list at

List requests should be sent to: majordomo at

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at> .
This is the general rule for most mailing lists when you need
to contact a human.

More information about the San-Diego-pm mailing list