[erlang-questions] How to find Pids of the children of a supervisor

Pierre Fenoll pierrefenoll@REDACTED
Thu Dec 7 15:34:00 CET 2017


> supervisor:which_children/1
> Is the the best way? - does anybody have an example?

That and using erlang:process_info(Pid, links) are the only ways.

The supervisor module lacks a child(SupRef, Name) function that would now
be able to fetch children by Name
with a complexity better than O(n) now that the module can use maps.
I started writing a PR for that but then got confused by the code that can
either use sets or maps: I couldn't understand which backend would be used
when...

My use case is to not register names for child processes (using
erlang:register via {local,Name}).



Cheers,
-- 
Pierre Fenoll


On 7 December 2017 at 14:26, Vance Shipley <vances@REDACTED> wrote:

> On Thu, Dec 7, 2017 at 6:03 PM, Joe Armstrong <erlang@REDACTED> wrote:
> > I was asked the following in a direct mail to me:
> >
> > "Given two worker processes in a supervision tree, A and B, if A wants
> > to message B, how should it obtain the pid of B ?"
> >
> > Pretty good question.
> >
> > I think the answer is to use supervisor:which_children/1 and to name
> > the supervisor and all the children.
> >
> > Is the the best way? - does anybody have an example?
>
> Sure, I don't bother to name the supervisor though, pass the pid() down:
>
> Here's an example of a gen_server which locates it's sibling
> simple_one_for_one supervisors after initializing:
> https://github.com/sigscale/ocs/blob/8aafd48fd876b7434517b512d79d2c
> 12559889bb/src/ocs_radius_auth_port_server.erl#L157
>
>
>
> --
>      -Vance
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171207/ebb90cb6/attachment.htm>


More information about the erlang-questions mailing list