【问题标题】:Why the Erlang shell does not terminate after all these processes have reached their end?为什么 Erlang shell 在所有这些进程都结束后没有终止?
【发布时间】:2014-12-07 22:23:19
【问题描述】:

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。

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

【问题讨论】:

  • init:stop() 是以干净的方式终止 erlang 的标准方式。它首先停止所有应用程序,然后停止 erlang 系统本身。

标签: shell erlang


【解决方案1】:

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

erl -noinput -run nodes test_commit -s init stop

请注意,-noinput 选项也暗示了-noshell

【讨论】:

  • 我认为这意味着nodes:test_commit/0 必须等待生成的进程终止,但这很好,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-16
  • 2018-08-01
  • 1970-01-01
  • 2021-02-02
  • 2016-07-09
  • 1970-01-01
  • 2021-11-15
相关资源
最近更新 更多