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



在 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!

但随后外壳无限期地挂在那里。我用 CTRL+C 退出,然后 (A(bort。

为什么外壳没有自行终止?如何检查在此挂起状态下哪些进程仍处于活动状态?如果正常,如何以编程方式从测试脚本终止它?

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

erl -noinput -run nodes test_commit -s init stop

请注意,-noinput选项还意味着-noshell

最新更新