[erlang-questions] How to detect that spawn/4 did not work

Brujo Benavides @ Inaka <>
Fri Aug 8 22:12:53 CEST 2014


Digging further, you can try with spawn_link:

1> process_flag(trap_exit, true).
false
2> spawn_link('', erlang, display, [nothing]).
<0.44.0>
3>
=ERROR REPORT==== 8-Aug-2014::17:11:51 ===
** Can not start erlang:display,[nothing] ([link]) on '' **
3> flush().
Shell got {'EXIT',<0.44.0>,noconnection}
ok
4>

> On Aug 8, 2014, at 17:06, Federico Carrone <> wrote:
> 
> How can we detect that spawn/4 did not work (network split, host down, etc)? We get an error report but the function returns an invalid Pid and it is not possible to know if it is a real one or not. 
> 
> Why does it return a pid even if it did not work and if it can detect the error (since it generated an error report)?
> 
> Regards,
> Federico.
> 
> ---
> 
> 1> spawn('', erlang, display, [nothing]).
> <0.43.0>
> 
> =ERROR REPORT==== 8-Aug-2014::16:50:52 ===
> ** Can not start erlang:display,[nothing] on '' **
> 
> 2> proc_lib:spawn('', erlang, display, [nothing]).
> <0.56.0>
> 
> 3>
> =ERROR REPORT==== 8-Aug-2014::16:52:21 ===
> ** Can not start proc_lib:init_p,[<0.50.0>,[],erlang,display,[nothing]] on '' **
> 
> 4> is_process_alive(spawn('', erlang, display, [nothing])).
> true
> 5>
> =ERROR REPORT==== 8-Aug-2014::16:53:27 ===
> ** Can not start erlang:display,[nothing] on '' **
> 
> -- 
> http://federicocarrone.com/
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140808/0712de78/attachment.html>


More information about the erlang-questions mailing list