[erlang-questions] supervisors, gen_server:terminate/2, and trap_exit

Fred Hebert mononcqc@REDACTED
Thu Mar 12 00:20:41 CET 2015


On 03/11, Youngkin, Rich wrote:
> "terminate/2 will also be called when its parent (the process that spawned
> it) dies, if and only if the gen_server is trapping exits."
> 
> [...]
> 
> The Erlang documentation on Supervisors states "Note that all child
> processes implemented using the standard OTP behavior modules automatically
> adhere to the shutdown protocol.". I'm having trouble reconciling these
> LYSE with the Erlang Supervisor docs.
> 
> Thanks,
> Rich

The references I found to the shutdown protocol is:

http://www.erlang.org/documentation/doc-4.9.1/doc/design_principles/sup_princ.html#shutdown

"The supervisor process sends an exit signal to the child process and
waits for acknowledgment. The child process should handle the
{'EXIT',ParentPid,shutdown} message and terminate with reason shutdown
if it traps exit signals."

The last line here is important -- if it traps exit signals. This is in
agreement with what LYSE mentions. If you don't trap exit signals, you
can't get the signal, it just kills the process directly.

Regards,
Fred.



More information about the erlang-questions mailing list