Skip to content

Instantly share code, notes, and snippets.

@kevsmith
Created December 10, 2012 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevsmith/4253279 to your computer and use it in GitHub Desktop.
Save kevsmith/4253279 to your computer and use it in GitHub Desktop.
Find all processes executing code from a given module
12> F = fun(P, {current_function, {Mod, _, _}}) -> {P, Mod} end,
12> C = fun(Mod, Prefixes) -> lists:sum([string:str(Mod, Prefix) || Prefix <- Prefixes]) > 0 end,
12> Target = fun(Prefixes) -> Candidates = [F(P, erlang:process_info(P, current_function)) || P <- erlang:processes()],
12> [{Pid, Mod} || {Pid, Mod} <- Candidates,
12> C(atom_to_list(Mod), Prefixes)] end.
#Fun<erl_eval.6.82930912>
13> Target(["erl"]).
[{<0.3.0>,erl_prim_loader},{<0.33.0>,erl_eval}]
14>
F = fun(P, {current_function, {Mod, _, _}}) -> {P, Mod} end,
C = fun(Mod, Prefixes) -> lists:sum([string:str(Mod, Prefix) || Prefix <- Prefixes]) > 0 end,
Target = fun(Prefixes) -> Candidates = [F(P, erlang:process_info(P, current_function)) || P <- erlang:processes()],
[{Pid, Mod} || {Pid, Mod} <- Candidates,
C(atom_to_list(Mod), Prefixes)] end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment