<div dir="ltr">Dear Forks,<div><br></div><div>I have a supervisor who will start children with simple_one_for_one strategy. First of all I have server process who starts the mentioned supervisor by using {ok, Pid} = supervisor:start_child(Supsup, ?SPEC), and then I add the children under the mentioned supervisor one by one also with supervisor:start_child(Pid, Args), but only the first child can be started and the rest children just got "process already started" error message. What's wrong I made? the snippets of the codes as following:</div>
<div><br></div><div><div>-module(spider_sup).</div><div>-behaviour(supervisor).</div><div><br></div><div>-export([start_link/0]). %% API.</div><div>-export([init/1]). %% supervisor.</div><div><br></div><div>-define(SUPERVISOR, ?MODULE).</div>
<div><br></div><div>%% API.</div><div><br></div><div>start_link() -></div><div> supervisor:start_link({local, ?SUPERVISOR}, ?MODULE, []).</div><div><br></div><div>%% supervisor.</div><div><br></div><div>init([]) -></div>
<div> MaxRestart = 5,</div><div> MaxTime = 60,</div><div> {ok, {{simple_one_for_one, MaxRestart, MaxTime},</div><div> [{spider,</div><div> {spider, start_link, []},</div>
<div> permanent,</div><div> 120,</div><div> worker,</div><div> [spider]}]}}.</div></div><div>----------------------------------------------------------------------------------------------------------</div>
<div><div>-module(spider).</div><div><br></div><div>-behavior(gen_fsm).</div><div><br></div><div>-export([start_link/1]).</div><div><br></div><div>-export([init/1,</div><div> event1/2,</div><div> handle_event/3,</div>
<div> handle_sync_event/4,</div><div> code_change/4,</div><div> terminate/3,</div><div> handle_info/3]).</div><div><br></div><div>start_link(Code) -></div><div>
gen_fsm:start_link({local, ?MODULE}, ?MODULE, Code, []).</div><div><br></div><div>init(Code) -></div><div> io:format("~p Starting~n",[Code]),</div><div> {ok, event1, Code, 10000}.</div></div>
<div>---------------------------------------------------------------------------------------------------</div><div><div>%snippet from the server process</div><div>start_spiders(_Pid, []) -></div><div> ok;</div><div>
start_spiders(Pid, [HCode | TCode]) -></div><div> supervisor:start_child(Pid, [HCode]),</div><div> start_spiders(Pid, TCode).</div></div><div><br></div><div><br></div></div>