Erlang进程挂起时试图杀死自己 [英] Erlang process hanging when it tries to kill itself

查看:233
本文介绍了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)。

进程(< 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),
进程(Ch)。

start() - >
io:setopts([{binary,true}]),
get_char()。

当我运行 ./ invoke.sh ,我按键并按预期的方式查看打印的字符。当我命中逃生时,shell窗口停止响应(我必须从终端关闭窗口)。为什么会发生这种情况?

解决方案

当您致电 exit / 1 只能终止erlang进程,不会停止erlang运行时系统(beam)。由于您没有运行shell,您会得到该窗口的行为没有响应。如果您从任务管理器或pkill中杀死光束过程,您将得到您的命令行。
一个简单的修复将是替换
exit(normal)
with
halt() 查看文档


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?

解决方案

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

这篇关于Erlang进程挂起时试图杀死自己的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆