<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7233.28">
<TITLE>how to use supervisor:start_child?</TITLE>
</HEAD>
<BODY>
<DIV id=idOWAReplyText550 dir=ltr>
<DIV dir=ltr><FONT face="Courier New" color=#000000 size=2>Hi
Dietmar,</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>first it is normally not necessary
to register the supervisor</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>your self in the init function.
That is taken care of providing</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>the supervisor:start_link function
with the SupName </FONT><FONT face="Courier New" size=2>parameter.</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2></FONT> </DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>Second, critisism against cryptic
error return-values are</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>many times well in place. Here
however I believe the return-value</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>you experience, invalid_child_spec,
to be very accurate.</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2></FONT> </DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>If you look in the documentation
for supervisor:</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2></FONT> </DIV>
<DIV dir=ltr><FONT face="Courier New" size=2><A
href="http://www.erlang.se/doc/doc-5.4.12/lib/stdlib-1.13.11/doc/html/index.html">http://www.erlang.se/doc/doc-5.4.12/lib/stdlib-1.13.11/doc/html/index.html</A></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2></FONT> </DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>you will find that ChildSpec shall
be a child_spec() and not a list</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>of child_spec(), as is required in
the childrenspecification of a</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>supervisor init return-value. This
from the logical point that you</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>are not starting an arbritray
amount of children but just one.</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2></FONT> </DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>Good luck and happy
hacking,</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>/Lennart</FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" color=#000000 size=2></FONT> </DIV>
<DIV dir=ltr><FONT face="Courier New" size=2>
<P><A name=start_child/2><STRONG><CODE><FONT face=Verdana
size=3>start_child(SupRef, ChildSpec) ->
Result</FONT></CODE></STRONG></A><BR>
<DIV class=REFBODY>
<P><FONT face=Verdana size=3>Types: </FONT>
<DIV class=REFTYPES>
<P><FONT face=Verdana><FONT size=3><STRONG><CODE>SupRef = Name | {Name,Node} |
{global,Name} | pid()</CODE></STRONG><BR><STRONG><CODE> Name = Node =
atom()</CODE></STRONG><BR><STRONG><CODE>ChildSpec = child_spec() |
[term()]</CODE></STRONG><BR><STRONG><CODE>Result = {ok,Child} | {ok,Child,Info}
| {error,Error}</CODE></STRONG><BR><STRONG><CODE> Child = pid() |
undefined</CODE></STRONG><BR><STRONG><CODE> Info =
term()</CODE></STRONG><BR><STRONG><CODE> Error = already_present |
{already_started,Child} |
term()</CODE></STRONG><BR></FONT></FONT></P></DIV></DIV>
<DIV class=REFBODY>
<P><FONT face=Verdana size=3>Dynamically adds a child specification to the
supervisor <CODE>SupRef</CODE> which starts the corresponding child process.
</FONT>
<P><FONT face=Verdana><FONT size=3><CODE>SupRef</CODE> can be: </FONT></FONT>
<P><FONT face=Verdana size=3></FONT>
<UL>
<LI><FONT face=Verdana size=3>the pid, </FONT>
<LI><FONT face=Verdana><FONT size=3><CODE>Name</CODE>, if the supervisor is
locally registered, </FONT></FONT>
<LI><FONT face=Verdana><FONT size=3><CODE>{Name,Node}</CODE>, if the
supervisor is locally registered at another node, or </FONT></FONT>
<LI><FONT face=Verdana><FONT size=3><CODE>{global,Name}</CODE>, if the
supervisor is globally registered. </FONT></FONT></LI></UL>
<P><FONT face=Verdana><FONT size=3><CODE>ChildSpec</CODE> should be a valid
child specification (unless the supervisor is a <CODE>simple_one_for_one</CODE>
supervisor, see below). The child process will be started by using the start
function as defined in the child specification.
</FONT></FONT></P></DIV></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2></FONT> </DIV>
<DIV dir=ltr><FONT face="Courier New" size=2></FONT> </DIV></DIV>
<DIV id=idSignature71618 dir=ltr>
<DIV><FONT face="Courier New" color=#000000
size=2>-------------------------------------------------------------</FONT></DIV>
<DIV><FONT face="Courier New" color=#000000 size=2>Lennart
Ohman
phone : +46-8-587 623 27</FONT></DIV>
<DIV><FONT face="Courier New" size=2>Sjöland & Thyselius Telecom
AB cellular: +46-70-552 6735</FONT></DIV>
<DIV><FONT face="Courier New" size=2>Sehlstedtsgatan
6
fax : +46-8-667 8230</FONT></DIV>
<DIV><FONT face="Courier New" size=2>SE-115 28 STOCKHOLM,
SWEDEN email : <A
href="mailto:lennart.ohman@st.se">lennart.ohman@st.se</A></FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>Från:</B> owner-erlang-questions@erlang.org genom
Dietmar Schaefer<BR><B>Skickat:</B> ti 2006-01-10 12:36<BR><B>Till:</B> Erlang
Questions<BR><B>Ämne:</B> how to use
supervisor:start_child?<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2>Hi !<BR><BR>I can't get this to work !<BR><BR><BR><BR>I have a
supervisor:<BR><BR>init([]) -><BR><BR> case
whereis(sup) of<BR> undefined
->
%% register only once<BR> register(sup,
self());<BR> _ -> ok<BR> end,<BR><BR>with
a few ChildSpec:<BR> AChild =
{xclock,{xclock,start_link,[]},<BR>
permanent,2000,worker,[xclock]},<BR><BR> StopChild =
{stop_wrp,{stop_wrp,start_link,[]},<BR>
permanent,2000,worker,[stop_wrp]},<BR><BR> SimpleSup =
{dynamic, {dynamic, start_link,
[]},<BR> transient, 2000, worker,
[dynamic]},<BR> <BR><BR> {ok,{{one_for_one,1,1},
[StopChild]}}.<BR><BR><BR>I I try to
start_child<BR><BR>supervisor:start_child(sup,[{dynamic, {dynamic,
start_link,<BR>[]},transient, 2000, worker, [dynamic]}]).<BR><BR>I
get<BR><BR>{error,{invalid_child_spec,[{dynamic,{dynamic,start_link,[]},<BR>
transient,<BR>
2000,<BR>
worker,<BR>
[dynamic]}]}}<BR><BR>How can this be?<BR>( it should be valid because I can use
it in the return value of<BR>supervisor:init)<BR>ok,{{one_for_one,1,1},
[SimpeSup]}}.<BR><BR><BR>Please give me a hint
!<BR><BR><BR><BR>regards<BR><BR><BR>Dietmar<BR><BR><BR></FONT></P></DIV>
</BODY>
</HTML>