Hi Chris,<br><br>We do something like this in our application.<br><br>First, in our "static" supervision tree we start a dynamic supervisor:<br><br><br>init(Args) -><br> {ok, {<br> {one_for_one, 5, 5}, <br>
[ <br> {dynamic_supervisor_id,<br> {dynamic_supervisor, start_link, [Args]},<br> permanent, <br> infinity, <br> supervisor, <br> [dynamic_supervisor]},<br>
<br><br>Where the dynamic_supervisor module has the functions:<br><br><br>start_link(Args) -><br> supervisor:start_link({local,?MODULE}, ?MODULE, [Args]).<br><br>init(_Args) -><br> {ok, {<br> {one_for_one, 5, 5}, <br>
[]<br> }}.<br><br><br><br>Then in our code we can dynamically start supervised processes with registered names, ProcName:<br><br><br>supervisor:start_child(dynamic_supervisor,<br> {ProcName,<br>
{gen_server, start_link,<br> [{local, ProcName}, ?MODULE, [StartArgs], []]},<br> permanent,<br> 10000,<br> worker,<br> [?MODULE]<br>
})<br><br><br>And shut them down with:<br><br><br>supervisor:terminate_child(dynamic_supervisor,PName),<br>supervisor:delete_child(dynamic_supervisor,PName),<br><br><br><br>This is just a few clippings from our code base here with the names made more generic, so there might be a syntax error or two but I think it helps do what you want.<br>
<br>//Tom.<br><br><br><br><br><div class="gmail_quote">On Thu, Sep 8, 2011 at 3:09 AM, Christopher Wilson <span dir="ltr"><<a href="mailto:wilsoncj1@gmail.com">wilsoncj1@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Is there a way to pass a name/ID into the call to supervisor:start_child, more specifically to init()? I'd like to specify the name of the worker or supervisor such that when I ran supervisor:which_children I could identify what's what.<div>
<br></div><div>Also, I've tried [unsuccessfully] to dynamically create a child spec and add pass that in. Are there any decent examples out there on how to do this outside of the man pages?</div><div><br></div><div>
Thank you.</div>
<div><br></div><div>-Chris </div>
<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>
<br></blockquote></div><br>