Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang: getting the "registered name" associated with a `pid`

Tags:

erlang

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?

like image 468
jldupont Avatar asked Dec 18 '09 15:12

jldupont


People also ask

What is PID in Erlang?

Every process in Erlang is identified by a unique process identifier (pid). The function self/0 returns the process identifier of the running process. Erlang processes can be created with any of the following functions: spawn, spawn link, spawn monitor, spawn opt, etc.

What is Erlang processes?

Erlang processes are lightweight, operate in (memory) isolation from other processes, and are scheduled by Erlang's Virtual Machine (VM). The creation time of process is very low, the memory footprint of a just spawned process is very small, and a single Erlang VM can have millions of processes running.

Which module is used to spawn processes manually in Erlang?

The Erlang BIF spawn is used to create a new process: spawn(Module, Exported_Function, List of Arguments).

What does spawn do in Erlang?

spawn() creates a new process and returns the pid. The new process starts executing in Module:Name(Arg1,...,ArgN) where the arguments are the elements of the (possible empty) Args argument list. There exist a number of different spawn BIFs: spawn/1,2,3,4.


1 Answers

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?

like image 113
Christian Avatar answered Oct 20 '22 09:10

Christian