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