quantumpotato
quantumpotato

Reputation: 9767

Erlang process hanging when it tries to kill itself

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?

Upvotes: 1

Views: 317

Answers (1)

Ahmed Omar
Ahmed Omar

Reputation: 466

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

Upvotes: 1

Related Questions