Say I'm working with some simple processes in erl:

1> Fun = fun(F) -> F(F) end.
#Fun<erl_eval.6.82930912>
2> Pid = spawn(fun() -> Fun(Fun) end).
<0.178.0>
3> f(Pid).

What happens when I do f(Pid).? Does the process exit or do I just lose my reference to it?

有帮助吗?

解决方案

According to documentation f(Pid) removes the binding of variable Pid, the process is not stopped.

You can test it in this way: suppose you have a gen_server called myserver which is based on the skeleton provided by emacs erlang mode.

1> {ok, Pid} = myserver:start_link().
{ok,<0.39.0>}
2> f(Pid).
ok
3> gen_server:call(pid(0,39,0), mycall).
ok
4> gen_server:call(myserver, mycall).
ok

As you can see even though we did f(Pid) we can still contact the process using its pid or the atom used during registration (in our case the module name).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top