<p>I have a process in erlang that is supposed to do something immediately after spawn, then send the result back to the parent when it is finished.  How do I figure out the PID of the process that spawned it?</p>

[{'answer_id': 4304, 'author': 'Lily Ballard', 'author_id': 582, 'author_profile': 'https://Stackoverflow.com/users/582', 'pm_score': 5, 'selected': True, 'text': '<p>You should pass self() to the child as one of the arguments to the entry function.</p>\n\n<pre><code>spawn_link(?MODULE, child, [self()]).\n</code></pre>\n'}, {'answer_id': 4374, 'author': 'Greg Case', 'author_id': 462, 'author_profile': 'https://Stackoverflow.com/users/462', 'pm_score': 0, 'selected': False, 'text': '<p>You can use the BIF register to give the spawning / parent process a name (an atom) then refer back to the registered name from other processes.</p>\n\n<blockquote>\n  <p>FUNC() -></p>\n  \n  <blockquote>\n    <p>%% Do something<br>\n    %% Then send message to parent<br>\n    parent ! MESSAGE.</p>\n  </blockquote>\n  \n  <p>...</p>\n  \n  <p>register(parent, self()),<br>\n  spawn(MODULE, FUNC, [ARGS]).</p>\n</blockquote>\n\n<p>See <a href="http://www.erlang.org/doc/getting_started/conc_prog.html#3.3" rel="nofollow noreferrer">Getting Started With Erlang §3.3</a> and <a href="http://www.erlang.org/doc/reference_manual/processes.html#10.3" rel="nofollow noreferrer">The Erlang Reference Manual §10.3</a>.</p>\n'}, {'answer_id': 73002, 'author': 'user12462', 'author_id': 12462, 'author_profile': 'https://Stackoverflow.com/users/12462', 'pm_score': 2, 'selected': False, 'text': "<p>@Eridius' answer is the preferred way to do it. Requiring a process to register a name may have unintended side-effects such as increasing the visibility of the process not to mention the hassle of coming up with unique names when you have lots of processes.</p>\n"}, {'answer_id': 1261457, 'author': 'rvirding', 'author_id': 77617, 'author_profile': 'https://Stackoverflow.com/users/77617', 'pm_score': 2, 'selected': False, 'text': "<p>The best way is definitely to pass it as an argument to the function called to start the child process. If you are spawning funs, which generally is a Good Thing to do, be careful of doing:</p>\n\n<pre><code>spawn_link(fun () -&gt; child(self()) end)\n</code></pre>\n\n<p>which will NOT do as you intended. (Hint: when is self() called)</p>\n\n<p>Generally you should avoid registering a process, i.e. giving it a global name, unless you really want it to be globally known. Spawning a fun means that you don't have to export the spawned function as you should generally avoid exporting functions that aren't meant to be called from other modules.</p>\n"}]
['https://Stackoverflow.com/questions/4287', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/121/']