SV: how to use supervisor:start_child?

Lennart Öhman <>
Tue Jan 10 14:18:04 CET 2006


Hi Dietmar,
first it is normally not necessary to register the supervisor
your self in the init function. That is taken care of providing
the supervisor:start_link function with the SupName parameter.
 
Second, critisism against cryptic error return-values are
many times well in place. Here however I believe the return-value
you experience, invalid_child_spec, to be very accurate.
 
If you look in the documentation for supervisor:
 
http://www.erlang.se/doc/doc-5.4.12/lib/stdlib-1.13.11/doc/html/index.html
 
you will find that ChildSpec shall be a child_spec() and not a list
of child_spec(), as is required in the childrenspecification of a
supervisor init return-value. This from the logical point that you
are not starting an arbritray amount of children but just one.
 
Good luck and happy hacking,
/Lennart
 
start_child(SupRef, ChildSpec) -> Result


Types: 

SupRef = Name | {Name,Node} | {global,Name} | pid()
 Name = Node = atom()
ChildSpec = child_spec() | [term()]
Result = {ok,Child} | {ok,Child,Info} | {error,Error}
 Child = pid() | undefined
 Info = term()
 Error = already_present | {already_started,Child} | term()


Dynamically adds a child specification to the supervisor SupRef which starts the corresponding child process. 

SupRef can be: 

*	the pid, 
*	Name, if the supervisor is locally registered, 
*	{Name,Node}, if the supervisor is locally registered at another node, or 
*	{global,Name}, if the supervisor is globally registered. 

ChildSpec should be a valid child specification (unless the supervisor is a simple_one_for_one supervisor, see below). The child process will be started by using the start function as defined in the child specification. 

 
 
-------------------------------------------------------------
Lennart Ohman                   phone   : +46-8-587 623 27
Sjöland & Thyselius Telecom AB  cellular: +46-70-552 6735
Sehlstedtsgatan 6               fax     : +46-8-667 8230
SE-115 28 STOCKHOLM, SWEDEN     email   : 

________________________________

Från:  genom Dietmar Schaefer
Skickat: ti 2006-01-10 12:36
Till: Erlang Questions
Ämne: how to use supervisor:start_child?



Hi !

I can't get this to work !



I have a supervisor:

init([]) ->

    case  whereis(sup) of
    undefined ->                    %% register only once
     register(sup, self());
    _ -> ok
    end,

with a few ChildSpec:
    AChild    = {xclock,{xclock,start_link,[]},
          permanent,2000,worker,[xclock]},

    StopChild = {stop_wrp,{stop_wrp,start_link,[]},
         permanent,2000,worker,[stop_wrp]},

    SimpleSup = {dynamic, {dynamic, start_link, []},
        transient, 2000, worker, [dynamic]},
  

    {ok,{{one_for_one,1,1}, [StopChild]}}.


I I try to start_child

supervisor:start_child(sup,[{dynamic, {dynamic, start_link,
[]},transient, 2000, worker, [dynamic]}]).

I get

{error,{invalid_child_spec,[{dynamic,{dynamic,start_link,[]},
                                     transient,
                                     2000,
                                     worker,
                                     [dynamic]}]}}

How can this be?
( it should be valid because I can use it in the return value of
supervisor:init)
ok,{{one_for_one,1,1}, [SimpeSup]}}.


Please give me a hint !



regards


Dietmar




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060110/6b3f0af3/attachment.html>


More information about the erlang-questions mailing list