Skip to content

Instantly share code, notes, and snippets.

@binarytemple
Last active June 23, 2025 18:22

Revisions

  1. Bryan Hunt revised this gist May 24, 2016. 1 changed file with 17 additions and 2 deletions.
    19 changes: 17 additions & 2 deletions elixir.diagnostics.markdown
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,6 @@ Inspired by [Stuff Goes Bad - Erlang in Anger](https://www.erlang-in-anger.com)

    >>Is the global process count indicative of a leak? If so, you may need to investigate unlinked processes, or peek inside supervisors’ children lists to see what may be weird-looking.
    This implementation needs to be simplified:

    ```elixir

    defmodule Diags do
    @@ -27,6 +25,16 @@ defmodule Diags do
    _ -> false
    end)
    end

    @doc """
    Simplified version of the above function
    """
    def list_non_linked_non_monitored_processes_simplified do
    for pid <- Process.list,
    pi <- [ Process.info(pid, [:links,:monitors,:registered_name]) ],
    [links: [], monitors: [], registered_name: registered_name ] <- [pi],
    do: {pid, registered_name}
    end
    end
    ```

    @@ -46,3 +54,10 @@ iex(157)> Diags.list_non_linked_non_monitored_processes
    [{#PID<0.130.0>, [], [], []}, {#PID<0.1029.0>, [], [], []},
    {#PID<0.1031.0>, [], [], []}]
    ```

    Update - simplified the original function `list_non_linked_non_monitored_processes/0`

    ```
    iex(190)> Diags.list_non_linked_non_monitored_processes
    [{#PID<0.130.0>, []}, {#PID<0.1029.0>, []}, {#PID<0.1031.0>, []}]
    ```
  2. Bryan Hunt revised this gist May 24, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions elixir.diagnostics.markdown
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@

    Inspired by [Stuff Goes Bad - Erlang in Anger](https://www.erlang-in-anger.com)

    >>Is the global process count indicative of a leak? If so, you may need to investigate unlinked processes, or peek inside supervisors’ children lists to see what may be weird-looking.
    This implementation needs to be simplified:

    ```elixir

  3. Bryan Hunt revised this gist May 24, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions elixir.diagnostics.markdown
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@

    Inspired by [Stuff Goes Bad - Erlang in Anger](https://www.erlang-in-anger.com)


    ```elixir

    defmodule Diags do
  4. Bryan Hunt revised this gist May 24, 2016. 2 changed files with 42 additions and 21 deletions.
    21 changes: 0 additions & 21 deletions diagnostics.ex
    Original file line number Diff line number Diff line change
    @@ -1,21 +0,0 @@
    defmodule Diags do

    @doc """
    Generate a list of all processes in the system which are neither linked nor monitored.
    """
    def list_non_linked_non_monitored_processes do
    Process.list |>
    Enum.map( fn pid -> {pid, Process.info( pid, [:links,:monitors,:registered_name])} end) |>
    Enum.map(
    fn {pid, words} -> {pid,
    Keyword.get(words,:links),
    Keyword.get(words,:monitors),
    Keyword.get(words,:registered_name)
    }
    end ) |>
    Enum.filter(fn
    {_,[],[],_} -> true
    _ -> false
    end)
    end
    end
    42 changes: 42 additions & 0 deletions elixir.diagnostics.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@

    ```elixir

    defmodule Diags do

    @doc """
    Generate a list of all processes in the system which are neither linked nor monitored.
    """
    def list_non_linked_non_monitored_processes do
    Process.list |>
    Enum.map( fn pid -> {pid, Process.info( pid, [:links,:monitors,:registered_name])} end) |>
    Enum.map(
    fn {pid, words} -> {pid,
    Keyword.get(words,:links),
    Keyword.get(words,:monitors),
    Keyword.get(words,:registered_name)
    }
    end ) |>
    Enum.filter(fn
    {_,[],[],_} -> true
    _ -> false
    end)
    end
    end
    ```

    ```
    iex(153)> idler = fn -> receive do x -> IO.puts("#{inspect x}") end end
    #Function<20.50752066/0 in :erl_eval.expr/5>
    iex(154)> Diags.list_non_linked_non_monitored_processes
    [{#PID<0.130.0>, [], [], []}]
    iex(155)> spawn(idler)
    #PID<0.1029.0>
    iex(156)> spawn(idler)
    #PID<0.1031.0>
    iex(157)> Diags.list_non_linked_non_monitored_processes
    [{#PID<0.130.0>, [], [], []}, {#PID<0.1029.0>, [], [], []},
    {#PID<0.1031.0>, [], [], []}]
    ```
  5. Bryan Hunt revised this gist May 24, 2016. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions diagnostics.ex
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@ defmodule Diags do
    Generate a list of all processes in the system which are neither linked nor monitored.
    """
    def list_non_linked_non_monitored_processes do

    Process.list |>
    Enum.map( fn pid -> {pid, Process.info( pid, [:links,:monitors,:registered_name])} end) |>
    Enum.map(
    @@ -15,8 +14,8 @@ defmodule Diags do
    }
    end ) |>
    Enum.filter(fn
    {_,nil,nil_} -> true
    {_,links,monitors,_} -> false
    {_,[],[],_} -> true
    _ -> false
    end)
    end
    end
  6. Bryan Hunt created this gist May 24, 2016.
    22 changes: 22 additions & 0 deletions diagnostics.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    defmodule Diags do

    @doc """
    Generate a list of all processes in the system which are neither linked nor monitored.
    """
    def list_non_linked_non_monitored_processes do

    Process.list |>
    Enum.map( fn pid -> {pid, Process.info( pid, [:links,:monitors,:registered_name])} end) |>
    Enum.map(
    fn {pid, words} -> {pid,
    Keyword.get(words,:links),
    Keyword.get(words,:monitors),
    Keyword.get(words,:registered_name)
    }
    end ) |>
    Enum.filter(fn
    {_,nil,nil_} -> true
    {_,links,monitors,_} -> false
    end)
    end
    end