I have a Supervisor and want to know all the processes running under that Supervisor at any given time. It seems like there should be an easy way to get all PIDs, names, etc. for all processes under a Supervisor or in a node, but I can't find anything.
Any suggestions for how to do this?
You can use Supervisor.which_children/1:
iex> Supervisor.which_children(MyApp.Supervisor)
[{MyApp.SubSupervisor, #PID<0.1695.0>, :supervisor, [MyApp.SubSupervisor]},
{MyApp.Endpoint, #PID<0.1686.0>, :supervisor, [MyApp.Endpoint]}]
Returns a list with information about all children of the given supervisor.
Note that calling this function when supervising a large number of children under low memory conditions can cause an out of memory exception.
This function returns a list of
{id, child, type, modules}
tuples, where:
id
- as defined in the child specification
child
- the PID of the corresponding child process,:restarting
if the process is about to be restarted, or:undefined
if there is no such process
type
-:worker
or:supervisor
, as specified by the child specification
modules
- as specified by the child specification
Since the type
and pid
are provided you can recursively fetch the children to generate a list of all the pids if required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With