3.8 Pid

A process identifier, pid, identifies a process.

The following BIFs, which are used to create processes, return values of this data type:

  • spawn/1,2,3,4
  • spawn_link/1,2,3,4
  • spawn_opt/4Example:
  1. 1> spawn(m, f, []).
  2. <0.51.0>

In the following example, the BIF self() returns the pid of the calling process:

  1. -module(m).
  2. -export([loop/0]).
  3.  
  4. loop() ->
  5. receive
  6. who_are_you ->
  7. io:format("I am ~p~n", [self()]),
  8. loop()
  9. end.
  10.  
  11. 1> P = spawn(m, loop, []).
  12. <0.58.0>
  13. 2> P ! who_are_you.
  14. I am <0.58.0>
  15. who_are_you

Read more about processes in Processes.