场景:父进程将生成N个工作子项以将数据加载到阶段表,并且Parent经常(每15分钟)调用一个存储过程来从阶段移动日期 - >芯
想法计划每15分钟设置' $ SIG {ALRM}' 处理程序,并在信号处理程序中调用存储过程。
寻求建议,如果设置信号处理程序以调用执行时间应为~5分钟的存储过程是个好主意,想知道如果存储过程在另一个ALRM信号关闭后运行超过15分钟会发生什么。
这第二个信号是否会
答案 0 :(得分:2)
如果你有
,你会问你会发生什么$SIG{ALRM} = sub {
alarm(15*60);
call_stored_proc();
};
alarm(15*60);
和call_stored_proc
的时间超过15分钟。你为什么不尝试呢?
perl -e'
use feature qw( say );
my $slow = 2;
my $done = 0;
sub call_stored_proc {
say sprintf "[%s] %s: %s", time, "call_stored_proc", "enter";
sleep($slow ? 8 : 2);
say sprintf "[%s] %s: %s", time, "call_stored_proc", "leave";
$done = 1 if !$slow;
--$slow;
}
$SIG{ALRM} = sub {
say sprintf "[%s] %s: %s", time, "SIGALRM hander", "enter";
say sprintf "[%s] %s: %s", time, "SIGALRM hander", "alarm set for ".(time+5);
alarm(5);
call_stored_proc();
say sprintf "[%s] %s: %s", time, "SIGALRM hander", "leave";
};
say sprintf "[%s] %s: %s", time, "[root]", "alarm set for ".(time+5);
alarm(5);
sleep(1) while !$done;
'
输出:
[1474490009] [root]: alarm set for 1474490014
[1474490014] SIGALRM hander: enter
[1474490014] SIGALRM hander: alarm set for 1474490019
[1474490014] call_stored_proc: enter
[1474490022] call_stored_proc: leave
[1474490022] SIGALRM hander: leave
[1474490022] SIGALRM hander: enter
[1474490022] SIGALRM hander: alarm set for 1474490027
[1474490022] call_stored_proc: enter
[1474490030] call_stored_proc: leave
[1474490030] SIGALRM hander: leave
[1474490031] SIGALRM hander: enter
[1474490031] SIGALRM hander: alarm set for 1474490036
[1474490031] call_stored_proc: enter
[1474490033] call_stored_proc: leave
[1474490033] SIGALRM hander: leave
如您所见,call_stored_proc
并未中断。在SIGALRM处理程序返回之前,SIGALRM被禁止。