<div dir="ltr">Got it! Thank you very much!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 30, 2013 at 11:00 AM, James Aimonetti <span dir="ltr"><<a href="mailto:james@2600hz.com" target="_blank">james@2600hz.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA256<br>
<div class="im"><br>
On 07/29/2013 07:53 PM, Barco You wrote:<br>
> Dear Forks,<br>
><br>
> I have a supervisor who will start children with<br>
> simple_one_for_one strategy. First of all I have server process who<br>
> starts the mentioned supervisor by using {ok, Pid} =<br>
> supervisor:start_child(Supsup, ?SPEC), and then I add the children<br>
> under the mentioned supervisor one by one also with<br>
> supervisor:start_child(Pid, Args), but only the first child can be<br>
> started and the rest children just got "process already started"<br>
> error message. What's wrong I made? the snippets of the codes as<br>
> following:<br>
><br>
> -module(spider_sup). -behaviour(supervisor).<br>
><br>
> -export([start_link/0]). %% API. -export([init/1]). %% supervisor.<br>
><br>
> -define(SUPERVISOR, ?MODULE).<br>
><br>
> %% API.<br>
><br>
> start_link() -> supervisor:start_link({local, ?SUPERVISOR},<br>
> ?MODULE, []).<br>
><br>
> %% supervisor.<br>
><br>
> init([]) -> MaxRestart = 5, MaxTime = 60, {ok,<br>
> {{simple_one_for_one, MaxRestart, MaxTime}, [{spider, {spider,<br>
> start_link, []}, permanent, 120, worker, [spider]}]}}.<br>
> ----------------------------------------------------------------------------------------------------------<br>
><br>
><br>
</div>- -module(spider).<br>
<div class="im">><br>
> -behavior(gen_fsm).<br>
><br>
> -export([start_link/1]).<br>
><br>
> -export([init/1, event1/2, handle_event/3, handle_sync_event/4,<br>
> code_change/4, terminate/3, handle_info/3]).<br>
><br>
> start_link(Code) -> gen_fsm:start_link({local, ?MODULE}, ?MODULE,<br>
> Code, []).<br>
><br>
> init(Code) -> io:format("~p Starting~n",[Code]), {ok, event1, Code,<br>
> 10000}.<br>
> ---------------------------------------------------------------------------------------------------<br>
><br>
><br>
%snippet from the server process<br>
> start_spiders(_Pid, []) -> ok; start_spiders(Pid, [HCode | TCode])<br>
> -> supervisor:start_child(Pid, [HCode]), start_spiders(Pid,<br>
> TCode).<br>
><br>
><br>
><br>
</div>> _______________________________________________ erlang-questions<br>
> mailing list <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
<br>
It appears your gen_fsm is registering itself as a named process. So<br>
the first succeeds because the name isn't registered; subsequent<br>
attempts will not start additional children as the name is no longer<br>
available. Try using gen_fsm:start_link/3 [0] instead.<br>
<br>
[0]<br>
<a href="http://erldocs.com/R15B/stdlib/gen_fsm.html?i=2&search=gen_fsm%20start#start_link/3" target="_blank">http://erldocs.com/R15B/stdlib/gen_fsm.html?i=2&search=gen_fsm%20start#start_link/3</a><br>
<br>
- --<br>
James Aimonetti<br>
Distributed Systems Engineer / DJ MC_<br>
<br>
2600hz | <a href="http://2600hz.com" target="_blank">http://2600hz.com</a><br>
<a href="mailto:sip%3Ajames@2600hz.com">sip:james@2600hz.com</a><br>
tel: 415.886.7905<br>
-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.11 (GNU/Linux)<br>
Comment: Using GnuPG with Thunderbird - <a href="http://www.enigmail.net/" target="_blank">http://www.enigmail.net/</a><br>
<br>
iF4EAREIAAYFAlH3LE8ACgkQ54NxaUq7OmBHqwD/Vu+If3oUpqgmHlooOW6ZwZ3z<br>
34YJKrncaBJDOxRINloBAIx25ZL3migY3y29jZ8hS4Oho4NY1n4uwjDCe8QFeu8k<br>
=u5w5<br>
-----END PGP SIGNATURE-----<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br></div>