Szetty

Szetty

Processes linked to IEx are not killed when IEx exits

Hello,

So I have learnt a new thing recently, processes spawned in an IEx shell are not terminated after IEx exists, not even if they were started using link. The same obviously is not true for any two processes linked between them, and not even true for Erlang shells, so it is really about IEx only.

When inspecting the processes I can see that the link just disappears and the “child” process is still alive after IEx process (which was the “parent”) is long gone.

I have been researching this, but could not find any Elixir, Erlang or C code pointing in this direction.

Does anyone have any idea how and where this is implemented ?

Most Liked

jstimps

jstimps

This was interesting, so I wanted to try to reproduce it, and it’s true. Please excuse the old versions.

jstimpson@myhost:~$ ./bin/myapp remote
Erlang/OTP 25 [erts-13.2.2.15] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.15.8) - press Ctrl+C to exit (type h() ENTER for help)
iex(myapp@myhost)1> spawn_link(fn -> :timer.sleep(100000000) end)
#PID<0.5573.0>
iex(myapp@myhost)2> :erlang.is_process_alive(pid(0, 5573, 0))
true
iex(myapp@myhost)3>
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
       (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
a
jstimpson@myhost:~$ ./bin/myapp remote
Erlang/OTP 25 [erts-13.2.2.15] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.15.8) - press Ctrl+C to exit (type h() ENTER for help)
iex(myapp@myhost)1> :erlang.is_process_alive(pid(0, 5573, 0))
true
jstimps

jstimps

The behavior in the remote shell case is surprising to me personally, since my background is mostly in Erlang, in which it’s different. To demonstrate:

Terminal A:

~ ❯❯❯ iex --sname server # or `erl -sname server`
Erlang/OTP 27 [erts-15.2.6] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Interactive Elixir (1.18.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(server@Mac)1>

Terminal B:

~ ❯❯❯ erl -remsh server
Erlang/OTP 27 [erts-15.2.6] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Eshell V15.2.6 (press Ctrl+G to abort, type help(). for help)
(server@Mac)1> spawn_link(fun() -> timer:sleep(1000000000) end).
<0.127.0>
(server@Mac)2>
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
       (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
a
~ ❯❯❯ erl -remsh server
Erlang/OTP 27 [erts-15.2.6] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Eshell V15.2.6 (press Ctrl+G to abort, type help(). for help)
(server@Mac)1> is_process_alive(pid(0,127,0)).
false
(server@Mac)2>

Coming from Erlang, I had a natural expectation that halting an iex remote shell would trigger links on processes that were started in that shell. My expectation turned out to be wrong, but I can see how this would end up causing unexpected system behavior during debugging sessions. I will attempt a PR to the iex docs to explain the behavior, as I don’t see anything in there currently (although I might have missed it!)

Edit: doc change merged to elixir main :heart:

Szetty

Szetty

Found the explanation while discussing with Claude LLM, and the answer is as simple as possible: when shutting down IEx with “Ctrl + C” and “a” the process exits normally, so the link is not triggered, because it is not a crash.

Where Next?

Popular in Questions Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement