Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple_one_for_one can only be terminated if appointed SHUTDOWN strategy to brutal_kill?
    text
    copied!<p>The supervisor is an OTP behavior.</p> <pre><code>init([]) -&gt; RoomSpec = {mod_zytm_room, {mod_zytm_room, start_link, []}, transient, brutal_kill, worker, [mod_zytm_room]}, {ok, {{simple_one_for_one, 10, 10000}, [RoomSpec]}}. </code></pre> <p>Above code will invoke child's <code>terminate</code> method.</p> <p>But if I change the <code>brutal_kill</code> to an integer timeout (e.g. 6000), the <code>terminate</code> method was never invoked.</p> <p>I see an explanation in the Erlang document:</p> <blockquote> <p>The dynamically created child processes of a simple-one-for-one supervisor are not explicitly killed, regardless of shutdown strategy, but are expected to terminate when the supervisor does (that is, when an exit signal from the parent process is received).</p> </blockquote> <p>But I cannot fully understand. Is it said that <code>exit(Pid, kill)</code> can terminate a <code>simple_one_for_one</code> child spec while <code>exit(Pid, shutdown)</code> can't ?</p> <p>===================================update====================================</p> <p>mod_zytm_room_sup.erl</p> <pre><code>-module(mod_zytm_room_sup). -behaviour(supervisor). -export([start_link/0, init/1, open_room/1, close_room/1]). start_link() -&gt; supervisor:start_link({local, ?MODULE}, ?MODULE, []). init([]) -&gt; RoomSpec = {mod_zytm_room, {mod_zytm_room, start_link, []}, transient, brutal_kill, worker, [mod_zytm_room]}, {ok, {{simple_one_for_one, 10, 10000}, [RoomSpec]}}. open_room(RoomId) -&gt; supervisor:start_child(?MODULE, [RoomId]). close_room(RoomPid) -&gt; supervisor:terminate_child(?MODULE, RoomPid). </code></pre> <p>mod_zytm_room.erl</p> <pre><code>-module(mod_zytm_room). -behaviour(gen_server). -export([start_link/1]). -export([init/1, handle_cast/2, handle_info/2, handle_call/3, code_change/3, terminate/2]). start_link(RoomId) -&gt; gen_server:start_link(?MODULE, [RoomId], []). init([RoomId]) -&gt; {ok, []}. terminate(_, _) -&gt; error_logger:info_msg("~p terminated:~p", [?MODULE, self()]), ok. ...other methods ommited. </code></pre> <p>mod_zytm_sup.erl</p> <pre><code>-module(mod_zytm_sup). -behaviour(gen_server). -export([start_link/0]). -export([init/1, handle_cast/2, handle_info/2, handle_call/3, code_change/3, terminate/2]). start_link() -&gt; gen_server:start_link(?MODULE, [], []). init([]) -&gt; {ok, []}. %% invoked by an erlang:send_after event. handle_info({'CLOSE_ROOM', RoomPid}, State) -&gt; mod_zytm_room_sup:close_room(RoomPid), {noreply, State}. ...other methods ommited. </code></pre> <p>Both <code>mod_zytm_sup</code> and <code>mod_zytm_room_sup</code> are a part of a system supervision tree, <code>mod_zytm_sup</code> invoke <code>mod_zytm_room_sup</code> to create or close mod_zytm_room process.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload