<commit_before><?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2003</year><year>2013</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      The contents of this file are subject to the Erlang Public License,
      Version 1.1, (the "License"); you may not use this file except in
      compliance with the License. You should have received a copy of the
      Erlang Public License along with this software. If not, it can be
      retrieved online at http://www.erlang.org/.
    
      Software distributed under the License is distributed on an "AS IS"
      basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
      the License for the specific language governing rights and limitations
      under the License.
    
    </legalnotice>

    <title>Processes</title>
    <prepared></prepared>
    <docno></docno>
    <date></date>
    <rev></rev>
    <file>processes.xml</file>
  </header>

  <section>
    <title>Processes</title>
    <p>Erlang is designed for massive concurrency. Erlang processes are
      light-weight (grow and shrink dynamically) with small memory
      footprint, fast to create and terminate and the scheduling
      overhead is low.</p>
  </section>

  <section>
    <title>Process Creation</title>
    <p>A process is created by calling <c>spawn</c>:</p>
    <pre>
spawn(Module, Name, Args) -> pid()
  Module = Name = atom()
  Args = [Arg1,...,ArgN]
    ArgI = term()</pre>
    <p><c>spawn</c> creates a new process and returns the pid.</p>
    <p>The new process will start executing in
      <c>Module:Name(Arg1,...,ArgN)</c> where the arguments is
      the elements of the (possible empty) <c>Args</c> argument list.</p>
    <p>There exist a number of other <c>spawn</c> BIFs, for example
      <c>spawn/4</c> for spawning a process at another node.</p>
  </section>

  <section>
    <title>Registered Processes</title>
    <p>Besides addressing a process by using its pid, there are also
      BIFs for registering a process under a name. The name must be an
      atom and is automatically unregistered if the process terminates:</p>
    <table>
      <row>
        <cell align="left" valign="middle"><c>register(Name, Pid)</c></cell>
        <cell align="left" valign="middle">Associates the name <c>Name</c>, an atom, with the process <c>Pid</c>.</cell>
      </row>
      <row>
        <cell align="left" valign="middle"><c>registered()</c></cell>
        <cell align="left" valign="middle">Returns a list of names which have been registered using<c>register/2</c>.</cell>
      </row>
      <row>
        <cell align="left" valign="middle"><c>whereis(Name)</c></cell>
        <cell align="left" valign="middle">Returns the pid registered under <c>Name</c>, or<c>undefined</c>if the name is not registered.</cell>
      </row>
      <tcaption>Name Registration BIFs.</tcaption>
    </table>
  </section>

  <section>
    <marker id="term"></marker>
    <title>Process Termination</title>
    <p>When a process terminates, it always terminates with an
      <em>exit reason</em>. The reason may be any term.</p>
    <p>A process is said to terminate <em>normally</em>, if the exit
      reason is the atom <c>normal</c>. A process with no more code to
      execute terminates normally.</p>
    <p>A process terminates with exit reason <c>{Reason,Stack}</c>
      when a run-time error occurs. See
      <seealso marker="errors#exit_reasons">Error and Error Handling</seealso>.</p>
    <p>A process can terminate itself by calling one of the BIFs
      <c>exit(Reason)</c>, 
      <c>erlang:error(Reason)</c>, <c>erlang:error(Reason, Args)</c>,
      <c>erlang:fault(Reason)</c> or <c>erlang:fault(Reason, Args)</c>. 
      The process then terminates with reason <c>Reason</c> for
      <c>exit/1</c> or <c>{Reason,Stack} for the others</c>.</p>
    <p>A process may also be terminated if it receives an exit signal
      with another exit reason than <c>normal</c>, see
      <seealso marker="#errors">Error Handling</seealso> below.</p>
  </section>

  <section>
    <title>Message Sending</title>
    <p>Processes communicate by sending and receiving messages.
      Messages are sent by using
      the <seealso marker="expressions#send">send operator !</seealso>
      and received by calling
      <seealso marker="expressions#receive">receive</seealso>.</p>
    <p>Message sending is asynchronous and safe, the message is
      guaranteed to eventually reach the recipient, provided that
      the recipient exists.</p>
  </section>

  <section>
    <title>Links</title>
    <p>Two processes can be <em>linked</em> to each other. A link
      between two processes <c>Pid1</c> and <c>Pid2</c> is created
      by <c>Pid1</c> calling the BIF <c>link(Pid2)</c> (or vice versa).
      There also exists a number a <c>spawn_link</c> BIFs, which spawns
      and links to a process in one operation.</p>
    <p>Links are bidirectional and there can only be one link between
      two processes. Repeated calls to <c>link(Pid)</c> have no effect.</p>
    <p>A link can be removed by calling the BIF <c>unlink(Pid)</c>.</p>
    <p>Links are used to monitor the behaviour of other processes, see
      <seealso marker="#errors">Error Handling</seealso> below.</p>
  </section>

  <section><commit_msg>rephrase sentence in process links doc<commit_after><?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2003</year><year>2013</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      The contents of this file are subject to the Erlang Public License,
      Version 1.1, (the "License"); you may not use this file except in
      compliance with the License. You should have received a copy of the
      Erlang Public License along with this software. If not, it can be
      retrieved online at http://www.erlang.org/.
    
      Software distributed under the License is distributed on an "AS IS"
      basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
      the License for the specific language governing rights and limitations
      under the License.
    
    </legalnotice>

    <title>Processes</title>
    <prepared></prepared>
    <docno></docno>
    <date></date>
    <rev></rev>
    <file>processes.xml</file>
  </header>

  <section>
    <title>Processes</title>
    <p>Erlang is designed for massive concurrency. Erlang processes are
      light-weight (grow and shrink dynamically) with small memory
      footprint, fast to create and terminate and the scheduling
      overhead is low.</p>
  </section>

  <section>
    <title>Process Creation</title>
    <p>A process is created by calling <c>spawn</c>:</p>
    <pre>
spawn(Module, Name, Args) -> pid()
  Module = Name = atom()
  Args = [Arg1,...,ArgN]
    ArgI = term()</pre>
    <p><c>spawn</c> creates a new process and returns the pid.</p>
    <p>The new process will start executing in
      <c>Module:Name(Arg1,...,ArgN)</c> where the arguments is
      the elements of the (possible empty) <c>Args</c> argument list.</p>
    <p>There exist a number of other <c>spawn</c> BIFs, for example
      <c>spawn/4</c> for spawning a process at another node.</p>
  </section>

  <section>
    <title>Registered Processes</title>
    <p>Besides addressing a process by using its pid, there are also
      BIFs for registering a process under a name. The name must be an
      atom and is automatically unregistered if the process terminates:</p>
    <table>
      <row>
        <cell align="left" valign="middle"><c>register(Name, Pid)</c></cell>
        <cell align="left" valign="middle">Associates the name <c>Name</c>, an atom, with the process <c>Pid</c>.</cell>
      </row>
      <row>
        <cell align="left" valign="middle"><c>registered()</c></cell>
        <cell align="left" valign="middle">Returns a list of names which have been registered using<c>register/2</c>.</cell>
      </row>
      <row>
        <cell align="left" valign="middle"><c>whereis(Name)</c></cell>
        <cell align="left" valign="middle">Returns the pid registered under <c>Name</c>, or<c>undefined</c>if the name is not registered.</cell>
      </row>
      <tcaption>Name Registration BIFs.</tcaption>
    </table>
  </section>

  <section>
    <marker id="term"></marker>
    <title>Process Termination</title>
    <p>When a process terminates, it always terminates with an
      <em>exit reason</em>. The reason may be any term.</p>
    <p>A process is said to terminate <em>normally</em>, if the exit
      reason is the atom <c>normal</c>. A process with no more code to
      execute terminates normally.</p>
    <p>A process terminates with exit reason <c>{Reason,Stack}</c>
      when a run-time error occurs. See
      <seealso marker="errors#exit_reasons">Error and Error Handling</seealso>.</p>
    <p>A process can terminate itself by calling one of the BIFs
      <c>exit(Reason)</c>, 
      <c>erlang:error(Reason)</c>, <c>erlang:error(Reason, Args)</c>,
      <c>erlang:fault(Reason)</c> or <c>erlang:fault(Reason, Args)</c>. 
      The process then terminates with reason <c>Reason</c> for
      <c>exit/1</c> or <c>{Reason,Stack} for the others</c>.</p>
    <p>A process may also be terminated if it receives an exit signal
      with another exit reason than <c>normal</c>, see
      <seealso marker="#errors">Error Handling</seealso> below.</p>
  </section>

  <section>
    <title>Message Sending</title>
    <p>Processes communicate by sending and receiving messages.
      Messages are sent by using
      the <seealso marker="expressions#send">send operator !</seealso>
      and received by calling
      <seealso marker="expressions#receive">receive</seealso>.</p>
    <p>Message sending is asynchronous and safe, the message is
      guaranteed to eventually reach the recipient, provided that
      the recipient exists.</p>
  </section>

  <section>
    <title>Links</title>
    <p>Two processes can be <em>linked</em> to each other. A link
      between two processes <c>Pid1</c> and <c>Pid2</c> is created
      by <c>Pid1</c> calling the BIF <c>link(Pid2)</c> (or vice versa).
      There also exist a number of <c>spawn_link</c> BIFs, which spawn
      and link to a process in one operation.</p>
    <p>Links are bidirectional and there can only be one link between
      two processes. Repeated calls to <c>link(Pid)</c> have no effect.</p>
    <p>A link can be removed by calling the BIF <c>unlink(Pid)</c>.</p>
    <p>Links are used to monitor the behaviour of other processes, see
      <seealso marker="#errors">Error Handling</seealso> below.</p>
  </section>

  <section>
{'fraction_non_alphanumeric': 0.13080129689671144, 'fraction_numerical': 0.004075961093098657, 'mean_word_length': 3.184496124031008, 'pattern_counts': {'":': 0, '<': 387, '<?xml version=': 2, '>': 389, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '812030', 'n_tokens_mistral': 3361, 'n_tokens_neox': 3254, 'n_words': 1154}