Erlang进程在试图自杀时挂起

我用这个脚本运行我的erlang进程

#!/bin/sh stty -f /dev/tty icanon raw erl -pa ./ -run thing start -run init -noshell stty echo echok icanon -raw 

我的Erlang流程:

 -module(thing). -compile(export_all). process(<>) -> io:fwrite("Ch: ~w", [<>]), exit(normal); process(Ch) -> io:fwrite("Ch: ~w", [Ch]), get_char(). get_char() -> Ch = io:get_chars("p: ", 1), process(Ch). start() -> io:setopts([{binary, true}]), get_char(). 

当我运行./invoke.sh ,我按下键并按预期看到字符打印。 当我点击逃生时,shell窗口停止响应(我必须从终端关闭窗口)。 为什么会这样?

当你调用只能终止erlang进程的exit/1 ,这不会停止erlang运行时系统(beam)。 由于您在没有shell的情况下运行,因此窗口的行为无法响应。 如果您从任务管理器或pkill中终止梁进程,您将获得命令行。 一个简单的解决方法是用halt()替换exit(normal) , 参见doc