Link question.

Lennart Öhman <>
Sat Jul 20 08:39:25 CEST 2002


Hi Martin,

I guess you have tried that in the shell!? I have run into that
during a training class or two while trying to show linking to students.

The general idea is that link/1 must always succeed since you can not tell
the difference between a process that does not exist at the linking moment
and a process that dies a second later.

I had to write a program and run it in a process spawned from the shell
to demonstrate it. From my "teacher-toolsbox":

-module(link_test).
-compile(export_all).

f(P) ->
    process_flag(trap_exit,true),
    case catch link(P) of
	true ->
	    io:format("true~n",[]),
	    wait_for_exit(P);
	{'EXIT',Reason} ->
	    io:format("Got~w~n",[Reason])
    end.

wait_for_exit(P) ->
    receive
	Any ->
	    io:format("Got 2: ~w~n",[Any])
    end.


/Lennart


martin logan wrote:
> 
> Hello all,
> I have found an interesting problem with link that I could not find an
> explanation for in the docs. I wanted to ask if link is defined this way for
> a reason? Here is the scenario.
> 
> All procs on one node:
> 
> case catch link(DeadLocalPid) of
>     true -> true;
>     {'EXIT', Reason} -> false
> end.
> 
> yeilds: false
> 
> The pid referanced of is on a remote node.
> 
> case catch link(DeadRemotePid) of
>     true -> true;
>     {'EXIT', Reason} -> false
> end.
> 
> yeilds: true
> 
> So the situation in english; If I have a pid that dies befor I link to it
> and it was local I get {'EXIT' Reason}. If the pid was remote I get true.
> Can anyone explain why this is the case?
> 
> Thanks,
> Martin
> 
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx


-------------------------------------------------------------
Lennart Ohman                   phone   : +46-8-587 623 27
Sjoland & Thyselius Telecom AB  cellular: +46-70-552 6735
Sehlstedtsgatan 6               fax     : +46-8-667 8230
SE-115 28 STOCKHOLM, SWEDEN     email   : 



More information about the erlang-questions mailing list