Skip to content

Instantly share code, notes, and snippets.

@elbrujohalcon
Created June 19, 2012 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbrujohalcon/2954398 to your computer and use it in GitHub Desktop.
Save elbrujohalcon/2954398 to your computer and use it in GitHub Desktop.
Linked processes in Erlang… when do they die?
20> P1 = spawn(fun() -> receive stop -> io:format("P1 ended~n") end end).
<0.61.0>
21> P2 = spawn(fun() -> link(P1), receive stop -> io:format("P2 ended~n") end end).
<0.63.0>
22> {erlang:is_process_alive(P1), erlang:is_process_alive(P2)}.
{true,true}
23> P1 ! stop.
P1 ended
stop
24> {erlang:is_process_alive(P1), erlang:is_process_alive(P2)}.
{false,true}
25> P2 ! stop.
P2 ended
stop
26> f().
ok
27> P1 = spawn(fun() -> receive stop -> io:format("P1 ended~n") end end).
<0.70.0>
28> P2 = spawn(fun() -> link(P1), receive stop -> io:format("P2 ended~n") end end).
<0.72.0>
29> {erlang:is_process_alive(P1), erlang:is_process_alive(P2)}.
{true,true}
30> exit(P1, kill).
true
31> {erlang:is_process_alive(P1), erlang:is_process_alive(P2)}.
{false,false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment