为什么Erlang shell在所有这些进程结束后都没有终止?

时间:2014-12-07 13:50:45

标签: shell erlang

https://github.com/giorgiosironi/erlang-2pc/blob/master/nodes.erl#L95中,我产生了3个进程,这些进程在算法结束后终止(或者我认为:它们的函数返回)。 我认为start / 0函数也已终止。

我开始执行此功能: 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!

然后shell无限期挂起。我用CTRL + C然后退出(A)bort。

为什么shell不会自行终止?如何在这种挂起的状态下检查shell中哪些进程仍然存活?如果这是正常的,我如何从我的测试脚本中以编程方式终止它?

1 个答案:

答案 0 :(得分:5)

一旦完成运行函数,您需要告诉运行时停止。一种方法是使用init:stop/0函数:

erl -noinput -run nodes test_commit -s init stop

请注意,-noinput选项还隐含-noshell