title: spawn_link not working?
body: <p>I'm using <code>spawn_link</code> but doesn't understand its behavior. Consider the following code:</p>
  
  <pre><code>-module(test).
  -export([try_spawn_link/0]).
  
  try_spawn_link() -&gt;
    spawn(fun() -&gt;
      io:format("parent: ~p~n", [Parent = self()]),
      Client = spawn_link(fun() -&gt;
        io:format("child: ~p~n", [self()]),
        spawn_link_loop(Parent)
      end),
      spawn_link_loop(Client)
    end).
  
  spawn_link_loop(Peer) -&gt;
    receive
      quit -&gt;
        exit(normal);
      Any -&gt;
        io:format("~p receives ~p~n", [self(), Any])
    end,
    spawn_link_loop(Peer).
  </code></pre>
  
  <p>From <a href="http://www.erlang.org/doc/man/erlang.html#spawn_link-1" rel="nofollow noreferrer">the Erlang documentation</a>, a link is created between the calling process and the new process, atomically. However, I tested as follows and didn't notice the effect of the link.</p>
  
  <pre><code>1&gt; test:try_spawn_link().
  parent: &lt;0.34.0&gt;
  &lt;0.34.0&gt;
  child: &lt;0.35.0&gt;
  2&gt; is_process_alive(pid(0,34,0)).
  true
  3&gt; is_process_alive(pid(0,35,0)).
  true
  4&gt; pid(0,35,0) ! quit.
  quit
  5&gt; is_process_alive(pid(0,35,0)).
  false
  6&gt; is_process_alive(pid(0,34,0)).
  true
  
  1&gt; test:try_spawn_link().
  parent: &lt;0.34.0&gt;
  &lt;0.34.0&gt;
  child: &lt;0.35.0&gt;
  2&gt; is_process_alive(pid(0,34,0)).
  true
  3&gt; is_process_alive(pid(0,35,0)).
  true
  4&gt; pid(0,34,0) ! quit.
  quit
  5&gt; is_process_alive(pid(0,35,0)).
  true
  6&gt; is_process_alive(pid(0,34,0)).
  false
  </code></pre>
  
  <p>In my understanding, if one peer of the link exits, the other peer exits (or is notified to exit). But the results seem different from my understanding.</p>
  
  <blockquote>
    <p><strong>EDIT:</strong> thanks to the answers of <a href="https://stackoverflow.com/a/13008203/940313">legoscia</a> and <a href="https://stackoverflow.com/a/13008199/940313">Pascal</a>.</p>
  </blockquote>