nested alarm signals

John R. Comeau comeaujr at sd.conexant.com
Thu Jun 15 15:08:07 CDT 2000


~sdpm~
I've been using an alarm signal in my large Perl project to spawn
processes that I want to happen in the background.  In the process of
debugging this code, I found some unexpected behavior.  It seems that,
when a new process is launched within the alarm signal handler, the
new process can't respond to an alarm signal itself.  I wrote a simple
test case consisting of two files.  If you're on SanDieog.pm.org, they
are located in my home directory:

    /home/comeau/alarm_die.pl
    /home/comeau/call_alarm_die.pl

Here are the two files, alarm_die.pl followed by call_alarm_die.pl

-------------------- cut here --------------------
#!/usr/bin/perl

$SIG{ALRM} = sub {die 'ALARM'};

alarm 10;

<STDIN>;
-------------------- cut here --------------------
#!/usr/bin/perl

$SIG{ALRM} = sub {warn "calling alarm_die.pl\n"; `alarm_die.pl`};

# $SIG{ALRM}->();

alarm 10;

<STDIN>;
-------------------- cut here --------------------

When I run alarm_die.pl by itself, I get the following results:

    $ alarm_die.pl
    ALARM at alarm_die.pl line 3.

alarm_die.pl waits for STDIN but dies when the alarm occurs.  But when
I run call_alarm_die.pl, I get results I didn't expect:

    $ call_alarm_die.pl
    calling alarm_die.pl

Neither alarm_die.pl nor call_alarm_die.pl because alarm_die.pl is
waiting for STDIN.  It somewhow does not respond to the alarm it sets
(or doesn't successfully set the alarm).  I've never heard of this
behavior.  Is there some kind of Unix rule that you can't have nested
alarm signals?  Even if there was such a rule for a single process, it
seems odd to me that the child process for alarm_die.pl would be
affected by the fact that it was run from within an alarm signal
handler.

When alarm_die.pl is spawned from outside a signal handler, by
uncommenting line 5 of call_alarm_die.pl, alarm_die.pl runs as
expected; it dies from the alarm.

Sorry that this is more of a Unix question than Perl, but it is kind
of Perl, isn't it?

I spent several hours last night going crazy before I isolated this
problem to these nested alarm signals.

-- 
John Comeau (john.comeau at conexant.com) 858-713-3593 (W)
-------------------------------------------------------
Jeder Fallschirmspringer muss der Gefahr ins Auge
blicken.

Every parchutist has to face the danger.
~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> 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 happyfunball.pm.org> .
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