5

It is possible to call link(pid) in Erlang to link the currently executing process to the process identified by pid. Is it possible to link a process to another if it is not currently executing?

John Cochran
  • 145
  • 1
  • 1
  • 5
  • 1
    What do you mean "not currently executing"? If the process **exists** then you can link to it, what ever its state and if it doesn't exist then you can't. As @P_A wrote using `spawn_link` you can create a new process and link to it. You can not link two **other** processes together, you can only link yourself to another process. – rvirding Sep 22 '15 at 12:04

2 Answers2

4

No, you cannot.

You can only link/unlink from a current process to another one. If the other process is not alive, you will get a noproc error (if you are trapping exits) or receive an exit signal (if you are not trapping exits or if the other process was on another node).

You can also use spawn_link to spawn and link in one atomic operation.

Adam Lindberg
  • 16,447
  • 6
  • 65
  • 85
-1

You can use spawn_link fun.

link is created between the calling process and the new process, atomically.

P_A
  • 1,804
  • 1
  • 19
  • 33