<div dir="ltr"><div> For the first question (responding to both 'cause it's easier), I think it actually just doesn't work across nodes; if I supply node() as the param, spawn_opt/5 works just fine with monitor. Though yes, spawn_opt/3 is probably the same issue, in that it delegates to spawn_opt/5. I bet both are related to the fact that spawn_monitor doesn't accept a node option; the distribution protocol probably does not handle spawning and monitoring across nodes in an atomic fashion. </div><div><br></div><div> For the second, could you trap exit signals and spawn_link, and then handle the exit messages? If an exit is from any other pid, or from the spawned one for a reason other than normal you can disable trapping exits and then exit for the received reason, but if it's from the spawned pid and normal you know it completed successfully, and you can then disable trapping exits, do a quick receive {'EXIT', ...} after 0 -> ok end in case of any new exit messages between handling the normal exit and disabling trapping, and then have the process go about its business.</div><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 23 Feb 2015 15:17:41 +0000<br>
From: Roger Lipscombe <<a href="mailto:roger@differentpla.net">roger@differentpla.net</a>><br>
To: "<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>" <<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>><br>
Subject: [erlang-questions] Using 'monitor' with spawn_opt/3 throws<br>
badarg. Documentation bug?<br>
Message-ID:<br>
<<a href="mailto:CAJgnQd8UOZzY0kPyix0oRUygw8cC-KB8ZuhJfGyq7zX-U6u_ZQ@mail.gmail.com">CAJgnQd8UOZzY0kPyix0oRUygw8cC-KB8ZuhJfGyq7zX-U6u_ZQ@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
I'm attempting to use spawn_opt/3 with a remote node, like this:<br>
<br>
Fun = fun() -> ok end,<br>
{Pid, Ref} = spawn_opt(Node, Fun, [link, monitor]).<br>
<br>
It fails with:<br>
<br>
{badarg,<br>
[{erlang,spawn_opt,<br>
['imp_server@roger-pc',erlang,apply,<br>
[#Fun<erl_eval.20.80484245>,[]],<br>
[link,monitor]],<br>
[]}<br>
<br>
Now, the documentation at<br>
<a href="http://www.erlang.org/doc/man/erlang.html#spawn_opt-5" target="_blank">http://www.erlang.org/doc/man/erlang.html#spawn_opt-5</a> says that the<br>
'monitor' option is not allowed for spawn_opt/5. It says nothing about<br>
spawn_opt/3.<br>
<br>
Looking at the error message, it looks like spawn_opt/3 simply calls<br>
spawn_opt/5. Does this note about 'monitor' being unsupported need to<br>
be in documentation for both functions?<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 23 Feb 2015 15:21:12 +0000<br>
From: Roger Lipscombe <<a href="mailto:roger@differentpla.net">roger@differentpla.net</a>><br>
To: "<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>" <<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>><br>
Subject: [erlang-questions] Using 'monitor' with spawn_opt/3 throws<br>
badarg. How to monitor a remote process?<br>
Message-ID:<br>
<<a href="mailto:CAJgnQd8t-RASC6RiJUTtfcFojp0KZVrWev4hpf7CAeOnD4pbow@mail.gmail.com">CAJgnQd8t-RASC6RiJUTtfcFojp0KZVrWev4hpf7CAeOnD4pbow@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
Note that, despite the preamble, this is a different question to the<br>
other one I just posted. Honest.<br>
<br>
I'm attempting to use spawn_opt/3 with a remote node, like this:<br>
<br>
Fun = fun() -> ok end,<br>
{Pid, Ref} = spawn_opt(Node, Fun, [link, monitor]).<br>
<br>
It fails with badarg.<br>
<br>
How do I monitor a process that I spawn on a remote node?<br>
<br>
If I use spawn_link followed by monitor, there's a race where the<br>
remote process could have exited already, and I get {'DOWN', Ref,<br>
process, Pid, noproc}, which is disconcerting.<br>
<br>
I want to know when it's finished. Preferably without it needing to<br>
explicitly send a message back to me.<br><br>
</blockquote></div><br></div></div>