[erlang-questions] How to get a supervisor to tell me a child's startfunc?
Torben Hoffmann
torben.lehoff@REDACTED
Mon Nov 2 21:43:02 CET 2009
Jim,
Since this seems to receive little attention and I kind of wanted to know
this too, I digged around a bit...
I have not tried this out with dynamically created children, but for
standard children something along the lines of:
supervisor:which_children(SupRef) to get the list of children of a
supervisor. The first element of the tuples in the list is the name of the
child.
sys:get_status(ChildName) will then give you details about the child.
Example:
1> application:start(sasl).
.... loads of things
2> supervisor:which_children(sasl_safe_sup).
[{overload,<0.41.0>,worker,[overload]},
{alarm_handler,<0.40.0>,worker,dynamic}]
3> sys:get_status(overload).
{status,<0.41.0>,
{module,gen_server},
[[{'$ancestors',[sasl_safe_sup,sasl_sup,<0.37.0>]},
{'$initial_call',{overload,init,1}}],
running,<0.39.0>,[],
[overload,
{state,0,0,0.8,5244,0.1,{0,0},clear},
overload,infinity]]}
The '$initial_call' tag seems to provide at least which function was called.
But it turns out that calling this on the supervisor is the solution!
11> sys:get_status(sasl_safe_sup).
{status,<0.39.0>,
{module,gen_server},
[[{'$ancestors',[sasl_sup,<0.37.0>]},
{'$initial_call',{supervisor,sasl,1}}],
running,<0.38.0>,[],
[sasl_safe_sup,
{state,{local,sasl_safe_sup},
one_for_one,
[{child,<0.41.0>,overload,
{overload,start_link,[]},
permanent,2000,worker,
[overload]},
{child,<0.40.0>,alarm_handler,
{alarm_handler,start_link,[]},
permanent,2000,worker,dynamic}],
{dict,0,16,16,8,80,48,{[],[],[],[],[],...},{{[],[],[],...}}},
4,3600,[],sasl,safe},
supervisor,infinity]]}
Fouth element of the child tagged tuples reveals how he children were
started.
Sorry about dragging you through the whole investigation, but I think it
holds some value... at least as to how I think ;-)
Cheers,
Torben
On Fri, Oct 30, 2009 at 17:45, Jim McCoy <jim.mccoy@REDACTED> wrote:
> I need to discover the startfunc being used by a variety of processes
> started dynamically by a supervisor and I am having a hard time
> figuring out how to dig this information out of the system. Process A
> starts a bunch of children for supervisor S over its lifetime, process
> B needs to do some maintenance or checking of which of these children
> are running at various points in time, to do this B needs to
> specifically know the start function that A used when it passed the
> child spec for any particular child process in to S. This information
> does not seem to be available directly from the supervisor, so I am
> guessing that there is some other place I need to look but my various
> search queries seem to be missing the magic keyword that will not lead
> me back to the standard supervisor docs...
>
> Any hints?
>
> Thanks,
> jim
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>
--
http://www.linkedin.com/in/torbenhoffmann
More information about the erlang-questions
mailing list