[erlang-questions] OTP Supervisor Question

Ulf Wiger <>
Mon Jan 4 13:35:01 CET 2010

Chandru wrote:
> 2010/1/4 Jayson Vantuyl <>
>> If I'm an OTP-style process (say, a gen_server), and I want to know who my
>> parent is (say, a supervisor), is this possible using any API, or do I need
>> to pass in the Parent explicitly?  Is using supervisor:get_child a good way
>> to find a process's sibling?  Would it be better to start a single
>> gen_server and have it use normal, linked processes?
> I think using supervisor:which_children(Sup_ref)  is quite reasonable. But
> for this, you'll have to store the process id of the supervisor in all the
> supervised processes.

The supervisor PID will be the head of get('$ancestors'), provided
the child is started using proc_lib (which is true for all OTP

Eshell V5.6.5  (abort with ^G)
1> proc_lib:spawn(fun() -> io:fwrite(">> ~p~n", [get()]) end).
2> self().
3> proc_lib:spawn(fun() -> io:fwrite(">> Parent is ~p~n", 
[hd(get('$ancestors'))]) end).
 >> Parent is <0.30.0>

This is not documented, but has been stable since the dawn of OTP,
and is unlikely to change anytime soon.

Of course, the proc_lib could export some of the helper functions,
such as get_ancestors/[0,1] or my_info/0...

Ulf W
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd



Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.


More information about the erlang-questions mailing list