0

I create a supervisor that creates a child (e.g., process listening on a port). I want to pass the supervisor's PID SupPid to the child, so it can dynamically start other children with supervisor:start_child() (e.g., when the connection is received). How to get the supervisor's PID, from within the supervisor?

-module(the_supervisor)

start_link() ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).

init([]) ->
    SupPid = get_my_own_pid(), % <-- get pid of the supervisor and pass it later
    ChildSpec = ?CHILD_WITH_ARGS(some_children, worker, [SupPid]),
    {ok, {{one_for_one, 5, 10},
          [ChildSpec]} }.

Related

Community
  • 1
  • 1
Jakub M.
  • 32,471
  • 48
  • 110
  • 179

1 Answers1

3

This is the erlang:self() function.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487