今天接續昨天的捕捉離開信號,各processes之間的互動關係.
process [B] 在今天的情境,都會以system_process的型態來互動.
情境4
[A] <--> [B] <--> [C]
5> e1017a:start(true, {die, by_command}).
Process b received {'EXIT',<0.54.0>,by_command}
Process b (<0.53.0>) is alive
Process c (<0.54.0>) is dead
ok
過程:
[A] <--> [B] <-- dead (Reason:by_command)
[A] <--> [B]
只有[B]收到,[A] 是被隔離開的.不受[C]離開的影響.
情境5
[A] <--> [B] <--> [C]
這次[C]將正常離開.
6> e1017a:start(true, normal).
Process b received {'EXIT',<0.58.0>,normal}
Process b (<0.57.0>) is alive
Process c (<0.58.0>) is dead
ok
這是一般正常的情況.結束後正常脫離. [B],[A]均正常.
情境6
[A] <--> [B] <--> [C]
這次[C]會發生除以0錯誤.
7> e1017a:start(true, {divide, 0}).
Process b received {'EXIT',<0.62.0>,
{badarith,
[{e1017a,c,2,[{file,"e1017a.erl"},{line,29}]}]}}
=ERROR REPORT==== 17-Oct-2014::15:27:54 ===
Error in process <0.62.0> with exit value: {badarith,[{e1017a,c,2,[{file,"e1017a.erl"},{line,29}]}]}
Process b (<0.61.0>) is alive
Process c (<0.62.0>) is dead
ok
過程:
[A] <--> [B] <-- dead(Reason:badarith) =ERROR REPORT==== [C]
[A] <--> [B]
系統偵測到發生除以0錯誤! 產生Error report!
[B]捕捉到[C]的錯誤以及原因,[B]依然存活! [A]完全不受影響!
可以看到[A]可以受到[B]的保護,就好像是防火牆一樣.
明天我們將繼續探討如何應用此一機制.