Elixir - Get All PIDs for Supervised Processes

I have a Supervisor and you want to know all the processes running under this Supervisor at any given time. There seems to be an easy way to get all the PIDs, names, etc. For all processes under the supervisor or in node, but I can not find anything.

Any suggestions on how to do this?

+5
source share
1 answer

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]}] 

This function returns a list of tuples containing:

id - as defined in the specification of the child or: undefined in case of simple_user_user

child - pid of the corresponding child process, atom: restart if the process should be restarted, or: undefined if there is no such process

type -: worker or: supervisor, as defined in the specification of the child

- as defined in the child specification

Since type and pid provided, you can recursively extract child elements to create a list of all pids, if necessary.

+10
source

Source: https://habr.com/ru/post/1245243/


All Articles