T
torahul
Hi,
Wondering what's happening here -- is it a bug or an expected behavior
from perl ? I am trying to set SIGALRM handle from within a
subroutine; surprisingly it executes the handler rotine soon I assign
to SIG{"ALRM"}, even I haven't set any alarm! If I move SIG{"ALRM"}
assignment outside the subroutine, it's working as I would expect.
Following perl code :
----------------- Start of Script -----------------
#!/usr/local/bin/perl
$pid = 0;
sub s_alarm_handler {
print ("$$ : *** KILLING process(pid=$pid) after timeout\n");
kill ("KILL", $pid);
}
sub s_sub1 {
local (@args) = @_;
print ("Setting alarm routine to s_alarm_handler\n");
$SIG{"ALRM"} = s_alarm_handler;
print ("Alarm routine set to s_alarm_handler\n");
}
&s_sub1 ("something");
--------------- End of Script ---------------
Running above script generates this output :
---------- Output ---------
Setting alarm routine to s_alarm_handler
18411 : *** KILLING process(pid=0) after timeout
Killed
------ End of Output ------
$ /usr/local/bin/perl -v
This is perl, version 5.004_04 built for sun4-solaris
Copyright 1987-1997, Larry Wall
Wondering what's happening here -- is it a bug or an expected behavior
from perl ? I am trying to set SIGALRM handle from within a
subroutine; surprisingly it executes the handler rotine soon I assign
to SIG{"ALRM"}, even I haven't set any alarm! If I move SIG{"ALRM"}
assignment outside the subroutine, it's working as I would expect.
Following perl code :
----------------- Start of Script -----------------
#!/usr/local/bin/perl
$pid = 0;
sub s_alarm_handler {
print ("$$ : *** KILLING process(pid=$pid) after timeout\n");
kill ("KILL", $pid);
}
sub s_sub1 {
local (@args) = @_;
print ("Setting alarm routine to s_alarm_handler\n");
$SIG{"ALRM"} = s_alarm_handler;
print ("Alarm routine set to s_alarm_handler\n");
}
&s_sub1 ("something");
--------------- End of Script ---------------
Running above script generates this output :
---------- Output ---------
Setting alarm routine to s_alarm_handler
18411 : *** KILLING process(pid=0) after timeout
Killed
------ End of Output ------
$ /usr/local/bin/perl -v
This is perl, version 5.004_04 built for sun4-solaris
Copyright 1987-1997, Larry Wall