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?
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.
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.
The Erlang BIF spawn is used to create a new process: spawn(Module, Exported_Function, List of Arguments).
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With