Erlang / Erlang Basics Interview questions
What happens when a linked process crashes?
When a linked process terminates abnormally, the BEAM sends an exit signal carrying the exit reason to every process it's linked to. What happens next depends on whether the receiving process is trapping exits.
process_flag(trap_exit, true), Pid = spawn_link(fun() -> exit(boom) end), receive {'EXIT', Pid, Reason} -> io:format("child died: ~p~n", [Reason]) end.
By default, a process receiving a non-normal exit signal also terminates with that same reason, propagating
the failure outward — which is exactly how a crash in one worker can cascade up to a supervisor. If the
receiving process has called process_flag(trap_exit, true), the exit signal instead arrives as an
ordinary {'EXIT', Pid, Reason} message it can pattern-match on and react to, which is precisely
how supervisors detect child crashes without being killed by them.
More Related questions...