ijt
ijt

Reputation: 3825

How can I abort a receive statement in the Erlang shell (erl) without aborting erl?

The following makes erl hang:

$ erl
Erlang/OTP 24 [erts-12.1] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1] [jit] [dtrace]

Eshell V12.1  (abort with ^G)
1> receive X -> X end.

Hitting ctrl-C brings up a menu of options:

BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo

However, I have not found that any of those returned me to the erl prompt. Is the idea that you have to Let It Crash by choosing "(a)bort" and then starting erl again?

Upvotes: 2

Views: 429

Answers (1)

Steve Vinoski
Steve Vinoski

Reputation: 20014

The answer is in parentheses right above your shell prompt:

(abort with ^G)

If you hit ctrl-G, you get a User switch command prompt. You can type h at this prompt to see what you can do:

User switch command
--> h
 c [nn]            - connect to job
 i [nn]            - interrupt job
 k [nn]            - kill job
 j                 - list all jobs
 s [shell]         - start local shell
 r [node [shell]]  - start remote shell
 q                 - quit erlang
 ? | h             - this message

Let's list the jobs:

--> j
  1* {shell,start,[init]}

That's the shell running your receive. You can kill it with k, and after that, j shows that no jobs are running, so then use s to start a new shell, which j then shows, and then use c to connect to that new shell:

--> k 1
--> j
--> s
--> j
  2* {shell,start,[]}
--> c 2
Eshell V12.1  (abort with ^G)
1>

Upvotes: 6

Related Questions