tags:

views:

163

answers:

1

Is there a direct way to retrieve the registered name associated with a pid() ? Or do I have to go through the registered() names and do a whereis() on each element of the list to find it?

+4  A: 

Check out erlang:process_info/2 and this ItemSpec:

{registered_name, Atom}

Atom is the registered name of the process. If the process has no registered name, this tuple is not present in the list.

PS. Why do you want this reverse mapping? Is it just for interactive debugging?

Christian
@Christian: I have a "message bus" where I keep track of the "subscribers". I do this via their "registered name" so when a server restarts (new pid()), I don't loose all its config -> lower down-time
jldupont