Reputation: 7464
I have some server
-module(trivial).
-behaviour(gen_server).
-export([
init/1,
handle_call/3,
handle_cast/2
]).
init([]) ->
{ok, []}.
handle_call(_Msg, _From, State) ->
{reply, ok, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
and then I start it from inside of other process that (instantly) terminates:
c(trivial).
Before = length([ Proc || Proc <- processes(), is_process_alive(Proc) ]).
Pid = spawn(fun() -> gen_server:start_link(trivial, [], []) end).
false = is_process_alive(Pid).
Before = length([ Proc || Proc <- processes(), is_process_alive(Proc) ]).
Unfortunately, the last assertion does not hold: there is +1 alive process. I would assume that gen_server:start_link
inside of spawn
created a link, so if the spawned process dies, the server would die as well. Why doesn't it happen? How would I make it happen?
Upvotes: 0
Views: 46
Reputation: 3509
That happens because Pid
has no more instructions to run, so it exits with the reason normal
, which in this case is silently dropped. You have all the cases in the doc
Upvotes: 2