这篇文章还不是最终版,有时间时,我会再来补充完善。
什么是link
Erlang程序基于进程建模,进程之间的交互机制有收发消息,link和monitor。其中,收发消息通常用于正常的进程间通讯,而link和monitor多用于异常情况处理,本文从应用的角度介绍和分析link机制。link是双向全联通的,用来将两个或多个进程绑定在一起,绑定在一起之后,VM会保证在有进程退出时,对与其绑定在一起的进程执行特定的操作。
创建link和取消link
Two processes can be linked to each other. A link between two
processes Pid1 and Pid2 is created by Pid1 calling the BIF
link(Pid2)(or vice versa). There also exists a number a spawn_link
BIFs, which spawns and links to a process in one operation.
Links are bidirectional and there can only be one link between two
processes.Repeated calls to link(Pid) have no effect.
A link can be removed bycalling the BIF unlink(Pid).
当有进程退出时
发送Exit Signal
When a process terminates, it will terminate with an exit reason as
explained in Process Termin