concurrency - Can I catch an external exit in Erlang? -
i have 2 processes linked; let's they're a , b , a set trap exits. want able recover piece of b 's process data if calls exit/2 on it, e.g. exit(b, diediedie) . in b 's module, let's call bmod.erl , have code looks this: -module(bmod). -export([b_start/2]). b_start(a, x) -> spawn(fun() -> b_main(a, x) end). b_main(a, x) -> try ! {self(), doing_stuff}, do_stuff() catch exit:_ -> exit({terminated, x}) end, b_main(a, x). do_stuff() -> io:format("doing stuff.~n",[]). and in a 's module, let's call amod.erl , have code looks this: -module(amod). -export([a_start/0]). a_start() -> process_flag(trap_exit, true), link(bmod:b_start(self(), some_stuff_to_do)), a_main(). a_main() -> receive {pid, doing_stuff} -> io:format("process ~p did stuff.~n",[pid]), exit(pid, diediedie), a_main(); {'exit', pid, {terminated, ...