2014-12-07 72 views
3

https://github.com/giorgiosironi/erlang-2pc/blob/master/nodes.erl#L95我產生了3個進程,在算法結束後終止(或者我認爲:他們的函數返回)。 我認爲啓動/ 0功能已經終止。爲什麼在所有這些進程到達最終狀態之後,Erlang shell都不會終止?

我開始這個功能與執行: erl -noshell -run nodes test_commit -noshell

執行功能後,我得到我的預期輸出: <0.30.0> - As coordinator added cohort: <0.31.0> <0.31.0> - Will propose: yes <0.32.0> - Will propose: yes <0.30.0> - As coordinator added cohort: <0.32.0> <0.30.0> - As coordinator, 1st phase trying to commit <0.31.0> - Queried by coordinator <0.32.0> - Queried by coordinator <0.30.0> - As coordinator received a yes <0.30.0> - As coordinator received a yes <0.30.0> - As coordinator, 2nd phase <0.31.0> - COMMIT! <0.32.0> - COMMIT! <0.30.0> - COMMIT!

但隨後的殼掛在那兒下去。我用CTRL + C退出,然後(A)退出。

爲什麼shell不會自行終止?如何在掛起狀態下檢查哪些進程仍處於活動狀態?如果這是正常的,我怎樣才能從我的測試腳本以編程方式終止它?

+0

'init:stop()'是以乾淨的方式終止erlang的標準方式。它首先停止所有的應用程序,然後erlang系統本身。 – rvirding 2014-12-08 11:37:51

回答

5

您需要告訴運行庫在完成運行功能後停止運行。要做到這一點的方法之一是使用init:stop/0功能:

erl -noinput -run nodes test_commit -s init stop 

注意,-noinput選項也意味着-noshell

+0

我認爲這意味着'節點:test_commit/0'必須等待產生的進程終止,但這很好,謝謝。 – giorgiosironi 2014-12-08 10:58:01

相關問題