얼랑에서 나는 서로 연결된 두 개의 프로세스를 생성 중이다. 양식 하나의 프로세스를 종료하면 다른 프로세스는 정상적으로 종료되면이를 무시합니다. 이 문제는 a link에 설명되어 있습니다.얼랑 프로세스 : 링크 된 프로세스에 의해 무시 된 정상적인 종료, "두 번 컴파일"후에 종료
내 질문은 동일한 코드를 두 번 컴파일하면 두 번째 프로세스도 종료됨을 알 수 있습니다. 여기 내 예제 코드입니다 :
-module(exitnormal).
-export([f1/0]).
f1() ->
X = whereis(f2) =/= undefined,
if
X -> exit(whereis(f2), shutdown), timer:sleep(1);
true -> ""
end,
register(f2, spawn_link(fun() -> f2() end)),
receive
kill -> { ok, f1 }
end.
f2() ->
receive
kill -> { ok, f2 }
end.
나는 다음과 같은 결과를 실행 :
얼랭 참조 설명서의 the Compilation and Code Loading section에서 설명한 바와 같이1> c(exitnormal).
{ok,exitnormal}
2> erlang:register(f1, spawn(exitnormal, f1, [])).
true
3> whereis(f2) ! kill, ok.
ok
4> whereis(f2).
undefined
5> whereis(f1).
<0.40.0>
6> c(exitnormal).
{ok,exitnormal}
7> whereis(f1).
<0.40.0>
8> c(exitnormal).
{ok,exitnormal}
9> whereis(f1).
undefined
10> erlang:register(f1, spawn(exitnormal, f1, [])).
true
11> whereis(f1) ! kill, ok.
ok
12> whereis(f1).
undefined
13> whereis(f2).
<0.59.0>
14> c(exitnormal).
{ok,exitnormal}
15> c(exitnormal).
{ok,exitnormal}
16> whereis(f2).
undefined
17>
변종은 컴파일하기 전에 코드에서 변경 사항을 찾지 않습니다 (추측). 그래서 프로세스의 종료를 설명합니다. 나 맞아. –
네, 맞습니다. – legoscia