<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> There are a couple of ways to achieve this, though not directly the way you describe. You would not pass in the Pid into the supervision spec, because the Pid can change any time a process restarts. Instead, you need to register the Pid to a name, and use the name.<br><br> As a quick aside, it sounds like the second process is dependent on the first process being up. With that in mind, you'll likely want a rest_for_one supervision strategy, with the first process being the first in the child spec list. <br><br> To your question, most gen_server examples actually are set up to do this for you, and you don't generally need the Pid, but if you're not using a gen_server you can manually use erlang:register/2, and erlang:whereis/1 to register the Pid to an atom, and to look up the Pid, as appropriate. <br><br><br> That is, I can do something like the following for my first process (ellipsis are indicative of 'assume the proper arguments; not relevant to the answer at hand') -<br><br>start_link() -></div><div> gen_server:start_link({local, NameToRegisterItAs}, ...).<br><br>or if not using a gen_server,<br><br>start_link() -><br> Pid = spawn_link(...),<br> true = register(NameToRegisterItAs, Pid),</div><div> Pid.<br><br><br><br></div><div>and then elsewhere (my second process) where I need that Pid, I can use<br><br>whereis(NameToRegisterItAs)</div><div><br></div><div>to get the Pid. As long as you set up your supervisor correctly, and assuming a single node (else you may need to globally register it rather than locally) the registered Pid should always be the one the process is running under. </div><div><br></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
------------------------------<br>
<br>
Message: 7<br>
Date: Wed, 25 Feb 2015 14:03:44 -0500<br>
From: nx <<a href="mailto:nx@nu-ex.com">nx@nu-ex.com</a>><br>
To: erlang-questions <<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>><br>
Subject: [erlang-questions] Supervising a Process that is Dependent on<br>
Another Process<br>
Message-ID:<br>
<CAP8Yv7KxYS+qXA04k7qWjZMjZMpD9uaMsAOwL2W4yA+6=<a href="mailto:VZMyw@mail.gmail.com">VZMyw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
Is it possible to supervise a process that requires the Pid of another<br>
process in its start_link function?<br>
<br>
I'm not clear on how I can get the supervisor to 1) start a process 2)<br>
start another process with the Pid of the first process, then 3)<br>
restart both of these if the first process fails and automatically<br>
pass in the Pid of the restarted first process to the second process.<br>
<br>
I may be expecting too much from the supervisor. Any suggestions?<br>
<br>
Thanks!<br>
<br><br></blockquote></div></div></div>