2016-09-21 14 views
2
+可能性

場景:父進程應產卵n個工作兒童加載數據至階段表,父頻繁地(每15分鐘)調用存儲過程以從載物臺移動的日期 - >芯的Perl多發性ALRM信號

建議:計劃每15分鐘設置一個'$ SIG {ALRM}'處理程序並調用信號處理程序中的存儲過程。

尋求建議,如果建立Signal處理程序來調用執行時間應該大約爲5分鐘的存儲過程是個好主意,想知道如果另一個ALRM信號關閉時存儲過程超過15分鐘會發生什麼。

這會第二信號得到

  • 排隊等待稍後處理
  • 丟失完全
  • 調用另一個處理程序和存儲過程的實例,而以前的處理程序仍在運行。

回答

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處理程序返回。

+0

請注意,如果您想獲得不同的結果,您可以確實揭露SIGALRM。 – ikegami

+0

感謝ikegami,精彩的模擬! – Shashi