<div dir="ltr"><div class="gmail_extra"><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 11, 2015 at 5:20 PM, Fred Hebert <span dir="ltr"><<a href="mailto:mononcqc@ferd.ca" target="_blank">mononcqc@ferd.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 03/11, Youngkin, Rich wrote:<br>> "terminate/2 will also be called when its parent (the process that spawned<br>> it) dies, if and only if the gen_server is trapping exits."<br>><br></span>> [...]<br><span class="">><br>> The Erlang documentation on Supervisors states "Note that all child<br>> processes implemented using the standard OTP behavior modules automatically<br>> adhere to the shutdown protocol.". I'm having trouble reconciling these<br>> LYSE with the Erlang Supervisor docs.<br>><br></span>> Thanks,<br>> Rich<br><br>The references I found to the shutdown protocol is:<br><br><a href="http://www.erlang.org/documentation/doc-4.9.1/doc/design_principles/sup_princ.html#shutdown" target="_blank">http://www.erlang.org/documentation/doc-4.9.1/doc/design_principles/sup_princ.html#shutdown</a><br><br>"The supervisor process sends an exit signal to the child process and<br>waits for acknowledgment. The child process should handle the<br>{'EXIT',ParentPid,shutdown} message and terminate with reason shutdown<br>if it traps exit signals."<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>The last line here is important -- if it traps exit signals. This is in<br>agreement with what LYSE mentions. If you don't trap exit signals, you<br>can't get the signal, it just kills the process directly.<br></blockquote><div><br class="">So let's say that:</div><div>  1. Supervisor1 starts Supervisor2 and GenServerA in that order.</div><div>  2. A Supervisor1 is given a child_spec with a simple_one_for_one restart strategy.</div><div>  3. GenServerA implements a start/0 API function that results in calling supervisor:start_child(Supervisor1, [SomeArgs]) that creates ChildZ.</div><div>  4. ChildZ's init/1 function does not trap_exits.</div><div>  4. GenServerA also implements a stop/0 API function that results in calling supervisor:terminate_child(Supervisor1, ChildZPid)</div><div><br></div><div>At step 4, will ChildZ:terminate/2 get called? Or does it have to trap_exit? If it's the latter AND ChildZ doesn't trap_exit then it seems as if ChildZ would have to implement handle_info('EXIT', ParentPid, shutdown) which could then call terminate/2?</div><div><br></div><div>Thanks,</div><div>Rich</div><div>  </div><div><br></div></div></div></div></div>