Erlang process hanging when it tries to kill itself

家住魔仙堡 提交于 2019-12-13 07:18:23

问题


I am running my erlang process with this script

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

my Erlang process:

-module(thing).
-compile(export_all).

process(<<27>>) ->
  io:fwrite("Ch: ~w", [<<27>>]),
  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().

When I run ./invoke.sh, I press keys and see the characters print as expected. When I hit escape, the shell window stops responding (I have to close the window from the terminal). Why does this happen?


回答1:


When you call exit/1 that only terminates the erlang process, that doesn't stop the erlang runtime system (beam). Since you're running without a shell, you get that behaviour of the window not responding. If you kill the beam process from your task manager or by pkill you'll get your command line back. An easy fix would be to replace exit(normal) with halt() see doc



来源:https://stackoverflow.com/questions/42792422/erlang-process-hanging-when-it-tries-to-kill-itself

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!