<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>庆亮的博客-webgame架构 &#187; Erlang</title>
	<atom:link href="http://www.qingliangcn.com/tag/erlang/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.qingliangcn.com</link>
	<description>关注LAMP&#124;PHP源代码分析&#124;web架构&#124;PHP扩展&#124;Erlang&#124;服务端架构</description>
	<lastBuildDate>Wed, 11 Aug 2010 15:25:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>erlang zlib引起的系统崩溃记录</title>
		<link>http://www.qingliangcn.com/2010/08/erlang-zlib%e5%bc%95%e8%b5%b7%e7%9a%84%e7%b3%bb%e7%bb%9f%e5%b4%a9%e6%ba%83%e8%ae%b0%e5%bd%95/</link>
		<comments>http://www.qingliangcn.com/2010/08/erlang-zlib%e5%bc%95%e8%b5%b7%e7%9a%84%e7%b3%bb%e7%bb%9f%e5%b4%a9%e6%ba%83%e8%ae%b0%e5%bd%95/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:00:37 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[erlang zlib]]></category>

		<guid isPermaLink="false">http://www.qingliangcn.com/?p=284</guid>
		<description><![CDATA[之前同事遇到一个问题，系统运行一段时间后有大量的port没有正常关闭而导致beam崩溃，经过定位发现是由于zlib引起的。过程很简单，没什么技术含量，记录一下。]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">author: </font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">庆亮</span></font><span lang="EN-US" style="font-size: 9pt"><font color="#000000" face="Calibri"> (</font><a href="mailto:qing.liang.cn@gmail.com"><font face="Calibri">qing.liang.cn@gmail.com</font></a><font color="#000000"><font face="Calibri"> /<span style="mso-spacerun: yes">&nbsp; </span></font></font><a href="http://twitter.com/qingliangcn"><font face="Calibri">http://twitter.com/qingliangcn</font></a><font face="Calibri"><font color="#000000"> ) <o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri"><font color="#000000">date: 2010-07-12<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; margin: 0cm 0cm 0pt"><font color="#000000"><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">之前同事遇到一个问题，系统运行一段时间后有大量的</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">port</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">没有正常关闭而导致</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">beam</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">崩溃，经过定位发现是由于</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">zlib</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">引起的。过程很简单，没什么技术含量，记录一下。<span id="more-284"></span></span><span lang="EN-US" style="font-size: 9pt"><o:p></o:p></span></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">错误信息大致是这样的（原因是传入的数据不是</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">zlib</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">压缩格式）：</span><span lang="EN-US" style="font-size: 9pt"><o:p></o:p></span></font></p>
<blockquote>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri"><font color="#000000">** exception error: data_error<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri"><font color="#000000"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>in function<span style="mso-spacerun: yes">&nbsp; </span>zlib:call/3<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri"><font color="#000000"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>in call from zlib:inflate/2<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri"><font color="#000000"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>in call from zlib:uncompress/1<o:p></o:p></font></font></span></p>
</blockquote>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">看</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">call</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">的实现，应该是这里，</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">erlang:error(list_to_atom(Res))</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">，</span><span style="font-size: 9pt"><font face="Calibri"> <span lang="EN-US"><o:p></o:p></span></font></span></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">看了下</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">zlib</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">的解压源码：</span><span lang="EN-US" style="font-size: 9pt"><o:p></o:p></span></font></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">-</span><b><span lang="EN-US" style="font-family: consolas; color: #999999; font-size: 9pt">spec</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> uncompress(binary()) </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> binary().<br />
		</span><span lang="EN-US" style="font-family: consolas; color: #00a000; font-size: 9pt">uncompress</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Binary</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">) </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">when</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">byte_size</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Binary</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">) </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">&gt;=</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">8</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">=</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> open(),<br />
		&nbsp;&nbsp;&nbsp; inflateInit(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">),<br />
		&nbsp;&nbsp;&nbsp; Bs </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">=</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> inflate(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Binary</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">),<br />
		&nbsp;&nbsp;&nbsp; inflateEnd(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">),<br />
		&nbsp;&nbsp;&nbsp; close(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">),<br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">list_to_binary</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(Bs);<br />
		</span><span lang="EN-US" style="font-family: consolas; color: #00a000; font-size: 9pt">uncompress</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Binary</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">) </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">when</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">is_binary</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Binary</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">) </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><b><span lang="EN-US" style="font-family: consolas; color: blue; font-size: 9pt">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:error(data_error);<br />
		</span><span lang="EN-US" style="font-family: consolas; color: #00a000; font-size: 9pt">uncompress</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(_) </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><b><span lang="EN-US" style="font-family: consolas; color: blue; font-size: 9pt">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:error(badarg).<o:p></o:p></span></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">open</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">是返回一个</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">port<o:p></o:p></font></span></font></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: #00a000; font-size: 9pt">open</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">() </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">open_port</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">({</span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">spawn</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: #bb4444; font-size: 9pt">&quot;zlib_drv&quot;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">}, [binary]).</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri"><font color="#000000"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></font></font></span></p>
</blockquote>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri"><font color="#000000"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">close</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">则关闭一个</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">port<o:p></o:p></font></span></font></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: #00a000; font-size: 9pt">close</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">) </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">try</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp; true </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">=</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">port_close</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">),<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">receive</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: #008800; font-size: 9pt">%In case the caller is the owner and traps exits</span></i><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;EXIT&#39;,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">,_} </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> ok<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">after</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">0</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> ok<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">end</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">catch</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> _:_ </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><b><span lang="EN-US" style="font-family: consolas; color: blue; font-size: 9pt">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:error(badarg)<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">end</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">.</p>
<p>
		</span><span lang="EN-US" style="font-family: consolas; color: #00a000; font-size: 9pt">inflate</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Data</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">) </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">try</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">port_command</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Data</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">) </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">of</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; true </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; call(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: #880000; font-size: 9pt">?INFLATE</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">&lt;&lt;</span><span lang="EN-US" style="font-family: consolas; color: #880000; font-size: 9pt">?Z_NO_FLUSH</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">32&gt;&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">),<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; collect(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">)<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">catch</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue; font-size: 9pt">error</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Err</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flush(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">),<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue; font-size: 9pt">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:error(badarg)<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">end</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">.<br />
		&nbsp;&nbsp;&nbsp; </p>
<p>		&nbsp;&nbsp;&nbsp; <br />
		</span><span lang="EN-US" style="font-family: consolas; color: #00a000; font-size: 9pt">call</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Cmd</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Arg</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">) </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">try</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">port_control</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Cmd</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Arg</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">) </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">of</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">0</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">|</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Res</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">] </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">list_to_atom</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Res</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">);<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">1</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">|</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Res</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">] </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flush(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Z</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">),<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue; font-size: 9pt">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:error(</span><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">list_to_atom</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">Res</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">));<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">2</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">A</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">,B,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">C</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">D</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">] </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">A</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">bsl</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">24</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">)</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">+</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(B </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">bsl</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">16</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">)</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">+</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">C</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">bsl</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">8</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">)</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">+</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">D</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">3</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">A</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">,B,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">C</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">D</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">] </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue; font-size: 9pt">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:error({need_dictionary,(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">A</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">bsl</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">24</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">)</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">+</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(B </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">bsl</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">16</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">)</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">+</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">C</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">bsl</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">8</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">)</span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">+</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod; font-size: 9pt">D</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">})<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">catch</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue; font-size: 9pt">error</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:badarg </span><span lang="EN-US" style="font-family: consolas; color: #666666; font-size: 9pt">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"> </span><i><span lang="EN-US" style="font-family: consolas; color: #008800; font-size: 9pt">%% Rethrow loses port_control from stacktrace.</span></i><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue; font-size: 9pt">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">:error(badarg)<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff; font-size: 9pt">end</span></b><span lang="EN-US" style="font-family: consolas; color: black; font-size: 9pt">.</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri"><font color="#000000"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></font></font></span></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">erlang</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">在遇到</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">port</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">返回错误时直接</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">error</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">了，典型的非防御性编程。</span><span style="font-size: 9pt"><font face="Calibri"> </font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">但是个人认为这个接口应该在抛出错误之前关闭掉打开的</span><span lang="EN-US" style="font-size: 9pt"><font face="Calibri">port</font></span><span style="font-family: 宋体; font-size: 9pt; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">。</span><span lang="EN-US" style="font-size: 9pt"><o:p></o:p></span></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-size: 9pt"><span style="mso-tab-count: 1"><font color="#000000" face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><o:p></o:p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2010/08/erlang-zlib%e5%bc%95%e8%b5%b7%e7%9a%84%e7%b3%bb%e7%bb%9f%e5%b4%a9%e6%ba%83%e8%ae%b0%e5%bd%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erlang OTP之terminate 深入分析</title>
		<link>http://www.qingliangcn.com/2010/08/erlang-otp%e4%b9%8bterminate-%e6%b7%b1%e5%85%a5%e5%88%86%e6%9e%90/</link>
		<comments>http://www.qingliangcn.com/2010/08/erlang-otp%e4%b9%8bterminate-%e6%b7%b1%e5%85%a5%e5%88%86%e6%9e%90/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 11:02:56 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[one_for_one]]></category>
		<category><![CDATA[otp]]></category>
		<category><![CDATA[simple_one_for_one]]></category>
		<category><![CDATA[supervisor]]></category>
		<category><![CDATA[terminate]]></category>

		<guid isPermaLink="false">http://www.qingliangcn.com/?p=280</guid>
		<description><![CDATA[作者：庆亮 (qing.liang.cn@gmail.com) 日期：2010-08-03 环境：centos&#160; 5.5&#160; 64 &#160;&#160;&#160;&#160;erlang 14A &#160; 一、terminate简述及问题产生 &#160; terminate是gen_server的一个回调函数，如果一个gen_server进程设置了trap_exit为true（process_flag(trap_exit, true)），则在该进程结束时会自动调用terminate。利用这个功能，我们可以在进程退出时进行一些善后工作，例如持久化数据、清理等等。但实际上terminate不一定有时间完成所有的任务，在此之前可能已经被系统强制结束了(如果使用init:stop形式结束beam)。 &#160; 二、测试terminate 一个erlang 内部 process结束有两种形式：主动结束（如玩家下线后，玩家进程会自动结束）和被动结束(init:stop)。 系统停止时（init:stop/c:q/erlang:halt），会依次停止所有的进程，如果一个进程是监控树，则该监控树会先依次停止所有的子进程，然后结束自己。对于子进程也是同样的处理方法。 &#160; 先做测试，后分析源码。测试分为四种情况： &#160; 进程主动退出 + simple_one_for_one init:stop + simple_one_for_one 进程主动退出 + one_for_one init:stop + one_for_one &#160; 源码文件： test.erl (application) test_sup.erl (supervisor) test_server.erl (gen_server) &#160; test.erl源码： &#160; -module(test). -behaviour(application). -export([start/0, start/2, stop/1]). start() -&#62; &#160;&#160;&#160; application:start(test). start(_StartType,]]></description>
			<content:encoded><![CDATA[<h1 style="margin: 17pt 0cm 16.5pt"><span style="font-size: 12px"><b><font color="#000000"><span style="font-family: 宋体">作者：庆亮</span><span lang="EN-US"><font face="Calibri"> (<a href="mailto:qing.liang.cn@gmail.com">qing.liang.cn@gmail.com</a>)</font></span></font></b></span></h1>
<h1 style="margin: 17pt 0cm 16.5pt"><span style="font-size: 12px"><b><font color="#000000"><span style="font-family: 宋体">日期：</span><span lang="EN-US"><font face="Calibri">2010-08-03</font></span></font></b></span></h1>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><b><font color="#000000"><span style="font-family: 宋体">环境：</span><span lang="EN-US"><font face="Calibri">centos&nbsp; 5.5&nbsp; 64 &nbsp;&nbsp;&nbsp;&nbsp;erlang 14A </font></span></font></b></span><b><font color="#000000"><font size="3"><span lang="EN-US"><font face="Calibri"><o:p></o:p></font></span></font></font></b></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent: -22.5pt; margin: 0cm 0cm 0pt 22.5pt"><span style="font-size: 12px"><font color="#000000"><font face="Calibri"><b><span lang="EN-US">一、</span></b><b><span lang="EN-US">terminate</span></b></font><b><span style="font-family: 宋体">简述及问题产生</span></b></font></span><font color="#000000"><font size="3"><b><span lang="EN-US"><o:p></o:p></span></b></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><b><span lang="EN-US"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></b></span><b><span lang="EN-US"><o:p></o:p></span></b></p>
<p align="left" class="MsoNormal" style="text-align: left; text-indent: 21pt; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><span lang="EN-US"><font face="Calibri">terminate</font></span><span style="font-family: 宋体">是</span><span lang="EN-US"><font face="Calibri">gen_server</font></span><span style="font-family: 宋体">的一个回调函数，如果一个</span><span lang="EN-US"><font face="Calibri">gen_server</font></span><span style="font-family: 宋体">进程设置了</span><span lang="EN-US"><font face="Calibri">trap_exit</font></span><span style="font-family: 宋体">为</span><span lang="EN-US"><font face="Calibri">true</font></span><span style="font-family: 宋体">（</span><span lang="EN-US"><font face="Calibri">process_flag(trap_exit, true)</font></span><span style="font-family: 宋体">），则在该进程结束时会自动调用</span><span lang="EN-US"><font face="Calibri">terminate</font></span><span style="font-family: 宋体">。利用这个功能，我们可以在进程退出时进行一些善后工作，例如持久化数据、清理等等。但实际上</span><span lang="EN-US"><font face="Calibri">terminate</font></span><span style="font-family: 宋体">不一定有时间完成所有的任务，在此之前可能已经被系统强制结束了</span><span lang="EN-US"><font face="Calibri">(</font></span><span style="font-family: 宋体">如果使用</span><span lang="EN-US"><font face="Calibri">init:stop</font></span><span style="font-family: 宋体">形式结束</span><span lang="EN-US"><font face="Calibri">beam)</font></span><span style="font-family: 宋体">。<span id="more-280"></span></span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent: -22.5pt; margin: 0cm 0cm 0pt 22.5pt"><span style="font-size: 12px"><font color="#000000"><b><span lang="EN-US"><font face="Calibri">二、</font></span><span style="font-family: 宋体">测试</span><span lang="EN-US"><font face="Calibri">terminate</font></span></b></font></span><font color="#000000"><font size="3"><b><span lang="EN-US"><font face="Calibri"><o:p></o:p></font></span></b></font></font></p>
<p class="MsoNormal" style="text-indent: 21pt; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><span style="font-family: 宋体">一个</span><span lang="EN-US"><font face="Calibri">erlang </font></span><span style="font-family: 宋体">内部</span><span lang="EN-US"><font face="Calibri"> process</font></span><span style="font-family: 宋体">结束有两种形式：主动结束（如玩家下线后，玩家进程会自动结束）和被动结束</span><span lang="EN-US"><font face="Calibri">(init:stop)</font></span><span style="font-family: 宋体">。</span><font face="Calibri"> </font></font></span></p>
<p class="MsoNormal" style="text-indent: 21pt; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><span style="font-family: 宋体">系统停止时（</span><span lang="EN-US"><font face="Calibri">init:stop/c:q/erlang:halt</font></span><span style="font-family: 宋体">），会依次停止所有的进程，如果一个进程是监控树，则该监控树会先依次停止所有的子进程，然后结束自己。对于子进程也是同样的处理方法。</span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体"><font color="#000000">先做测试，后分析源码。测试分为四种情况：</font></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000" face="Calibri">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><strong><span style="font-family: 宋体">进程主动退出</span><span lang="EN-US" style="font-family: 'calibri', 'sans-serif'"><font face=""> + simple_one_for_one</font></span></strong></font></span><font color="#000000"><font size="3"><strong><span lang="EN-US" style="font-family: 'calibri', 'sans-serif'"><font face=""><o:p></o:p></font></span></strong></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><strong><span lang="EN-US" style="font-family: 'calibri', 'sans-serif'"><font face=""><font color="#000000">init:stop + simple_one_for_one</font></font></span></strong></span><strong><span lang="EN-US" style="font-family: 'calibri', 'sans-serif'"><font face=""><font color="#000000"><font size="3"><o:p></o:p></font></font></font></span></strong></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><strong><span style="font-family: 宋体">进程主动退出</span><span lang="EN-US" style="font-family: 'calibri', 'sans-serif'"><font face=""> + one_for_one</font></span></strong></font></span><font color="#000000"><font size="3"><strong><span lang="EN-US" style="font-family: 'calibri', 'sans-serif'"><font face=""><o:p></o:p></font></span></strong></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><strong><span lang="EN-US" style="font-family: 'calibri', 'sans-serif'"><font face=""><font color="#000000">init:stop + one_for_one</font></font></span></strong></span><strong><span lang="EN-US" style="font-family: 'calibri', 'sans-serif'"><font face=""><font color="#000000"><font size="3"><o:p></o:p></font></font></font></span></strong></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体"><font color="#000000">源码文件：</font></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><font color="#000000">test.erl (application)</font></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><font color="#000000">test_sup.erl (supervisor)</font></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><font color="#000000">test_server.erl (gen_server)</font></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><span lang="EN-US">test.erl</span><span style="font-family: 宋体">源码：</span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">module</span></b><span lang="EN-US" style="font-family: consolas; color: black">(test).</p>
<p>		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">behaviour</span></b><span lang="EN-US" style="font-family: consolas; color: black">(application).</p>
<p>		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">export</span></b><span lang="EN-US" style="font-family: consolas; color: black">([start</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/0</span><span lang="EN-US" style="font-family: consolas; color: black">, start</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/2</span><span lang="EN-US" style="font-family: consolas; color: black">, stop</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/1</span><span lang="EN-US" style="font-family: consolas; color: black">]).</p>
<p>		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">start</span><span lang="EN-US" style="font-family: consolas; color: black">() </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue">application</span></b><span lang="EN-US" style="font-family: consolas; color: black">:start(test).</p>
<p>		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">start</span><span lang="EN-US" style="font-family: consolas; color: black">(_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">StartType</span><span lang="EN-US" style="font-family: consolas; color: black">, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">StartArgs</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">case</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><b><span lang="EN-US" style="font-family: consolas; color: blue">test_sup</span></b><span lang="EN-US" style="font-family: consolas; color: black">:start_link() </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">of</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {ok, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {ok, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">};<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Error</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Error</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">.</p>
<p>		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">stop</span><span lang="EN-US" style="font-family: consolas; color: black">(_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; ok.</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">非常简单，直接通过</span><span style="font-family: consolas; color: black"> <span lang="EN-US">erl -name test@192.168.1.83 -setcookie 123456 -boot start_sasl -s test start </span></span><span style="font-family: 宋体; color: black">即可启动该</span><span lang="EN-US" style="font-family: consolas; color: black">app</span><span style="font-family: 宋体; color: black">。</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">test_sup.erl</span><span style="font-family: 宋体; color: black">源码：</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">module</span></b><span lang="EN-US" style="font-family: consolas; color: black">(test_sup).</p>
<p>		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">behaviour</span></b><span lang="EN-US" style="font-family: consolas; color: black">(supervisor).</p>
<p>		</span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% API</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">export</span></b><span lang="EN-US" style="font-family: consolas; color: black">([start_link</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/0</span><span lang="EN-US" style="font-family: consolas; color: black">]).</p>
<p>		</span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% Supervisor callbacks</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">export</span></b><span lang="EN-US" style="font-family: consolas; color: black">([init</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/1</span><span lang="EN-US" style="font-family: consolas; color: black">]).</p>
<p>		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">define</span></b><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">SERVER</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">?MODULE</span><span lang="EN-US" style="font-family: consolas; color: black">).</p>
<p>
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">start_link</span><span lang="EN-US" style="font-family: consolas; color: black">() </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue">supervisor</span></b><span lang="EN-US" style="font-family: consolas; color: black">:start_link({local, </span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">?SERVER</span><span lang="EN-US" style="font-family: consolas; color: black">}, </span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">?MODULE</span><span lang="EN-US" style="font-family: consolas; color: black">, []).</p>
<p>
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">init</span><span lang="EN-US" style="font-family: consolas; color: black">([]) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">RestartStrategy</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> simple_one_for_one,<br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MaxRestarts</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">1000</span><span lang="EN-US" style="font-family: consolas; color: black">,<br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MaxSecondsBetweenRestarts</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">3600</span><span lang="EN-US" style="font-family: consolas; color: black">,</p>
<p>		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupFlags</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> {</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">RestartStrategy</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MaxRestarts</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MaxSecondsBetweenRestarts</span><span lang="EN-US" style="font-family: consolas; color: black">},</p>
<p>		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Restart</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> transient,<br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Shutdown</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">200000</span><span lang="EN-US" style="font-family: consolas; color: black">,<br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Type</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> worker,</p>
<p>		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">AChild</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> {test_server, {test_server, start_link, []},<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Restart</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Shutdown</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Type</span><span lang="EN-US" style="font-family: consolas; color: black">, [test_server]},</p>
<p>		&nbsp;&nbsp;&nbsp; {ok, {</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupFlags</span><span lang="EN-US" style="font-family: consolas; color: black">, [</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">AChild</span><span lang="EN-US" style="font-family: consolas; color: black">]}}.</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">源码骨架都是</span><span lang="EN-US" style="font-family: consolas; color: black">emacs</span><span style="font-family: 宋体; color: black">生成的，我们只关注</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">RestartStrategy</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> simple_one_for_one,</span><span style="font-family: 宋体; color: black">这里，等会需要改成</span><span lang="EN-US" style="font-family: consolas; color: black">one_for_one</span><span style="font-family: 宋体; color: black">以便测试对比。</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">test_server.erl</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">module</span></b><span lang="EN-US" style="font-family: consolas; color: black">(test_server).</p>
<p>		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">behaviour</span></b><span lang="EN-US" style="font-family: consolas; color: black">(gen_server).</p>
<p>		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">export</span></b><span lang="EN-US" style="font-family: consolas; color: black">([<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/0</span><span lang="EN-US" style="font-family: consolas; color: black">, <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start_link</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/0</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]).</p>
<p>		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">export</span></b><span lang="EN-US" style="font-family: consolas; color: black">([init</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/1</span><span lang="EN-US" style="font-family: consolas; color: black">, handle_call</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/3</span><span lang="EN-US" style="font-family: consolas; color: black">, handle_cast</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/2</span><span lang="EN-US" style="font-family: consolas; color: black">, handle_info</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/2</span><span lang="EN-US" style="font-family: consolas; color: black">,<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; terminate</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/2</span><span lang="EN-US" style="font-family: consolas; color: black">, code_change</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">/3</span><span lang="EN-US" style="font-family: consolas; color: black">]).</p>
<p>		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">define</span></b><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">SERVER</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">?MODULE</span><span lang="EN-US" style="font-family: consolas; color: black">). </p>
<p>		-</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(153,153,153)">record</span></b><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">state</span><span lang="EN-US" style="font-family: consolas; color: black">, {}).</p>
<p>		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">start</span><span lang="EN-US" style="font-family: consolas; color: black">() </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; {ok, _} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><b><span lang="EN-US" style="font-family: consolas; color: blue">supervisor</span></b><span lang="EN-US" style="font-family: consolas; color: black">:start_child(test_sup, []).</p>
<p>
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">start_link</span><span lang="EN-US" style="font-family: consolas; color: black">() </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue">gen_server</span></b><span lang="EN-US" style="font-family: consolas; color: black">:start_link(</span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">?MODULE</span><span lang="EN-US" style="font-family: consolas; color: black">, [], []).</p>
<p>
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">init</span><span lang="EN-US" style="font-family: consolas; color: black">([]) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black">:</span><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">process_flag</span><span lang="EN-US" style="font-family: consolas; color: black">(trap_exit, true),<br />
		&nbsp;&nbsp;&nbsp; {ok, </span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#state</span><span lang="EN-US" style="font-family: consolas; color: black">{}}.</p>
<p>
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">handle_call</span><span lang="EN-US" style="font-family: consolas; color: black">(_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Request</span><span lang="EN-US" style="font-family: consolas; color: black">, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">From</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reply</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> ok,<br />
		&nbsp;&nbsp;&nbsp; {reply, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reply</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">}.</p>
<p>
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">handle_cast</span><span lang="EN-US" style="font-family: consolas; color: black">(_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Msg</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; {noreply, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">}.</p>
<p>		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">handle_info</span><span lang="EN-US" style="font-family: consolas; color: black">({&#39;EXIT&#39;, _, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">}, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue">io</span></b><span lang="EN-US" style="font-family: consolas; color: black">:format(</span><span lang="EN-US" style="font-family: consolas; color: rgb(187,68,68)">&quot;exit:</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(187,102,136)">~p~n</span></b><span lang="EN-US" style="font-family: consolas; color: rgb(187,68,68)">&quot;</span><span lang="EN-US" style="font-family: consolas; color: black">, [</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">]),<br />
		&nbsp;&nbsp;&nbsp; {stop, normal, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">};</p>
<p>		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">handle_info</span><span lang="EN-US" style="font-family: consolas; color: black">(_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Info</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; {noreply, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">}.</p>
<p>
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">terminate</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue">io</span></b><span lang="EN-US" style="font-family: consolas; color: black">:format(</span><span lang="EN-US" style="font-family: consolas; color: rgb(187,68,68)">&quot;i&#39;m terminate:</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(187,102,136)">~p~n</span></b><span lang="EN-US" style="font-family: consolas; color: rgb(187,68,68)">&quot;</span><span lang="EN-US" style="font-family: consolas; color: black">, [</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">]),<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue">timer</span></b><span lang="EN-US" style="font-family: consolas; color: black">:sleep(</span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">10000</span><span lang="EN-US" style="font-family: consolas; color: black">),<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue">io</span></b><span lang="EN-US" style="font-family: consolas; color: black">:format(</span><span lang="EN-US" style="font-family: consolas; color: rgb(187,68,68)">&quot;</span><b><span lang="EN-US" style="font-family: consolas; color: rgb(187,102,136)">~s</span></b><span lang="EN-US" style="font-family: consolas; color: rgb(187,68,68)">&quot;</span><span lang="EN-US" style="font-family: consolas; color: black">, [</span><span lang="EN-US" style="font-family: consolas; color: rgb(187,68,68)">&quot;end&quot;</span><span lang="EN-US" style="font-family: consolas; color: black">]),<br />
		&nbsp;&nbsp;&nbsp; ok.</p>
<p>
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">code_change</span><span lang="EN-US" style="font-family: consolas; color: black">(_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OldVsn</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Extra</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; {ok, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">}.</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">简单说明下</span><span lang="EN-US" style="font-family: consolas; color: black">test_server</span><span style="font-family: 宋体; color: black">：</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoListParagraph" style="text-align: left; text-indent: -18pt; margin: 0cm 0cm 0pt 18pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoListParagraph" style="text-align: left; text-indent: -18pt; margin: 0cm 0cm 0pt 18pt"><span lang="EN-US" style="font-family: consolas; color: black"><span><font size="3">2．</font><span style="font: 7pt 'times new roman'"> </span></span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">handle_info</span><span lang="EN-US" style="font-family: consolas; color: black">({&#39;EXIT&#39;, _, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">}, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span style="font-family: 宋体; color: black">方便</span><span lang="EN-US" style="font-family: consolas; color: black">simple_one_for_one</span><span style="font-family: 宋体; color: black">下进程进程退出操作</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoListParagraph" style="text-align: left; text-indent: -18pt; margin: 0cm 0cm 0pt 18pt"><font color="#000000"><span lang="EN-US" style="font-family: consolas"><span><font size="3">3．</font><span style="font: 7pt 'times new roman'"> </span></span></span><font size="3"><span lang="EN-US" style="font-family: consolas">terminate</span><span style="font-family: 宋体">中的清理工作：</span><span lang="EN-US" style="font-family: consolas">io </span><span style="font-family: 宋体">&rarr;</span><span lang="EN-US" style="font-family: consolas"> timer:sleep </span><span style="font-family: 宋体">&rarr;</span><span lang="EN-US" style="font-family: consolas"> io<o:p></o:p></span></font></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas"><o:p><font color="#000000" size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><span style="font-family: 宋体">启动命令行：</span><span lang="EN-US" style="font-family: consolas; color: black">erl -name test@192.168.1.83 -setcookie 123456 -boot start_sasl -s test start<o:p></o:p></span></font></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas"><o:p><font color="#000000" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas"><o:p><font color="#000000" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoListParagraph" style="text-align: left; text-indent: -21pt; margin: 0cm 0cm 0pt 21pt"><font color="#000000"><b><span lang="EN-US" style="font-family: consolas"><span><font size="3">1．</font><span style="font: 7pt 'times new roman'"> </span></span></span></b><font size="3"><b><span style="font-family: 宋体">进程主动退出</span></b><b><span lang="EN-US" style="font-family: consolas"> + simple_one_for_one<o:p></o:p></span></b></font></font></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">(test@192.168.1.83)1&gt; erlang:exit(list_to_pid(&quot;&lt;0.51.0&gt;&quot;), test).</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">exit:test</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">true</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">i&#39;m terminate:normal</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">(test@192.168.1.83)2&gt; end</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas"><o:p><font color="#000000" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><span style="font-family: 宋体">正常完成了</span><span lang="EN-US" style="font-family: consolas">terminate<o:p></o:p></span></font></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><b><span lang="EN-US" style="font-family: consolas"><o:p><font color="#000000" size="3">&nbsp;</font></o:p></span></b></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><b><span lang="EN-US" style="font-family: consolas">2</span></b><b><span style="font-family: 宋体">．</span></b><b><span lang="EN-US" style="font-family: consolas"> init:stop + simple_one_for_one<o:p></o:p></span></b></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" size="3">&nbsp;</font></o:p></span></p>
<blockquote>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span>&nbsp;</span><span style="font-size: 12px">(test@192.168.1.83)1&gt; test_server:start().</span><o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">{ok,&lt;0.53.0&gt;}</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">(test@192.168.1.83)2&gt; init:stop().</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">ok</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">(test@192.168.1.83)3&gt; i&#39;m terminate:shutdown</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">[root@ming2_local_dev test]#</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
</blockquote>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black">可以看到似乎没能正常的处理完</span><span lang="EN-US" style="font-family: consolas; color: black">terminate<o:p></o:p></span></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><b><span lang="EN-US" style="font-family: consolas; color: black">3. </span></b><b><span style="font-family: 宋体; color: black">进程主动退出</span></b><b><span lang="EN-US" style="font-family: consolas; color: black"> + one_for_one<o:p></o:p></span></b></font></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">(test@192.168.1.83)1&gt; erlang:exit(list_to_pid(&quot;&lt;0.51.0&gt;&quot;), test).</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">exit:test</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">true</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">i&#39;m terminate:normal</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas"><font color="#000000">(test@192.168.1.83)2&gt; end</font></span></span><span lang="EN-US" style="font-family: consolas"><font color="#000000"><font size="3"><o:p></o:p></font></font></span></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas"><o:p><font color="#000000" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><span style="font-family: 宋体">正常完成了</span><span lang="EN-US" style="font-family: consolas">terminate<o:p></o:p></span></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p class="MsoListParagraph" style="text-indent: -18pt; margin: 0cm 0cm 0pt 18pt"><b><span lang="EN-US" style="font-family: consolas; color: black"><span><font size="3">4．</font><span style="font: 7pt 'times new roman'"> </span></span></span></b><b><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">init:stop + one_for_one<o:p></o:p></font></span></b></p>
<blockquote>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">(test@192.168.1.83)2&gt; init:stop().</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">ok</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">(test@192.168.1.83)3&gt; i&#39;m terminate:shutdown</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">end[root@ming2_local_dev test]#</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
</blockquote>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">ok</span><span style="font-family: 宋体; color: black">，很完整的执行了我们的</span><span lang="EN-US" style="font-family: consolas; color: black">terminate</span><span style="font-family: 宋体; color: black">。</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">terminate</span><span style="font-family: 宋体; color: black">执行测试结果</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p>&nbsp;</p>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; border-top: medium none; border-right: medium none">
<tbody>
<tr>
<td style="border-bottom: black 1pt solid; border-left: black 1pt solid; padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142pt; padding-right: 5.4pt; border-top: black 1pt solid; border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: black 1pt solid; border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">Simple_one_for_one<o:p></o:p></font></span></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: black 1pt solid; border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">One_for_one<o:p></o:p></font></span></p>
</td>
</tr>
<tr>
<td style="border-bottom: black 1pt solid; border-left: black 1pt solid; padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black">进程主动退出</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black">完整执行</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black">完整执行</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
</tr>
<tr>
<td style="border-bottom: black 1pt solid; border-left: black 1pt solid; padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">init:stop<o:p></o:p></font></span></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black">不能完整执行</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black">完整执行</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p class="MsoListParagraph" style="text-indent: -22.5pt; margin: 0cm 0cm 0pt 22.5pt"><font size="3"><b><span lang="EN-US" style="font-family: consolas; color: black"><span>三、</span></span></b><b><span style="font-family: 宋体; color: black">底层分析</span></b><b><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></b></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><span style="font-family: 宋体">看起来很奇怪的结果，还是从源码来分析问题。从</span><span lang="EN-US">supervisor</span><span style="font-family: 宋体">开始：</span></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" size="3">&nbsp;</font></o:p></span></p>
<blockquote>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><strong><em><font color="#4f81bd"><font size="3"><span class="MsoIntenseEmphasis"><span lang="EN-US"><o:p></o:p></span></span></font></font></em></strong></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span class="MsoIntenseEmphasis"><span lang="EN-US"><o:p><strong><em><font color="#4f81bd" size="3">&nbsp;</font></em></strong></o:p></span></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">terminate</span><span lang="EN-US" style="font-family: consolas; color: black">(_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; terminate_children(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#state.children</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#state.name</span><span lang="EN-US" style="font-family: consolas; color: black">),<br />
		&nbsp;&nbsp;&nbsp; ok.</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><span lang="EN-US">terminate_children/2 </span><span style="font-family: 宋体">是一个尾递归函数，依次结束每个子进程</span><span lang="EN-US">:</span></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">terminate_children</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Children</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupName</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; terminate_children(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Children</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupName</span><span lang="EN-US" style="font-family: consolas; color: black">, []).</p>
<p>		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">terminate_children</span><span lang="EN-US" style="font-family: consolas; color: black">([</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: black"> | </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Children</span><span lang="EN-US" style="font-family: consolas; color: black">], </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupName</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Res</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">NChild</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> do_terminate(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupName</span><span lang="EN-US" style="font-family: consolas; color: black">),<br />
		&nbsp;&nbsp;&nbsp; terminate_children(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Children</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupName</span><span lang="EN-US" style="font-family: consolas; color: black">, [</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">NChild</span><span lang="EN-US" style="font-family: consolas; color: black"> | </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Res</span><span lang="EN-US" style="font-family: consolas; color: black">]);<br />
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">terminate_children</span><span lang="EN-US" style="font-family: consolas; color: black">([], _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupName</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Res</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Res</span><span lang="EN-US" style="font-family: consolas; color: black">.</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;<span _fck_bookmark="1" style="display: none">&nbsp;</span></font></o:p></span></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black">在看</span><span lang="EN-US" style="font-family: consolas; color: black">do_terminate/2<o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">do_terminate</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupName</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">when</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#child.pid</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=/=</span><span lang="EN-US" style="font-family: consolas; color: black"> undefined </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">case</span></b><span lang="EN-US" style="font-family: consolas; color: black"> shutdown(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#child.pid</span><span lang="EN-US" style="font-family: consolas; color: black">,<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#child.shutdown</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">of</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; ok </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#child</span><span lang="EN-US" style="font-family: consolas; color: black">{pid </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> undefined};<br />
		&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; report_error(shutdown_error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupName</span><span lang="EN-US" style="font-family: consolas; color: black">),<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#child</span><span lang="EN-US" style="font-family: consolas; color: black">{pid </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> undefined}<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">;<br />
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">do_terminate</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: black">, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupName</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: black">.</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black">继续：</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">shutdown</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, brutal_kill) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp; <br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">case</span></b><span lang="EN-US" style="font-family: consolas; color: black"> monitor_child(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">of</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; ok </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">exit</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, kill),<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">receive</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;DOWN&#39;, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MRef</span><span lang="EN-US" style="font-family: consolas; color: black">, process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, killed} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;DOWN&#39;, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MRef</span><span lang="EN-US" style="font-family: consolas; color: black">, process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">;<br />
		&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">;</p>
<p>		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">shutdown</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Time</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; <br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">case</span></b><span lang="EN-US" style="font-family: consolas; color: black"> monitor_child(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">of</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; ok </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">exit</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, shutdown), </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% Try to shutdown gracefully</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">receive</span></b><span lang="EN-US" style="font-family: consolas; color: black"> <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;DOWN&#39;, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MRef</span><span lang="EN-US" style="font-family: consolas; color: black">, process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, shutdown} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;DOWN&#39;, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MRef</span><span lang="EN-US" style="font-family: consolas; color: black">, process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">after</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Time</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">exit</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, kill),&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% Force termination.</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">receive</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;DOWN&#39;, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MRef</span><span lang="EN-US" style="font-family: consolas; color: black">, process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">;<br />
		&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">.</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">Ok</span><span style="font-family: 宋体; color: black">，结束子进程时分情况处理了，先看看</span><span lang="EN-US" style="font-family: consolas; color: black">monitor_child/1</span><span style="font-family: 宋体; color: black">，代码注释的比较详细，简单的说是用于处理</span><span lang="EN-US" style="font-family: consolas; color: black">child</span><span style="font-family: 宋体; color: black">自己退出的情况。</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">monitor_child</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; <br />
		&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% Do the monitor operation first so that if the child dies </span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% before the monitoring is done causing a &#39;DOWN&#39;-message with</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% reason noproc, we will get the real reason in the &#39;EXIT&#39;-message</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% unless a naughty child has already done unlink&#8230;</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: blue">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black">:</span><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">monitor</span><span lang="EN-US" style="font-family: consolas; color: black">(process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">),<br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">unlink</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">),</p>
<p>		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">receive</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% If the child dies before the unlik we must empty</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% the mail-box of the &#39;EXIT&#39;-message and the &#39;DOWN&#39;-message.</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; {&#39;EXIT&#39;, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"> <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">receive</span></b><span lang="EN-US" style="font-family: consolas; color: black"> <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;DOWN&#39;, _, process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, _} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">after</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">0</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"> <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% If a naughty child did unlink and the child dies before</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% monitor the result will be that shutdown/2 receives a </span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% &#39;DOWN&#39;-message with reason noproc.</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% If the child should die after the unlink there</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% will be a &#39;DOWN&#39;-message with a correct reason</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% that will be handled in shutdown/2. </span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok&nbsp;&nbsp; <br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">.</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">回头看</span><span lang="EN-US" style="font-family: consolas; color: black">shutdown/2</span><span style="font-family: 宋体; color: black">，主要区别在于</span><span lang="EN-US" style="font-family: consolas; color: black">exit(Pid, Reason)</span><span style="font-family: 宋体; color: black">这一行，如果子进程的</span><span lang="EN-US" style="font-family: consolas; color: black">shutdown</span><span style="font-family: 宋体; color: black">策略为</span><span lang="EN-US" style="font-family: consolas; color: black">brutal_kill</span><span style="font-family: 宋体; color: black">，则子进程被直接</span><span lang="EN-US" style="font-family: consolas; color: black">kill</span><span style="font-family: 宋体; color: black">，而</span><span lang="EN-US" style="font-family: consolas; color: black">kill</span><span style="font-family: 宋体; color: black">消息是不能被捕捉的，也就不存在</span><span lang="EN-US" style="font-family: consolas; color: black">terminate</span><span style="font-family: 宋体; color: black">被调用的可能了（</span><span lang="EN-US" style="font-family: consolas; color: black">terminate</span><span style="font-family: 宋体; color: black">能被调用是因为捕捉了</span><span lang="EN-US" style="font-family: consolas; color: black">{&lsquo;EXIT&rsquo;,_, _}</span><span style="font-family: 宋体; color: black">消息，详细情况请自行查看</span><span lang="EN-US" style="font-family: consolas; color: black">gen_server</span><span style="font-family: 宋体; color: black">实现）。如果你想在退出时清理数据，这里一定不能设置为</span><span lang="EN-US" style="font-family: consolas; color: black">brutal_kill</span><span style="font-family: 宋体; color: black">，而是设置为一个较大的时间数值（毫秒），用于等待子进程做善后工作：</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">exit</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, shutdown), </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% Try to shutdown gracefully</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">receive</span></b><span lang="EN-US" style="font-family: consolas; color: black"> <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;DOWN&#39;, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MRef</span><span lang="EN-US" style="font-family: consolas; color: black">, process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, shutdown} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;DOWN&#39;, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MRef</span><span lang="EN-US" style="font-family: consolas; color: black">, process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">after</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Time</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">exit</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, kill),&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%% Force termination.</span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">receive</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;DOWN&#39;, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MRef</span><span lang="EN-US" style="font-family: consolas; color: black">, process, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">OtherReason</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		</span><span style="font-family: 宋体; color: black">如果在指定时间内，子进程尚未结束，则强制</span><span lang="EN-US" style="font-family: consolas; color: black">kill</span><span style="font-family: 宋体; color: black">。</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">从这一块的源码中我们没有看到</span><span lang="EN-US" style="font-family: consolas; color: black">restart strategy(one_for_one &hellip;)</span><span style="font-family: 宋体; color: black">对</span><span lang="EN-US" style="font-family: consolas; color: black">terminate</span><span style="font-family: 宋体; color: black">的影响，这跟上面的测试结果不太吻合。过一遍</span><span lang="EN-US" style="font-family: consolas; color: black">supervisor</span><span style="font-family: 宋体; color: black">的代码，发现针对</span><span lang="EN-US" style="font-family: consolas; color: black">simple_one_for_one</span><span style="font-family: 宋体; color: black">和</span><span lang="EN-US" style="font-family: consolas; color: black">one_for_one</span><span style="font-family: 宋体; color: black">的子进程的启动过程是不同的：</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">handle_call</span><span lang="EN-US" style="font-family: consolas; color: black">({start_child, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">EArgs</span><span lang="EN-US" style="font-family: consolas; color: black">}, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">From</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">when</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">?is_simple</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#child</span><span lang="EN-US" style="font-family: consolas; color: black">{mfa </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> {</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">M</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">F</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">A</span><span lang="EN-US" style="font-family: consolas; color: black">}} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">hd</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#state.children</span><span lang="EN-US" style="font-family: consolas; color: black">),<br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">A</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">++</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">EArgs</span><span lang="EN-US" style="font-family: consolas; color: black">,<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">case</span></b><span lang="EN-US" style="font-family: consolas; color: black"> do_start_child_i(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">M</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">F</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">of</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; {ok, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">NState</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#state</span><span lang="EN-US" style="font-family: consolas; color: black">{dynamics </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">?DICT</span><span lang="EN-US" style="font-family: consolas; color: black">:store(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#state.dynamics</span><span lang="EN-US" style="font-family: consolas; color: black">)},<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {reply, {ok, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">}, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">NState</span><span lang="EN-US" style="font-family: consolas; color: black">};<br />
		&nbsp;&nbsp;&nbsp; {ok, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Extra</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">NState</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#state</span><span lang="EN-US" style="font-family: consolas; color: black">{dynamics </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> <br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">?DICT</span><span lang="EN-US" style="font-family: consolas; color: black">:store(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: rgb(160,160,0)">#state.dynamics</span><span lang="EN-US" style="font-family: consolas; color: black">)},<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {reply, {ok, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Extra</span><span lang="EN-US" style="font-family: consolas; color: black">}, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">NState</span><span lang="EN-US" style="font-family: consolas; color: black">};<br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">What</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {reply, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">What</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">;</p>
<p>		</span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%%% The requests terminate_child, delete_child and restart_child are </span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		</span><i><span lang="EN-US" style="font-family: consolas; color: rgb(0,136,0)">%%% invalid for simple_one_for_one supervisors. </span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">handle_call</span><span lang="EN-US" style="font-family: consolas; color: black">({_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Req</span><span lang="EN-US" style="font-family: consolas; color: black">, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Data</span><span lang="EN-US" style="font-family: consolas; color: black">}, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">From</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">when</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(136,0,0)">?is_simple</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; {reply, {error, simple_one_for_one}, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">};</p>
<p>		</span><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)">handle_call</span><span lang="EN-US" style="font-family: consolas; color: black">({start_child, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">ChildSpec</span><span lang="EN-US" style="font-family: consolas; color: black">}, _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">From</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">case</span></b><span lang="EN-US" style="font-family: consolas; color: black"> check_childspec(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">ChildSpec</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">of</span></b><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp; {ok, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Resp</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">NState</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> handle_start_child(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Child</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">),<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {reply, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Resp</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">NState</span><span lang="EN-US" style="font-family: consolas; color: black">};<br />
		&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">What</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {reply, {error, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">What</span><span lang="EN-US" style="font-family: consolas; color: black">}, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">}<br />
		&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: rgb(170,34,255)">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">;</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</blockquote>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">simple_one_for_one</span><span style="font-family: 宋体; color: black">形式启动的子进程根本没有放在</span><span lang="EN-US" style="font-family: consolas; color: black">supervisor</span><span style="font-family: 宋体; color: black">的</span><span lang="EN-US" style="font-family: consolas; color: black">state.children</span><span style="font-family: 宋体; color: black">里面，也就是说</span><span lang="EN-US" style="font-family: consolas; color: black">supervisor</span><span style="font-family: 宋体; color: black">在</span><span lang="EN-US" style="font-family: consolas; color: black">terminate</span><span style="font-family: 宋体; color: black">的时候根本没管</span><span lang="EN-US" style="font-family: consolas; color: black">simple_one_for_one</span><span style="font-family: 宋体; color: black">形式启动的子进程，如此当</span><span lang="EN-US" style="font-family: consolas; color: black">supervisor</span><span style="font-family: 宋体; color: black">结束时，所有的</span><span lang="EN-US" style="font-family: consolas; color: black">simple_one_for_one</span><span style="font-family: 宋体; color: black">子进程都会收到一条</span><span lang="EN-US" style="font-family: consolas; color: black">{&lsquo;EXIT&rsquo;, Pid, Reason}</span><span style="font-family: 宋体; color: black">的消息，如果子进程有处理这样的消息并返回了</span><span lang="EN-US" style="font-family: consolas; color: black">stop</span><span style="font-family: 宋体; color: black">，则会调用</span><span lang="EN-US" style="font-family: consolas; color: black">terminate</span><span style="font-family: 宋体; color: black">。</span><span style="font-family: consolas; color: black"> </span><span style="font-family: 宋体; color: black">但在执行</span><span lang="EN-US" style="font-family: consolas; color: black">terminate</span><span style="font-family: 宋体; color: black">期间，</span><span lang="EN-US" style="font-family: consolas; color: black">app</span><span style="font-family: 宋体; color: black">可能已经结束，从而正在停止中的系统会直接</span><span lang="EN-US" style="font-family: consolas; color: black">kill</span><span style="font-family: 宋体; color: black">掉该进程（实际上是所有剩余的进程），使得其没有时间执行完所有的功能代码（参考之前的分析《</span><span lang="EN-US" style="font-family: consolas; color: black">init:stop</span><span style="font-family: 宋体; color: black">浅析》）。</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
<p align="left" class="MsoListParagraph" style="text-align: left; text-indent: -22.5pt; margin: 0cm 0cm 0pt 22.5pt"><span style="font-size: 12px"><b><span lang="EN-US" style="font-family: consolas; color: black">四、</span><span style="font-family: 宋体; color: black">结论、问题与解决办法</span></b></span><font size="3"><b><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></b></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent: -18pt; margin: 0cm 0cm 0pt 18pt"><span style="font-size: 12px"><font color="#000000"><span lang="EN-US">1．<span style="line-height: normal; font-variant: normal; font-style: normal; font-family: 'times new roman'; font-weight: normal">&nbsp; </span></span><span style="font-family: 宋体">结论</span></font></span></p>
<p><span style="font-size: 12px">&nbsp;</span></p>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-bottom: medium none; border-left: medium none; border-collapse: collapse; border-top: medium none; border-right: medium none">
<tbody>
<tr>
<td style="border-bottom: black 1pt solid; border-left: black 1pt solid; padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142pt; padding-right: 5.4pt; border-top: black 1pt solid; border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black"><o:p>&nbsp;</o:p></span></span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: black 1pt solid; border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">Simple_one_for_one</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: black 1pt solid; border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">One_for_one</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
</td>
</tr>
<tr>
<td style="border-bottom: black 1pt solid; border-left: black 1pt solid; padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">进程主动退出</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">完整执行</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">完整执行</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
</tr>
<tr>
<td style="border-bottom: black 1pt solid; border-left: black 1pt solid; padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: black">init:stop</span></span><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><o:p></o:p></font></span></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">不能完整执行</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
<td style="border-bottom: black 1pt solid; border-left: rgb(0,0,0); padding-bottom: 0cm; background-color: transparent; padding-left: 5.4pt; width: 142.05pt; padding-right: 5.4pt; border-top: rgb(0,0,0); border-right: black 1pt solid; padding-top: 0cm" valign="top" width="189">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span style="font-family: 宋体; color: black">完整执行</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent: -18pt; margin: 0cm 0cm 0pt 18pt"><span style="font-size: 12px"><font color="#000000"><span lang="EN-US">2．<span style="line-height: normal; font-variant: normal; font-style: normal; font-family: 'times new roman'; font-weight: normal">&nbsp; </span></span><span style="font-family: 宋体">问题</span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><span style="font-family: 宋体">使用</span><span lang="EN-US">simple_one_for_one</span><span style="font-family: 宋体">时，在系统关闭时，可能无法正常的完成某些的善后工作，如数据持久等等</span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent: -18pt; margin: 0cm 0cm 0pt 18pt"><span style="font-size: 12px"><font color="#000000"><span lang="EN-US">3．<span style="line-height: normal; font-variant: normal; font-style: normal; font-family: 'times new roman'; font-weight: normal">&nbsp; </span></span><span style="font-family: 宋体">解决办法</span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><span style="font-family: 宋体">使用</span><span lang="EN-US">one_for_one</span><span style="font-family: 宋体">，但是</span><span lang="EN-US">one_for_one</span><span style="font-family: 宋体">的启动过程需要做一些简单的调整：</span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><span lang="EN-US">sup</span><span style="font-family: 宋体">树的</span><span lang="EN-US">init</span><span style="font-family: 宋体">返回：</span></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US" style="font-family: consolas; color: rgb(0,160,0)"><span _fck_bookmark="1" style="display: none">&nbsp;</span><span _fck_bookmark="1" style="display: none">&nbsp;</span>init</span><span lang="EN-US" style="font-family: consolas; color: black">([]) </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"><br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">RestartStrategy</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> one_for_one,<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MaxRestarts</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">1000</span><span lang="EN-US" style="font-family: consolas; color: black">,<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MaxSecondsBetweenRestarts</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">3600</span><span lang="EN-US" style="font-family: consolas; color: black">,<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupFlags</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">=</span><span lang="EN-US" style="font-family: consolas; color: black"> {</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">RestartStrategy</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MaxRestarts</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MaxSecondsBetweenRestarts</span><span lang="EN-US" style="font-family: consolas; color: black">},<br />
	&nbsp;&nbsp;&nbsp; {ok, {</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">SupFlags</span><span lang="EN-US" style="font-family: consolas; color: black">, []}}.</span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><span lang="EN-US"><o:p><font color="#000000">&nbsp;</font></o:p></span></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-size: 12px"><font color="#000000"><span lang="EN-US">start_child</span><span style="font-family: 宋体">的时候</span><span lang="EN-US">childspec</span><span style="font-family: 宋体">需要拼凑</span><span lang="EN-US">spec id</span><span style="font-family: 宋体">：</span></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-size: 12px"><b><span lang="EN-US" style="font-family: consolas; color: blue">supervisor</span></b><span lang="EN-US" style="font-family: consolas; color: black">:start_child(mod_stall_sup, <br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><b><span lang="EN-US" style="font-family: consolas; color: blue">lists</span></b><span lang="EN-US" style="font-family: consolas; color: black">:concat([</span><span lang="EN-US" style="font-family: consolas; color: rgb(187,68,68)">&quot;mod_stall_server_&quot;</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MAPID</span><span lang="EN-US" style="font-family: consolas; color: black">]), <br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{mod_stall_server, start_link, [</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">MAPID</span><span lang="EN-US" style="font-family: consolas; color: black">]},<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transient, </span><span lang="EN-US" style="font-family: consolas; color: rgb(102,102,102)">30000</span><span lang="EN-US" style="font-family: consolas; color: black">, worker, [mod_stall_server]})<span _fck_bookmark="1" style="display: none">&nbsp;</span><span _fck_bookmark="1" style="display: none">&nbsp;</span></span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"><span _fck_bookmark="1" style="display: none">&nbsp;</span></span></font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2010/08/erlang-otp%e4%b9%8bterminate-%e6%b7%b1%e5%85%a5%e5%88%86%e6%9e%90/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>erlang init stop浅析</title>
		<link>http://www.qingliangcn.com/2010/08/erlang-init-stop%e6%b5%85%e6%9e%90/</link>
		<comments>http://www.qingliangcn.com/2010/08/erlang-init-stop%e6%b5%85%e6%9e%90/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 11:01:09 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[erlang停止过程]]></category>
		<category><![CDATA[init]]></category>
		<category><![CDATA[stop]]></category>

		<guid isPermaLink="false">http://www.qingliangcn.com/?p=277</guid>
		<description><![CDATA[作者：庆亮 (qing.liang.cn@gmail.com) 日期：2010-08-03 &#160; &#160; boot之后关注的自然是stop，直接打开erts-5.7.5/src/init.erl源码看了看： &#160; -spec stop() -&#62; no_return(). stop() -&#62; init ! {stop,stop}, ok. {stop,Reason} -&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; stop(Reason,State); &#160; 最终的调用： stop(Reason,State) -&#62; &#160;&#160;&#160; BootPid = State#state.bootpid, &#160;&#160;&#160; {_,Progress} = State#state.status, &#160;&#160;&#160; State1 = State#state{status = {stopping, Progress}}, &#160;&#160;&#160; clear_system(BootPid,State1), &#160;&#160;&#160; do_stop(Reason,State1). &#160; 看看 clear_system/2： &#160; clear_system(BootPid,State) -&#62; &#160;&#160;&#160; Heart = get_heart(State#state.kernel), &#160;&#160;&#160;]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><b style="mso-bidi-font-weight: normal"><font color="#000000"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">作者：庆亮</span><span lang="EN-US"><font face="Calibri"> (qing.liang.cn@gmail.com)<o:p></o:p></font></span></font></font></b></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><b style="mso-bidi-font-weight: normal"><font color="#000000"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">日期：</span><span lang="EN-US"><font face="Calibri">2010-08-03<o:p></o:p></font></span></font></font></b></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><span lang="EN-US"><font face="Calibri">boot</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">之后关注的自然是</span><span lang="EN-US"><font face="Calibri">stop</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">，直接打开</span><span lang="EN-US"><font face="Calibri">erts-5.7.5/src/init.erl</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">源码看了看：</span></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">-</span><b><span lang="EN-US" style="font-family: consolas; color: #999999">spec</span></b><span lang="EN-US" style="font-family: consolas; color: black"> stop() </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"> no_return().<br />
	</span><span lang="EN-US" style="font-family: consolas; color: #00a000">stop</span><span lang="EN-US" style="font-family: consolas; color: black">() </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"> init </span><span lang="EN-US" style="font-family: consolas; color: #666666">!</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"> {stop,stop}, ok.</p>
<p>	{stop,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stop(</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">);<span id="more-277"></span><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas"><font size="3">最终的调用：</font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">stop</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state.bootpid</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,<br />
	&nbsp;&nbsp;&nbsp; {_,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Progress</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state.status</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State1</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state</span><span lang="EN-US" style="font-family: consolas; color: black">{status </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> {stopping, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Progress</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">}},<br />
	&nbsp;&nbsp;&nbsp; clear_system(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State1</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; do_stop(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State1</span><span lang="EN-US" style="font-family: consolas; color: black">).<o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">看看</span><span lang="EN-US"><font face="Calibri"> clear_system/2</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">：</span></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">clear_system</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Heart</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> get_heart(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state.kernel</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; shutdown_pids(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Heart</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; unload(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Heart</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">).<br />
	&nbsp;&nbsp;&nbsp; <br />
	</span><span lang="EN-US" style="font-family: consolas; color: #00a000">shutdown_pids</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Heart</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> shutdown_timer(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state.flags</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">catch</span></b><span lang="EN-US" style="font-family: consolas; color: black"> shutdown(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state.kernel</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; kill_all_pids(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Heart</span><span lang="EN-US" style="font-family: consolas; color: black">), </span><i><span lang="EN-US" style="font-family: consolas; color: #008800">% Even the shutdown timer.</span></i></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; kill_all_ports(</font></span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod"><font size="3">Heart</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; flush_timout(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">).<br />
	&nbsp;&nbsp;&nbsp; <br />
	</span><i><span lang="EN-US" style="font-family: consolas; color: #008800">%%</span></i></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	</span><i><span lang="EN-US" style="font-family: consolas; color: #008800"><font size="3">%% Kill all existing pids in the system (except init and heart).</font></span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
	</span><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">kill_all_pids</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Heart</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">case</span></b><span lang="EN-US" style="font-family: consolas; color: black"> get_pids(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Heart</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">of</span></b></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [] </font></span><span lang="EN-US" style="font-family: consolas; color: #666666"><font size="3">-&gt;</font></span><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pids</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kill_em(</font></span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod"><font size="3">Pids</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kill_all_pids(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Heart</span><span lang="EN-US" style="font-family: consolas; color: black">)&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: #008800">% Continue until all are really killed.</span></i></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff"><font size="3">end</font></span></b><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">.</p>
<p>
	</span><span lang="EN-US" style="font-family: consolas; color: #00a000">kill_em</span><span lang="EN-US" style="font-family: consolas; color: black">([</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">|</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pids</span><span lang="EN-US" style="font-family: consolas; color: black">]) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: #aa22ff">exit</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,kill),<br />
	&nbsp;&nbsp;&nbsp; kill_em(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pids</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">);<br />
	</span><span lang="EN-US" style="font-family: consolas; color: #00a000">kill_em</span><span lang="EN-US" style="font-family: consolas; color: black">([]) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; ok.<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">看到这里得到两个结论：</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoListParagraph" style="text-align: left; text-indent: -18pt; margin: 0cm 0cm 0pt 39pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1"><span lang="EN-US" style="font-family: consolas; color: black; mso-fareast-font-family: consolas; mso-bidi-font-family: consolas"><span style="mso-list: ignore"><font size="3">1．</font><span style="font: 7pt 'times new roman'"> </span></span></span><font size="3"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">除了</span><span lang="EN-US" style="font-family: consolas; color: black">kernel</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">和</span><span lang="EN-US" style="font-family: consolas; color: black">init</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">之外的所有的进程都是以</span><span lang="EN-US" style="font-family: consolas; color: black">kill</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">的形式干掉的。注意这里的</span><span lang="EN-US" style="font-family: consolas; color: black">kernel</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">是个</span><span lang="EN-US" style="font-family: consolas; color: black">list</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">，包含多了</span><span lang="EN-US" style="font-family: consolas; color: black">pid</span></font></p>
<p align="left" class="MsoListParagraph" style="text-align: left; text-indent: -18pt; margin: 0cm 0cm 0pt 39pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1"><span lang="EN-US" style="font-family: consolas; color: black; mso-fareast-font-family: consolas; mso-bidi-font-family: consolas"><span style="mso-list: ignore"><font size="3">2．</font><span style="font: 7pt 'times new roman'"> </span></span></span><font color="#000000"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">先</span><span lang="EN-US"><font face="Calibri">shutdown</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">所有的</span><span lang="EN-US"><font face="Calibri">kernel</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">进程，后</span><span lang="EN-US"><font face="Calibri">kill</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">掉其他进程，最终</span><span lang="EN-US"><font face="Calibri">halt</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">。</span><span lang="EN-US"><font face="Calibri">shutdown</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">的形式则是一条</span><span lang="EN-US"><font face="Calibri">EXIT</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">消息</span></font></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">shutdown</span><span lang="EN-US" style="font-family: consolas; color: black">([{heart,_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">}|</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Kernel</span><span lang="EN-US" style="font-family: consolas; color: black">],</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; shutdown(</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Kernel</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">);<br />
	</span><span lang="EN-US" style="font-family: consolas; color: #00a000">shutdown</span><span lang="EN-US" style="font-family: consolas; color: black">([{_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Name</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">}|</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Kernel</span><span lang="EN-US" style="font-family: consolas; color: black">],</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; shutdown_kernel_pid(</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; shutdown(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Kernel</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">);<br />
	</span><span lang="EN-US" style="font-family: consolas; color: #00a000">shutdown</span><span lang="EN-US" style="font-family: consolas; color: black">(_,_,_,_) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; true.</p>
<p>	</font></span><i><span lang="EN-US" style="font-family: consolas; color: #008800"><font size="3">%%</font></span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
	</span><i><span lang="EN-US" style="font-family: consolas; color: #008800"><font size="3">%% A kernel pid must handle the special case message</font></span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
	</span><i><span lang="EN-US" style="font-family: consolas; color: #008800"><font size="3">%% {&#39;EXIT&#39;,Parent,Reason} and terminate upon it!</font></span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
	</span><i><span lang="EN-US" style="font-family: consolas; color: #008800"><font size="3">%%</font></span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
	</span><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">shutdown_kernel_pid</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">!</span><span lang="EN-US" style="font-family: consolas; color: black"> {&#39;EXIT&#39;,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,shutdown},<br />
	&nbsp;&nbsp;&nbsp; shutdown_loop(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Timer</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">, []).<o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">发送</span><span lang="EN-US" style="font-family: consolas; color: black">EXIT</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">消息，</span><span lang="EN-US" style="font-family: consolas; color: black">shutdown_loop/4</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">等待结果。</span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">根据上一篇分析的结果，</span><span lang="EN-US"><font face="Calibri">application_controller</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">是</span><span lang="EN-US"><font face="Calibri">kernel pids</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">的一员，查看</span><span lang="EN-US"><font face="Calibri">application_controller</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">的源码：</span></font></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">terminate</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span><span lang="EN-US" style="font-family: consolas; color: black">, S) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">case</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><b><span lang="EN-US" style="font-family: consolas; color: blue">application</span></b><span lang="EN-US" style="font-family: consolas; color: black">:get_env(kernel, shutdown_func) </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">of</span></b></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; {ok, {</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">M</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">F</span><span lang="EN-US" style="font-family: consolas; color: black">}} </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font size="3"><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">catch</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">M</span><span lang="EN-US" style="font-family: consolas; color: black">:</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">F</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Reason</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">);<br />
	&nbsp;&nbsp;&nbsp; _ </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok<br />
	&nbsp;&nbsp;&nbsp; </font></span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff"><font size="3">end</font></span></b><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,<br />
	&nbsp;&nbsp;&nbsp; foreach(</span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">fun</span></b><span lang="EN-US" style="font-family: consolas; color: black">({_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">AppName</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Id</span><span lang="EN-US" style="font-family: consolas; color: black">}) </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">when</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">is_pid</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Id</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"> <br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">exit</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Id</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">, shutdown),<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">receive</span></b></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#39;EXIT&#39;, </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Id</span><span lang="EN-US" style="font-family: consolas; color: black">, _} </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"> ok<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">end</span></b></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (_) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"> ok<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">end</span></b></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state.running</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	</span><b><span lang="EN-US" style="font-family: consolas; color: blue">ets</span></b><span lang="EN-US" style="font-family: consolas; color: black">:delete(ac_tab).<o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">S</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state.running</span><font color="#000000"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">中保存了所有已经在运行的</span><span lang="EN-US"><font face="Calibri">application</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">，对于每一个</span><span lang="EN-US"><font face="Calibri">application</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">，都以</span></font><span lang="EN-US" style="font-family: consolas; color: #aa22ff">exit</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Id</span><span lang="EN-US" style="font-family: consolas; color: black">, shutdown)</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">形式让其退出，并一直等待。</span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; text-indent: 9pt; margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin"><font color="#000000" size="3">到了这里不用继续看源码大致也能理清思路了，结论：</font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><b style="mso-bidi-font-weight: normal"><span lang="EN-US"><font face="Calibri"><font size="3"><font color="#000000">init:stop<span style="mso-spacerun: yes">&nbsp; </span><o:p></o:p></font></font></font></span></b></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><font color="#000000"><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">&rarr;</span><span lang="EN-US"><span style="mso-spacerun: yes"><font face="Calibri">&nbsp; </font></span></span></b><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">向所有</span><span lang="EN-US"><font face="Calibri">kernel</font></span></b><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">进程发送</span><span lang="EN-US"><font face="Calibri">shutdown Exit</font></span></b><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">消息</span><font face="Calibri"> <span lang="EN-US"><o:p></o:p></span></font></b></font></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><font color="#000000"><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">&rarr;</span><span lang="EN-US"><font face="Calibri"> application </font></span></b><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">依次关闭子</span><span lang="EN-US"><font face="Calibri">sup</font></span></b><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">树（等待）</span><span lang="EN-US"><o:p></o:p></span></b></font></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><font color="#000000"><b style="mso-bidi-font-weight: normal"><span lang="EN-US"><span style="mso-spacerun: yes"><font face="Calibri">&nbsp;</font></span></span></b><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">&rarr;</span><span lang="EN-US"><font face="Calibri"> kill</font></span></b><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">所有其他的非</span><span lang="EN-US"><font face="Calibri">kernel</font></span></b><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">进程</span><span lang="EN-US"><o:p></o:p></span></b></font></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><font color="#000000"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">对于我们的</span><span lang="EN-US"><font face="Calibri">app</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">，一般都是最后启动，最先停止，如此，在停止我们的</span><span lang="EN-US"><font face="Calibri">app</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">的时候所有的系统服务都还是可用的（分布式、</span><span lang="EN-US"><font face="Calibri">mnesia</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">等等）。</span></font></font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2010/08/erlang-init-stop%e6%b5%85%e6%9e%90/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>erlang init boot 浅析</title>
		<link>http://www.qingliangcn.com/2010/08/init-boot-%e6%b5%85%e6%9e%90/</link>
		<comments>http://www.qingliangcn.com/2010/08/init-boot-%e6%b5%85%e6%9e%90/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 09:43:37 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[boot]]></category>
		<category><![CDATA[init]]></category>
		<category><![CDATA[启动过程]]></category>

		<guid isPermaLink="false">http://www.qingliangcn.com/?p=274</guid>
		<description><![CDATA[说明：遇到一个OTP的问题，疑惑了很久，也就有了这篇文章。 目的：跟踪Erlang的启动过程 &#160; 参考这里 http://erlangdisplay.javaeye.com/blog/315497 ，直接从erts-5.7.5/src/init.erl 的boot/1函数开始（关于这个链接给出的结论以后会继续研究分析）： &#160; -spec boot([binary()]) -&#62; no_return(). boot(BootArgs) -&#62; &#160;&#160;&#160; register(init, self()), &#160;&#160;&#160; process_flag(trap_exit, true), &#160;&#160;&#160; start_on_load_handler_process(), &#160;&#160;&#160; {Start0,Flags,Args} = parse_boot_args(BootArgs), &#160;&#160;&#160; Start = map(fun prepare_run_args/1, Start0), &#160;&#160;&#160; Flags0 = flags_to_atoms_again(Flags), &#160;&#160;&#160; boot(Start,Flags0,Args). &#160; do_boot(Init,Flags,Start) -&#62; &#160;&#160;&#160; process_flag(trap_exit,true), &#160;&#160;&#160; {Pgm0,Nodes,Id,Path} = prim_load_flags(Flags), &#160;&#160;&#160; Root = b2s(get_flag(&#39;-root&#39;,Flags)), &#160;&#160;&#160; PathFls = path_flags(Flags),]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">说明：</span></b><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">遇到一个</span><span lang="EN-US"><font face="Calibri">OTP</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">的问题，疑惑了很久，也就有了这篇文章。</span></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font color="#000000"><font size="3"><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">目的：</span></b><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">跟踪</span><span lang="EN-US"><font face="Calibri">Erlang</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">的启动过程</span></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font size="3"><font color="#000000"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">参考这里</span><font face="Calibri"> </font></font><span lang="EN-US"><a href="http://erlangdisplay.javaeye.com/blog/315497"><font color="#800080" face="Calibri">http://erlangdisplay.javaeye.com/blog/315497</font></a><font color="#000000" face="Calibri"> </font></span><font color="#000000"><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">，直接从</span><span lang="EN-US"><font face="Calibri">erts-5.7.5/src/init.erl </font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">的</span><span lang="EN-US"><font face="Calibri">boot/1</font></span><span style="font-family: 宋体; mso-ascii-font-family: calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: calibri; mso-hansi-theme-font: minor-latin">函数开始（关于这个链接给出的结论以后会继续研究分析）：</span></font></font></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span id="more-274"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span lang="EN-US"><o:p><font color="#000000" face="Calibri" size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">-</span><b><span lang="EN-US" style="font-family: consolas; color: #999999">spec</span></b><span lang="EN-US" style="font-family: consolas; color: black"> boot([binary()]) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"> no_return().<br />
	</span><span lang="EN-US" style="font-family: consolas; color: #00a000">boot</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootArgs</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><span lang="EN-US" style="font-family: consolas; color: #aa22ff"><font size="3">register</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">(init, self()),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">process_flag</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">(trap_exit, true),<br />
	&nbsp;&nbsp;&nbsp; start_on_load_handler_process(),<br />
	&nbsp;&nbsp;&nbsp; {</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Start0</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> parse_boot_args(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootArgs</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Start</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> map(</span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">fun</span></b><span lang="EN-US" style="font-family: consolas; color: black"> prepare_run_args</span><span lang="EN-US" style="font-family: consolas; color: #666666">/1</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Start0</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags0</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> flags_to_atoms_again(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; boot(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Start</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags0</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span><span lang="EN-US" style="font-family: consolas; color: black">).<o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">do_boot</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Start</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><span lang="EN-US" style="font-family: consolas; color: #aa22ff"><font size="3">process_flag</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">(trap_exit,true),<br />
	&nbsp;&nbsp;&nbsp; {</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pgm0</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Nodes</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Id</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Path</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> prim_load_flags(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Root</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> b2s(get_flag(&#39;-root&#39;,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">)),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">PathFls</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> path_flags(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pgm</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> b2s(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pgm0</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; _</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> start_prim_loader(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span><span lang="EN-US" style="font-family: consolas; color: black">,b2a(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Id</span><span lang="EN-US" style="font-family: consolas; color: black">),</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pgm</span><span lang="EN-US" style="font-family: consolas; color: black">,bs2as(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Nodes</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bs2ss(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Path</span><span lang="EN-US" style="font-family: consolas; color: black">),</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">PathFls</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootFile</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> bootfile(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Root</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootList</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> get_boot(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootFile</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Root</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">LoadMode</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> b2a(get_flag(&#39;-mode&#39;,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,false)),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Deb</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> b2a(get_flag(&#39;-init_debug&#39;,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,false)),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootVars</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> get_flag_args(&#39;-boot_var&#39;,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Flags</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">ParallelLoad</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"> <br />
	&nbsp;&nbsp;&nbsp; (</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pgm</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black">:</span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #bb4444">&quot;efile&quot;</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">and</span></b><span lang="EN-US" style="font-family: consolas; color: black"> (</span><b><span lang="EN-US" style="font-family: consolas; color: blue">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black">:</span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">system_info</span><span lang="EN-US" style="font-family: consolas; color: black">(thread_pool_size) </span><span lang="EN-US" style="font-family: consolas; color: #666666">&gt;</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">0</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),</p>
<p>	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">PathChoice</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"> code_path_choice(),<br />
	&nbsp;&nbsp;&nbsp; eval_script(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootList</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">PathFls</span><span lang="EN-US" style="font-family: consolas; color: black">,{</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Root</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootVars</span><span lang="EN-US" style="font-family: consolas; color: black">},</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Path</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {true,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">LoadMode</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">ParallelLoad</span><span lang="EN-US" style="font-family: consolas; color: black">},</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Deb</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">PathChoice</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),</p>
<p>	&nbsp;&nbsp;&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: #008800">%% To help identifying Purify windows that pop up,</span></i></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><i><span lang="EN-US" style="font-family: consolas; color: #008800"><font size="3">%% print the node name into the Purify log.</font></span></i><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; (</font></span><font size="3"><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">catch</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><b><span lang="EN-US" style="font-family: consolas; color: blue">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black">:</span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">system_info</span><span lang="EN-US" style="font-family: consolas; color: black">({purify, </span><span lang="EN-US" style="font-family: consolas; color: #bb4444">&quot;Node: &quot;</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">++</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">atom_to_list</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">node</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">())})),</p>
<p>	&nbsp;&nbsp;&nbsp; start_em(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Start</span><span lang="EN-US" style="font-family: consolas; color: black">).<o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">boot/3</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">的基本流程为</span><span style="font-family: consolas; color: black"> <span lang="EN-US">start_prim_loader/6 </span></span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">&rarr;</span><span lang="EN-US" style="font-family: consolas; color: black"> eval_script/8 </span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">&rarr;</span><span style="font-family: consolas; color: black"> <span lang="EN-US">start_em/1<o:p></o:p></span></span></font></p>
<p align="left" class="MsoListParagraph" style="text-align: left; text-indent: -18pt; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1"><span lang="EN-US" style="font-family: consolas; color: black; mso-fareast-font-family: consolas; mso-bidi-font-family: consolas"><span style="mso-list: ignore"><font size="3">1．</font><span style="font: 7pt 'times new roman'"> </span></span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">start_prim_loader/6</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">启动了</span><span lang="EN-US" style="font-family: consolas; color: black">erl_prim_loader</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">模块，负责代码加载（远程或者本地等）</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoListParagraph" style="text-align: left; text-indent: -18pt; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1"><span lang="EN-US" style="font-family: consolas; color: black; mso-fareast-font-family: consolas; mso-bidi-font-family: consolas"><span style="mso-list: ignore"><font size="3">2．</font><span style="font: 7pt 'times new roman'"> </span></span></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">eval_script/8 </span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">负责启动一些关键的进程</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">来看个</span><span lang="EN-US" style="font-family: consolas; color: black">eval_script/8</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">参数的例子：</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">{[{preLoaded,[erl_prim_loader,erlang,init,otp_ring0,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>prim_file,prim_inet,prim_zip,zlib]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{progress,preloaded},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{path,[&quot;$ROOT/lib/kernel-2.13.5/ebin&quot;,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&quot;$ROOT/lib/stdlib-1.16.5/ebin&quot;]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{primLoad,[error_handler]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{kernel_load_completed},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{progress,kernel_load_completed},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{path,[&quot;$ROOT/lib/kernel-2.13.5/ebin&quot;]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{primLoad,[application,application_controller,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>application_master,application_starter,auth,code,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>code_server,disk_log,disk_log_1,disk_log_server,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>disk_log_sup,dist_ac,dist_util,erl_boot_server,erl_ddll,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>erl_distribution,erl_epmd,erl_reply|...]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{path,[&quot;$ROOT/lib/stdlib-1.16.5/ebin&quot;]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{primLoad,[array,base64,beam_lib,c,calendar,dets,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dets_server,dets_sup,dets_utils,dets_v8,dets_v9,dict,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>digraph,digraph_utils,edlin,edlin_expand|...]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{progress,modules_loaded},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{path,[&quot;$ROOT/lib/kernel-2.13.5/ebin&quot;,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&quot;$ROOT/lib/stdlib-1.16.5/ebin&quot;]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{kernelProcess,heart,{heart,start,[]}},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{kernelProcess,error_logger,{error_logger,start_link,[]}},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{kernelProcess,application_controller,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{application_controller,start,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>[{application,kernel,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>[{description,[...]},{vsn,&#8230;},{&#8230;}|&#8230;]}]}},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{progress,init_kernel_started},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{apply,{application,load,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>[{application,stdlib,[{description,...},{...}|...]}]}},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{progress,applications_loaded},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{apply,{application,start_boot,[kernel,permanent]}},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{apply,{application,start_boot,[stdlib,permanent]}},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{apply,{c,erlangrc,[]}},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{progress,started}],<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;</span>&lt;0.0.0&gt;,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;</span>{[],[]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;</span>{&quot;/usr/local/lib/erlang&quot;,[]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;</span>false,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;</span>{true,false,false},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;</span>false,relaxed}<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">查看</span><span lang="EN-US" style="font-family: consolas; color: black">eval_script/8</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">的实现（代码就不贴了），发现启动了上面参数中</span><span style="font-family: consolas; color: black"> <span lang="EN-US">kernelProcess</span></span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">对应键值的进程，如：</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">{kernelProcess,heart,{heart,start,[]}},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{kernelProcess,error_logger,{error_logger,start_link,[]}},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp; </span>{kernelProcess,application_controller,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun: yes">&nbsp;</span>{application_controller,start,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>[{application,kernel,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">eval_script</span><span lang="EN-US" style="font-family: consolas; color: black">([{kernelProcess,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Server</span><span lang="EN-US" style="font-family: consolas; color: black">,{</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Mod</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Fun</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span><span lang="EN-US" style="font-family: consolas; color: black">}}|</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">CfgL</span><span lang="EN-US" style="font-family: consolas; color: black">],</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">PathFs</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Vars</span><span lang="EN-US" style="font-family: consolas; color: black">,P,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Ph</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Deb</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">PathChoice</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; debug(</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Deb</span><span lang="EN-US" style="font-family: consolas; color: black">,{start,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Server</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">}),<br />
	&nbsp;&nbsp;&nbsp; start_in_kernel(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Server</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Mod</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Fun</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; eval_script(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">CfgL</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">PathFs</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Vars</span><span lang="EN-US" style="font-family: consolas; color: black">,P,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Ph</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Deb</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">PathChoice</span><span lang="EN-US" style="font-family: consolas; color: black">);<o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">start_in_kernel</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Server</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Mod</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Fun</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Res</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">apply</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Mod</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Fun</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Args</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">!</span><span lang="EN-US" style="font-family: consolas; color: black"> {self(),started,{</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Server</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Res</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">}},<br />
	&nbsp;&nbsp;&nbsp; </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">receive</span></b></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; {</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span><span lang="EN-US" style="font-family: consolas; color: black">,ok,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">} </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: #aa22ff">unlink</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">),&nbsp; </span><i><span lang="EN-US" style="font-family: consolas; color: #008800">%% Just for sure&#8230;</span></i></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok;<br />
	&nbsp;&nbsp;&nbsp; {</font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span><span lang="EN-US" style="font-family: consolas; color: black">,ignore} </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ignore<br />
	&nbsp;&nbsp;&nbsp; </font></span><font size="3"><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">end</span></b><span lang="EN-US" style="font-family: consolas; color: black">.<o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">最终产生一条消息给</span><span lang="EN-US" style="font-family: consolas; color: black">init</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">：</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Init</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">!</span><span lang="EN-US" style="font-family: consolas; color: black"> {self(),started,{</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Server</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Res</span></font><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">}},<br style="mso-special-character: line-break" /><br />
	<br style="mso-special-character: line-break" /><br />
	<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">{BootPid,started,KernelPid} -&gt;<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>boot_loop(BootPid, new_kernelpid(KernelPid, BootPid, State));<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">init</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">收到消息后，就将该进程加入到</span><span lang="EN-US" style="font-family: consolas; color: black">kernel pids</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">的队列中了。</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: #00a000">new_kernelpid</span><span lang="EN-US" style="font-family: consolas; color: black">({</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Name</span><span lang="EN-US" style="font-family: consolas; color: black">,{ok,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">}},</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><b><span lang="EN-US" style="font-family: consolas; color: #aa22ff">when</span></b><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">is_pid</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: #aa22ff">link</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">!</span><span lang="EN-US" style="font-family: consolas; color: black"> {self(),ok,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">},<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Kernel</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state.kernel</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">,<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: #a0a000">#state</span><span lang="EN-US" style="font-family: consolas; color: black">{kernel </span><span lang="EN-US" style="font-family: consolas; color: #666666">=</span><span lang="EN-US" style="font-family: consolas; color: black"> [{</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Name</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Pid</span><span lang="EN-US" style="font-family: consolas; color: black">}|</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Kernel</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">]};<br />
	</span><span lang="EN-US" style="font-family: consolas; color: #00a000">new_kernelpid</span><span lang="EN-US" style="font-family: consolas; color: black">({_</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Name</span><span lang="EN-US" style="font-family: consolas; color: black">,ignore},</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black"> </span><span lang="EN-US" style="font-family: consolas; color: #666666">!</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black"> {self(),ignore},<br />
	&nbsp;&nbsp;&nbsp; </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">;<br />
	</span><span lang="EN-US" style="font-family: consolas; color: #00a000">new_kernelpid</span><span lang="EN-US" style="font-family: consolas; color: black">({</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Name</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">What</span><span lang="EN-US" style="font-family: consolas; color: black">},</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span><span lang="EN-US" style="font-family: consolas; color: black">) </span><span lang="EN-US" style="font-family: consolas; color: #666666">-&gt;</span></font><span lang="EN-US" style="font-family: consolas; color: black"><br />
	<font size="3">&nbsp;&nbsp;&nbsp; </font></span><font size="3"><b><span lang="EN-US" style="font-family: consolas; color: blue">erlang</span></b><span lang="EN-US" style="font-family: consolas; color: black">:</span><span lang="EN-US" style="font-family: consolas; color: #aa22ff">display</span><span lang="EN-US" style="font-family: consolas; color: black">({</span><span lang="EN-US" style="font-family: consolas; color: #bb4444">&quot;could not start kernel pid&quot;</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Name</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">What</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">}),<br />
	&nbsp;&nbsp;&nbsp; clear_system(</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">BootPid</span><span lang="EN-US" style="font-family: consolas; color: black">,</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">State</span></font><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">),<br />
	&nbsp;&nbsp;&nbsp; crash(</span><span lang="EN-US" style="font-family: consolas; color: #bb4444">&quot;could not start kernel pid&quot;</span><span lang="EN-US" style="font-family: consolas; color: black">, [</span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">Name</span><span lang="EN-US" style="font-family: consolas; color: black">, </span><span lang="EN-US" style="font-family: consolas; color: darkgoldenrod">What</span><span lang="EN-US" style="font-family: consolas; color: black">]).</span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">{kernelProcess,application_controller,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{application_controller,start,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>[{application,kernel,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span lang="EN-US" style="font-family: consolas; color: black">application_controller</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">启动后会启动</span><span lang="EN-US" style="font-family: consolas; color: black">kernel app</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">，至此</span><span lang="EN-US" style="font-family: consolas; color: black">erlang</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">的启动过程就大致的有个了解了，而关于</span><span lang="EN-US" style="font-family: consolas; color: black">application</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">的启动过程就不在本次分析范围之内了。</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">结论：</span></b><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></b></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">系统从</span><span lang="EN-US" style="font-family: consolas; color: black">init&lt;0.0.0&gt;</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">开始，一些关键的进程如：</span><span lang="EN-US" style="font-family: consolas; color: black">error_logger</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">、</span><span lang="EN-US" style="font-family: consolas; color: black">application_controller</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">、</span><span lang="EN-US" style="font-family: consolas; color: black">erl_prim_load</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">等都会预先启动并加入到</span><span lang="EN-US" style="font-family: consolas; color: black">kernel pids</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">中。</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><b style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">附言：</span></b><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></b></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">本次跟踪自然又离不开余锋老大</span><span lang="EN-US" style="font-family: consolas; color: black">(</span><span lang="EN-US"><a href="http://blog.yufeng.info/"><span style="font-family: consolas"><font color="#800080">http://blog.yufeng.info/</font></span></a></span><span lang="EN-US" style="font-family: consolas; color: black"> )</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">的指点，</span><span lang="EN-US" style="font-family: consolas; color: black">init.erl</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">是</span><span lang="EN-US" style="font-family: consolas; color: black">preloaded</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">模块：</span><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></font></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3">{preLoaded,[erl_prim_loader,erlang,init,otp_ring0,<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><font size="3"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>prim_file,prim_inet,prim_zip,zlib]},<o:p></o:p></font></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><span lang="EN-US" style="font-family: consolas; color: black"><o:p><font size="3">&nbsp;</font></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">而由于本文之前的无知，导致我去尝试修改</span><span lang="EN-US" style="font-family: consolas; color: black">init.erl</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">。</span><span style="font-family: consolas; color: black"> </span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">如果大家需要跟踪</span><span lang="EN-US" style="font-family: consolas; color: black">init.erl</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">的启动细节，需要修改源码包中的</span><span lang="EN-US" style="font-family: consolas; color: black"> erts/preloaded/src/init.erl</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">、</span><span lang="EN-US" style="font-family: consolas; color: black">make &amp;&amp; make install</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">，由于此时系统还没跑起来，所以</span><span lang="EN-US" style="font-family: consolas; color: black">error_logger io</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">之类的模块是没有用的，幸运的是</span><span lang="EN-US" style="font-family: consolas; color: black">preloaded</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">里面有</span><span lang="EN-US" style="font-family: consolas; color: black"> prim_file</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">，可以通过</span><span lang="EN-US" style="font-family: consolas; color: black"> prim_file:write_file/2</span><span style="font-family: 宋体; color: black; mso-ascii-font-family: consolas; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: consolas">把一些状态写入到文件中以便查看。</span></font><span lang="EN-US" style="font-family: consolas; color: black"><o:p></o:p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2010/08/init-boot-%e6%b5%85%e6%9e%90/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>erlang shell web版</title>
		<link>http://www.qingliangcn.com/2010/08/erlang-shell-web%e7%89%88/</link>
		<comments>http://www.qingliangcn.com/2010/08/erlang-shell-web%e7%89%88/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 01:50:12 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>

		<guid isPermaLink="false">http://www.qingliangcn.com/?p=267</guid>
		<description><![CDATA[http://www.tryerlang.org/]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tryerlang.org/">http://www.tryerlang.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2010/08/erlang-shell-web%e7%89%88/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R13B04的Emacs erlang-mode</title>
		<link>http://www.qingliangcn.com/2010/05/r13b04%e7%9a%84emacs-erlang-mode/</link>
		<comments>http://www.qingliangcn.com/2010/05/r13b04%e7%9a%84emacs-erlang-mode/#comments</comments>
		<pubDate>Fri, 21 May 2010 03:55:50 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[erlang-mode]]></category>

		<guid isPermaLink="false">http://www.qingliangcn.com/?p=260</guid>
		<description><![CDATA[R13B04的Emacs erlang-mode在编译后少了几个文件，默认%erlang_root%/lib/tools-2.6.5.1/emacs下有如下文件： &#160; -rw-r&#8211;r&#8211; 1 root root 183741 2010-05-21 11:43 erlang.el -rw-r&#8211;r&#8211; 1 root root &#160;10059 2010-05-21 11:43 erlang-eunit.el -rw-r&#8211;r&#8211; 1 root root &#160; 3452 2010-05-21 11:43 erlang-start.el -rw-r&#8211;r&#8211; 1 root root &#160; 1611 2010-05-21 11:43 README -rw-r&#8211;r&#8211; 1 root root &#160;12834 2010-05-21 11:43 test.erl.indented -rw-r&#8211;r&#8211; 1 root root &#160;11877 2010-05-21 11:43 test.erl.orig 直接在emacs中配置指向这里的话，会无法正常使用erlang-mode： (setq]]></description>
			<content:encoded><![CDATA[<p>R13B04的Emacs erlang-mode在编译后少了几个文件，默认%erlang_root%/lib/tools-2.6.5.1/emacs下有如下文件：</p>
<p>&nbsp;</p>
<p>-rw-r&#8211;r&#8211; 1 root root 183741 2010-05-21 11:43 erlang.el</p>
<p>-rw-r&#8211;r&#8211; 1 root root &nbsp;10059 2010-05-21 11:43 erlang-eunit.el</p>
<p>-rw-r&#8211;r&#8211; 1 root root &nbsp; 3452 2010-05-21 11:43 erlang-start.el</p>
<p>-rw-r&#8211;r&#8211; 1 root root &nbsp; 1611 2010-05-21 11:43 README</p>
<p>-rw-r&#8211;r&#8211; 1 root root &nbsp;12834 2010-05-21 11:43 test.erl.indented</p>
<p>-rw-r&#8211;r&#8211; 1 root root &nbsp;11877 2010-05-21 11:43 test.erl.orig</p>
<div>直接在emacs中配置指向这里的话，会无法正常使用erlang-mode：</div>
<div>
<div><meta content="text/html; charset=utf-8" http-equiv="content-type" /></p>
<div>(setq load-path (cons &quot;/usr/local/erlang/lib/tools-2.6.5.1/emacs&quot; load-path))</div>
<div>&nbsp;</div>
<div>需要拷贝源代码目录中的emacs el文件过来，拷贝后如下：</div>
<div>
<div>-r-xr-xr-x 1 root root &nbsp;45795 2010-05-21 11:54 erlang_appwiz.el*</div>
<div>-rw-r&#8211;r&#8211; 1 root root 183741 2010-05-21 11:54 erlang.el</div>
<div>-rw-r&#8211;r&#8211; 1 root root &nbsp;10059 2010-05-21 11:54 erlang-eunit.el</div>
<div>-r-xr-xr-x 1 root root &nbsp;55313 2010-05-21 11:54 erlang-skels.el*</div>
<div>-r-xr-xr-x 1 root root &nbsp;48006 2010-05-21 11:54 erlang-skels-old.el*</div>
<div>-rw-r&#8211;r&#8211; 1 root root &nbsp; 3452 2010-05-21 11:54 erlang-start.el</div>
<div>-rw-r&#8211;r&#8211; 1 root root &nbsp; 1611 2010-05-21 11:43 README</div>
<div>-rw-r&#8211;r&#8211; 1 root root &nbsp;12834 2010-05-21 11:43 test.erl.indented</div>
<div>-rw-r&#8211;r&#8211; 1 root root &nbsp;11877 2010-05-21 11:43 test.erl.orig</div>
</p></div>
</p></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2010/05/r13b04%e7%9a%84emacs-erlang-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mnesia脏读与事物读性能结果</title>
		<link>http://www.qingliangcn.com/2010/05/mnesia%e8%84%8f%e8%af%bb%e4%b8%8e%e4%ba%8b%e7%89%a9%e8%af%bb%e6%80%a7%e8%83%bd%e7%bb%93%e6%9e%9c/</link>
		<comments>http://www.qingliangcn.com/2010/05/mnesia%e8%84%8f%e8%af%bb%e4%b8%8e%e4%ba%8b%e7%89%a9%e8%af%bb%e6%80%a7%e8%83%bd%e7%bb%93%e6%9e%9c/#comments</comments>
		<pubDate>Thu, 13 May 2010 04:13:26 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[mnesia]]></category>
		<category><![CDATA[事务]]></category>
		<category><![CDATA[脏读]]></category>

		<guid isPermaLink="false">http://www.qingliangcn.com/?p=252</guid>
		<description><![CDATA[一直知道mnesia的事务比较慢，但慢到什么程度却没有一个数值的概念，今天正好有空测试一下。 上代码： -module(mnesia_read_test). -export([start/0, init_data/0, start2/0]). -record(r_test, {id, name}). start() -&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#160; statistics(wall_clock), &#160;&#160;&#160; statistics(runtime), &#160; &#160;&#160;&#160;&#160;&#160;&#160;read(), &#160;&#160;&#160;&#160;&#160;&#160;&#160; {_, Time1} = statistics(wall_clock), &#160;&#160;&#160; {_, Time2} = statistics(runtime), &#160;&#160;&#160; io:format(&#34;times:~p, wall_clock ~p, runtime:~p&#34;, [100000, Time1, Time2]). &#160; start2() -&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#160; statistics(wall_clock), &#160;&#160;&#160; statistics(runtime), &#160;&#160;&#160;&#160;&#160;&#160;&#160; read2(), &#160;&#160;&#160;&#160;&#160;&#160;&#160; {_, Time1} = statistics(wall_clock), &#160;&#160;&#160; {_, Time2} = statistics(runtime), &#160;&#160;&#160;]]></description>
			<content:encoded><![CDATA[<p>一直知道mnesia的事务比较慢，但慢到什么程度却没有一个数值的概念，今天正好有空测试一下。</p>
<p>上代码：</p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">-module(mnesia_read_test)</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue;<br />
mso-font-kerning:0pt">.</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">-export([start/</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;<br />
mso-font-kerning:0pt">0</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">, init_data/</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;<br />
mso-font-kerning:0pt">0</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">, start2/</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;<br />
mso-font-kerning:0pt">0</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">])</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue;<br />
mso-font-kerning:0pt">.</span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">-record(r_test, {id, name})</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue;<br />
mso-font-kerning:0pt">.</span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">start() -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>statistics(wall_clock), </span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>statistics(runtime),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>read(),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">_</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">Time1</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">} = statistics(wall_clock),</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>{</span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">_</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">, </span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">Time2</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">} = statistics(runtime),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>io:format(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:rosybrown;mso-font-kerning:<br />
0pt">&quot;times:~p, wall_clock ~p, runtime:~p&quot;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:<br />
0pt">, [</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:#5A5AB4;mso-font-kerning:0pt">100000</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:<br />
0pt">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:darkgoldenrod;mso-font-kerning:0pt">Time1</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:<br />
0pt">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:darkgoldenrod;mso-font-kerning:0pt">Time2</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:<br />
0pt">])</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:blue;mso-font-kerning:0pt">.</span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p>&nbsp;<span id="more-252"></span></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">start2() -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>statistics(wall_clock),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>statistics(runtime),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>read2(),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">_</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">Time1</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">} = statistics(wall_clock),</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>{</span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">_</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">, </span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">Time2</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">} = statistics(runtime),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>io:format(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:rosybrown;mso-font-kerning:<br />
0pt">&quot;times:~p, wall_clock ~p, runtime:~p&quot;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:<br />
0pt">, [</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:#5A5AB4;mso-font-kerning:0pt">100000</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:<br />
0pt">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:darkgoldenrod;mso-font-kerning:0pt">Time1</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:<br />
0pt">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:darkgoldenrod;mso-font-kerning:0pt">Time2</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:<br />
0pt">])</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:blue;mso-font-kerning:0pt">.</span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p>&nbsp;</o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">read() -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>dirty_read(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;mso-font-kerning:<br />
0pt">100000</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:black;mso-font-kerning:0pt">)</span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;color:blue;mso-font-kerning:0pt">.</span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">dirty_read(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;<br />
mso-font-kerning:0pt">0</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">) -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>ok;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">dirty_read(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">) -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>mnesia:dirty_read(r_test, </span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>dirty_read(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">-</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;<br />
mso-font-kerning:0pt">1</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">)</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue;<br />
mso-font-kerning:0pt">.</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p>&nbsp;</o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">read2() -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>t_read(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;mso-font-kerning:<br />
0pt">100000</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:black;mso-font-kerning:0pt">)</span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;color:blue;mso-font-kerning:0pt">.</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p>&nbsp;</o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">t_read(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;mso-font-kerning:<br />
0pt">0</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:black;mso-font-kerning:0pt">) -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ok;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">t_read(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">) -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>mnesia:transaction( </span><b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#A020F0;<br />
mso-font-kerning:0pt">fun</span></b><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">() -&gt; mnesia:read(r_test, </span><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">) </span><b><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:#A020F0;mso-font-kerning:0pt">end</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">),</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>t_read(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">-</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;<br />
mso-font-kerning:0pt">1</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">)</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:blue;<br />
mso-font-kerning:0pt">.</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p>&nbsp;</o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">init_data() -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>mnesia:stop(),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>mnesia:create_schema([node()]),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>mnesia:start(),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>mnesia:create_table(r_test, [</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{attributes, record_info(fields, r_test)},</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{record_name, r_test},</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{disc_copies, [node()]}</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>]),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>mnesia:transaction(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#A020F0;mso-font-kerning:<br />
0pt">fun</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:black;mso-font-kerning:0pt">() -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>t_write(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;mso-font-kerning:<br />
0pt">10000</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:black;mso-font-kerning:0pt">)</span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#A020F0;mso-font-kerning:<br />
0pt">end</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>)</span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;color:blue;mso-font-kerning:0pt">.</span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">t_write(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:#5A5AB4;<br />
mso-font-kerning:0pt">0</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">) -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>ok;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">t_write(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">) -&gt;</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span></span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">Name</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt"> = lists:append([</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:rosybrown;mso-font-kerning:<br />
0pt">&quot;name_&quot;</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">]),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span></span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">R</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt"> = #r_test{id=</span><span lang="EN-US" style="font-size:<br />
10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">, name=</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">Name</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">},</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;mso-font-kerning:0pt"><o:p></o:p></span></span></font></p>
<p align="left" class="MsoNormal" style="text-align:left;mso-layout-grid-align:<br />
none;text-autospace:none"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>mnesia:write(</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:darkgoldenrod;<br />
mso-font-kerning:0pt">R</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:black;mso-font-kerning:0pt">),</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;mso-font-kerning:<br />
0pt"><o:p></o:p></span></span></font></p>
<p class="MsoNormal"><font class="Apple-style-span" color="#000000" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;<br />
color:black;mso-font-kerning:0pt"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>t_write(</span><span lang="EN-US" style="font-size:10.0pt;font-family:<br />
&quot;Courier New&quot;;color:darkgoldenrod;mso-font-kerning:0pt">N</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">-</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:#5A5AB4;mso-font-kerning:0pt">1</span><span lang="EN-US" style="font-size:10.0pt;font-family:&quot;Courier New&quot;;color:black;<br />
mso-font-kerning:0pt">)</span><span lang="EN-US" style="font-size:10.0pt;<br />
font-family:&quot;Courier New&quot;;color:blue;mso-font-kerning:0pt">.</span></span></font></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">两种情况都循环读了10W次，连续测试10次，机器配置为：</p>
<p class="MsoNormal">Intel(R) Xeon(R) CPU &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; E5420 &nbsp;@ 2.50GHz &nbsp; &nbsp; &nbsp;2*4核</p>
<p class="MsoNormal">12G内存</p>
<p class="MsoNormal">事务读测试结果：</p>
<p class="MsoNormal">times:100000, wall_clock 4168, runtime:4160ok</p>
<p class="MsoNormal">times:100000, wall_clock 4296, runtime:4250ok</p>
<p class="MsoNormal">times:100000, wall_clock 4338, runtime:4290ok</p>
<p class="MsoNormal">times:100000, wall_clock 4310, runtime:4260ok</p>
<p class="MsoNormal">times:100000, wall_clock 4330, runtime:4280ok</p>
<p class="MsoNormal">times:100000, wall_clock 4342, runtime:4270ok</p>
<p class="MsoNormal">times:100000, wall_clock 4399, runtime:4310ok</p>
<p class="MsoNormal">times:100000, wall_clock 4366, runtime:4310ok</p>
<p class="MsoNormal">times:100000, wall_clock 4378, runtime:4310ok</p>
<p class="MsoNormal">times:100000, wall_clock 4429, runtime:4330ok</p>
<p class="MsoNormal"><span style="color:#f00;">一次读的时间大于为44us，这还是在没有分布式的情况下的测试结果，如果是在分布式环境中，由于网络IO和远程加锁，性能会更差。</span></p>
<p class="MsoNormal">脏读测试结果：</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">times:100000, wall_clock 128, runtime:130ok</p>
<p class="MsoNormal">times:100000, wall_clock 126, runtime:120ok</p>
<p class="MsoNormal">times:100000, wall_clock 124, runtime:120ok</p>
<p class="MsoNormal">times:100000, wall_clock 126, runtime:120ok</p>
<p class="MsoNormal">times:100000, wall_clock 127, runtime:130ok</p>
<p class="MsoNormal">times:100000, wall_clock 125, runtime:130ok</p>
<p class="MsoNormal">times:100000, wall_clock 125, runtime:120ok</p>
<p class="MsoNormal">times:100000, wall_clock 127, runtime:120ok</p>
<p class="MsoNormal">times:100000, wall_clock 128, runtime:130ok</p>
<p class="MsoNormal">times:100000, wall_clock 127, runtime:130ok</p>
<p class="MsoNormal"><span style="color: rgb(255, 0, 0); ">和ets的性能几乎一样，一次读取的消耗大约1.2us，和事务相比快了几十倍。</span>追踪脏读源码到mnesia_lib.erl中：</p>
<p align="left" class="MsoNormal" style="text-align: left; "><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">db_get(</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Tab</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Key</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">) -&gt;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; "><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; "><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; "><span>&nbsp;&nbsp;&nbsp;&nbsp;</span>db_get(val({</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Tab</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">, storage_type}),&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Tab</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Key</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">)</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: blue; ">.</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; "><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; "><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">db_get(ram_copies,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Tab</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Key</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">) -&gt;&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(95, 158, 160); ">?ets_lookup</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">(</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Tab</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Key</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">);</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; "><o:p></o:p></span></p>
<p align="left" class="MsoNormal" style="text-align: left; "><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">db_get(disc_copies,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Tab</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Key</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">) -&gt;&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(95, 158, 160); ">?ets_lookup</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">(</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Tab</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Key</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">);</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; "><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 24pt; "><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">db_get(disc_only_copies,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Tab</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Key</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">) -&gt; dets:lookup(</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Tab</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">,&nbsp;</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: rgb(184, 134, 11); ">Key</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: black; ">)</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; color: blue; ">.</span></p>
<p class="MsoNormal" style="text-indent: 24pt; ">呵呵，果然是ets直接操作。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2010/05/mnesia%e8%84%8f%e8%af%bb%e4%b8%8e%e4%ba%8b%e7%89%a9%e8%af%bb%e6%80%a7%e8%83%bd%e7%bb%93%e6%9e%9c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gen_server三两话</title>
		<link>http://www.qingliangcn.com/2010/04/gen_server%e4%b8%89%e4%b8%a4%e8%af%9d/</link>
		<comments>http://www.qingliangcn.com/2010/04/gen_server%e4%b8%89%e4%b8%a4%e8%af%9d/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 02:53:49 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[gen_server]]></category>
		<category><![CDATA[otp]]></category>

		<guid isPermaLink="false">http://www.qingliangcn.com/?p=248</guid>
		<description><![CDATA[(最近挺忙，都没时间写点啥) gen_server是OTP中的一个重要组成，在开发中出现的频率相当高。弄明白这一块的，对于gen_server的使用有着相当好的帮忙。下面多数为代码。 从start_link开始： gen_server.erl start_link(Name,&#160;Mod,&#160;Args,&#160;Options)&#160;-&#62; gen:start(?MODULE,&#160;link,&#160;Name,&#160;Mod,&#160;Args,&#160;Options). &#160; 跳到gen.erl，这里的GenMod值为gen_server，LinkP为link start(GenMod,&#160;LinkP,&#160;Name,&#160;Mod,&#160;Args,&#160;Options)&#160;-&#62; &#160;&#160;&#160;&#160;case&#160;where(Name)&#160;of undefined&#160;-&#62; &#160;&#160;&#160;&#160;do_spawn(GenMod,&#160;LinkP,&#160;Name,&#160;Mod,&#160;Args,&#160;Options); Pid&#160;-&#62; &#160;&#160;&#160;&#160;{error,&#160;{already_started,&#160;Pid}} end. 再跳： do_spawn(GenMod,&#160;link,&#160;Name,&#160;Mod,&#160;Args,&#160;Options)&#160;-&#62; &#160;&#160;&#160;&#160;Time&#160;=&#160;timeout(Options), &#160;&#160;&#160;&#160;proc_lib:start_link(?MODULE,&#160;init_it, [GenMod,&#160;self(),&#160;self(),&#160;Name,&#160;Mod,&#160;Args,&#160;Options], Time, spawn_opts(Options)); 跳到proc_lib.erl文件： start_link(M,F,A,Timeout,SpawnOpts)&#160;when&#160;is_atom(M),&#160;is_atom(F),&#160;is_list(A)&#160;-&#62; &#160;&#160;&#160;&#160;Pid&#160;=&#160;?MODULE:spawn_opt(M,&#160;F,&#160;A,&#160;ensure_link(SpawnOpts)), sync_wait(Pid,&#160;Timeout). 注意这里有个等待返回，之后需要proc_lib:init_ack来返回消息。 spawn_opt(M,&#160;F,&#160;A,&#160;Opts)&#160;when&#160;is_atom(M),&#160;is_atom(F),&#160;is_list(A)&#160;-&#62; &#160;&#160;&#160;&#160;Parent&#160;=&#160;get_my_name(), &#160;&#160;&#160;&#160;Ancestors&#160;=&#160;get_ancestors(), &#160;&#160;&#160;&#160;check_for_monitor(Opts), &#160;&#160;&#160;&#160;erlang:spawn_opt(?MODULE,&#160;init_p,&#160;[Parent,Ancestors,M,F,A],&#160;Opts). 这里调用proc_lib模块的init_p方法： -spec&#160;init_p(pid(),&#160;[pid()],&#160;function())&#160;-&#62;&#160;term(). init_p(Parent,&#160;Ancestors,&#160;Fun)&#160;when&#160;is_function(Fun)&#160;-&#62; &#160;&#160;&#160;&#160;put(&#39;$ancestors&#39;,&#160;[Parent&#124;Ancestors]), &#160;&#160;&#160;&#160;{module,Mod}&#160;=&#160;erlang:fun_info(Fun,&#160;module), &#160;&#160;&#160;&#160;{name,Name}&#160;=&#160;erlang:fun_info(Fun,&#160;name), &#160;&#160;&#160;&#160;{arity,Arity}&#160;=&#160;erlang:fun_info(Fun,&#160;arity), &#160;&#160;&#160;&#160;put(&#39;$initial_call&#39;,&#160;{Mod,Name,Arity}), &#160;&#160;&#160;&#160;try Fun() &#160;&#160;&#160;&#160;catch Class:Reason&#160;-&#62; &#160;&#160;&#160;&#160;exit_p(Class,&#160;Reason) &#160;&#160;&#160;&#160;end. -spec&#160;init_p(pid(),&#160;[pid()],&#160;atom(),&#160;atom(),&#160;[term()])&#160;-&#62;&#160;term(). init_p(Parent,&#160;Ancestors,&#160;M,&#160;F,&#160;A)&#160;when&#160;is_atom(M),&#160;is_atom(F),&#160;is_list(A)&#160;-&#62; &#160;&#160;&#160;&#160;put(&#39;$ancestors&#39;,&#160;[Parent&#124;Ancestors]), &#160;&#160;&#160;&#160;put(&#39;$initial_call&#39;,&#160;trans_init(M,&#160;F,&#160;A)), &#160;&#160;&#160;&#160;init_p_do_apply(M,&#160;F,&#160;A). init_p_do_apply(M,&#160;F,&#160;A)&#160;-&#62; &#160;&#160;&#160;&#160;try apply(M,&#160;F,&#160;A)&#160; &#160;&#160;&#160;&#160;catch]]></description>
			<content:encoded><![CDATA[<div class="Section0" style="layout-grid:  15.6pt none">
<p><span style="font-family: '宋体'; font-size: 16pt; font-weight: bold; mso-spacerun: 'yes'"><o:p><span style="font-size: 11px"><span style="font-size: 12px">(最近挺忙，都没时间写点啥)</span></span></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">gen_server<font face="宋体">是</font><font face="Courier New">OTP</font><font face="宋体">中的一个重要组成，在开发中出现的频率相当高。弄明白这一块的，对于</font><font face="Courier New">gen_server</font><font face="宋体">的使用有着相当好的帮忙。下面多数为代码。</font></span><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">从<font face="Courier New">start_link</font><font face="宋体">开始：</font></span><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">gen_server.erl</span><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">start_link(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">gen:start(</span><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10.5pt; mso-spacerun: 'yes'">?MODULE</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;link,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt">&nbsp;</p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><span id="more-248"></span></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">跳到<font face="Times New Roman">gen.erl</font><font face="宋体">，这里的</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">GenMod</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">值为</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">gen_server<font face="宋体">，</font><font face="Times New Roman">LinkP</font><font face="宋体">为</font><font face="Times New Roman">link</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">start(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">GenMod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">LinkP</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;where(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">undefined&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;do_spawn(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">GenMod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">LinkP</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Pid</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;{error,&nbsp;{already_started,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Pid</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}}</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">再跳：</span><span style="font-family: '宋体'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">do_spawn(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">GenMod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;link,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Time</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;timeout(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;proc_lib:start_link(</span><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10.5pt; mso-spacerun: 'yes'">?MODULE</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;init_it,</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">GenMod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;self(),&nbsp;self(),&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">],</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Time</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">spawn_opts(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">));</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">跳到<font face="Courier New">proc_lib.erl</font><font face="宋体">文件：</font></span><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">start_link(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Timeout</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">SpawnOpts</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">when</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;is_atom(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),&nbsp;is_atom(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),&nbsp;is_list(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Pid</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;</span><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10.5pt; mso-spacerun: 'yes'">?MODULE</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">:spawn_opt(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;ensure_link(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">SpawnOpts</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">sync_wait(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Pid</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Timeout</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">注意这里有个等待返回，之后需要</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">proc_lib:init_ack</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">来返回消息。</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">spawn_opt(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Opts</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">when</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;is_atom(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),&nbsp;is_atom(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),&nbsp;is_list(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;get_my_name(),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Ancestors</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;get_ancestors(),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;check_for_monitor(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Opts</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;erlang:spawn_opt(</span><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10.5pt; mso-spacerun: 'yes'">?MODULE</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;init_p,&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Ancestors</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">],&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Opts</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">这里调用</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">proc_lib<font face="宋体">模块的</font><font face="Times New Roman">init_p</font><font face="宋体">方法：</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">-</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">spec</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;init_p(pid(),&nbsp;[pid()],&nbsp;function())&nbsp;-&gt;&nbsp;term()</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">init_p(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Ancestors</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Fun</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">when</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;is_function(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Fun</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;put(&#39;$ancestors&#39;,&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">|</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Ancestors</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">]),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;{module,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;=&nbsp;erlang:fun_info(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Fun</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;module),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;{name,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;=&nbsp;erlang:fun_info(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Fun</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;name),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;{arity,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Arity</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;=&nbsp;erlang:fun_info(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Fun</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;arity),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;put(&#39;$initial_call&#39;,&nbsp;{</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Arity</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">try</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Fun</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">()</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">catch</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Class</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">:</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit_p(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Class</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">-</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">spec</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;init_p(pid(),&nbsp;[pid()],&nbsp;atom(),&nbsp;atom(),&nbsp;[term()])&nbsp;-&gt;&nbsp;term()</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">init_p(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Ancestors</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">when</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;is_atom(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),&nbsp;is_atom(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),&nbsp;is_list(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;put(&#39;$ancestors&#39;,&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">|</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Ancestors</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">]),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;put(&#39;$initial_call&#39;,&nbsp;trans_init(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;init_p_do_apply(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">init_p_do_apply(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">try</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">apply(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">M</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">F</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">A</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">catch</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Class</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">:</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit_p(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Class</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">有点晕头了吧，<font face="Times New Roman">MFA</font><font face="宋体">是什么呢？如下：</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(95,158,160); font-size: 10.5pt; mso-spacerun: 'yes'">gen</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;init_it,</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">[</span><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">gen_server</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;self(),&nbsp;self(),&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">]</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">这里的</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">是我们自己的注册名，模块名、参数。</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">调回<font face="Times New Roman">init</font><font face="宋体">：</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">init_it(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">GenMod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;name_register(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">true&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;init_it2(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">GenMod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{false,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Pid</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;proc_lib:init_ack(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;{error,&nbsp;{already_started,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Pid</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}})</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">init_it2(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">GenMod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">GenMod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">:init_it(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">ok<font face="宋体">，又回到</font><font face="Times New Roman">gen_server</font><font face="宋体">了。跳转到</font><font face="Times New Roman">gen_server</font><font face="宋体">的</font><font face="Times New Roman">init_it</font><font face="宋体">：</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">init_it(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;self,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;init_it(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;self(),&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">init_it(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name0</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;name(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name0</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;debug_options(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Options</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">catch</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">:init(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Args</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{ok,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;proc_lib:init_ack(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;{ok,&nbsp;self()}),&nbsp;</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;loop(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;infinity,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{ok,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Timeout</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;proc_lib:init_ack(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;{ok,&nbsp;self()}),&nbsp;</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"> </span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;loop(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Timeout</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{stop,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(178,34,34); font-size: 10.5pt; mso-spacerun: 'yes'">%%&nbsp;For&nbsp;consistency,&nbsp;we&nbsp;must&nbsp;make&nbsp;sure&nbsp;that&nbsp;the</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(178,34,34); font-size: 10.5pt; mso-spacerun: 'yes'">%%&nbsp;registered&nbsp;name&nbsp;(if&nbsp;any)&nbsp;is&nbsp;unregistered&nbsp;before</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(178,34,34); font-size: 10.5pt; mso-spacerun: 'yes'">%%&nbsp;the&nbsp;parent&nbsp;process&nbsp;is&nbsp;notified&nbsp;about&nbsp;the&nbsp;failure.</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(178,34,34); font-size: 10.5pt; mso-spacerun: 'yes'">%%&nbsp;(Otherwise,&nbsp;the&nbsp;parent&nbsp;process&nbsp;could&nbsp;get</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(178,34,34); font-size: 10.5pt; mso-spacerun: 'yes'">%%&nbsp;an&nbsp;&#39;already_started&#39;&nbsp;error&nbsp;if&nbsp;it&nbsp;immediately</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(178,34,34); font-size: 10.5pt; mso-spacerun: 'yes'">%%&nbsp;tried&nbsp;starting&nbsp;the&nbsp;process&nbsp;again.)</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;unregister_name(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name0</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;proc_lib:init_ack(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;{error,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">ignore&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;unregister_name(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name0</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;proc_lib:init_ack(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;ignore),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit(normal);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{&#39;EXIT&#39;,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;unregister_name(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name0</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;proc_lib:init_ack(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;{error,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Else</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Error</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;{bad_return_value,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Else</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">},</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;proc_lib:init_ack(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Starter</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;{error,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Error</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Error</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">呵呵，苦尽甘来，终于来到<font face="Courier New">loop</font><font face="宋体">主循环了。&nbsp;</font><font face="Courier New">gen_server</font><font face="宋体">的消息怎么来的？就是这个</font><font face="Courier New">loop</font><font face="宋体">不断地取出消息、</font><font face="Courier New">decode_msg</font><font face="宋体">、再</font><font face="Courier New">loop</font><font face="宋体">来不断从消息队列中取出消息的。这个主循环就是我们的</font><font face="Courier New">gen_server</font><font face="宋体">进程了。</font></span><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: '宋体'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">loop(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;hibernate,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;proc_lib:hibernate(</span><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10.5pt; mso-spacerun: 'yes'">?MODULE</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,wake_hib,[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">]);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">loop(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Time</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">receive</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Input</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Input</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">after</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Time</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;timeout</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;decode_msg(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Time</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;false)</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">decode_msg(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Time</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Hib</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{system,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">From</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Req</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;sys:handle_system_msg(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Req</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">From</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10.5pt; mso-spacerun: 'yes'">?MODULE</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;[</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Time</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">],&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Hib</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{&#39;EXIT&#39;,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;terminate(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">_Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">when</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=:=&nbsp;[]&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;handle_msg(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">_Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug1</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;=&nbsp;sys:handle_debug(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;{</span><span style="font-family: 'courier new'; color: rgb(95,158,160); font-size: 10.5pt; mso-spacerun: 'yes'">?MODULE</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;print_event},&nbsp;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;{in,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;handle_msg(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug1</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">这里我们就看到了</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">terminate<font face="宋体">的自动回调（如果设置了</font><font face="Times New Roman">trap_exit</font><font face="宋体">）。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">handle_msg<font face="宋体">中处理了</font><font face="Times New Roman">handle_call</font><font face="宋体">类型的调用，&nbsp;而</font><font face="Times New Roman">handle_cast</font><font face="宋体">和</font><font face="Times New Roman">handle_info</font><font face="宋体">则由</font></span><span style="font-family: 'courier new'; background: rgb(255,255,255); color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'; mso-highlight: rgb(255, 255, 255)">dispatch</span><span style="font-family: '宋体'; background: rgb(255,255,255); color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'; mso-highlight: rgb(255, 255, 255)">来处理：</span><span style="font-family: '宋体'; background: rgb(255,255,255); color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'; mso-highlight: rgb(255, 255, 255)"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">dispatch({&#39;$gen_cast&#39;,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">},&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">:handle_cast(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">dispatch(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Info</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">:handle_info(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Info</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">handle_msg<font face="宋体">处理</font><font face="Times New Roman">handle_call</font><font face="宋体">也很简单，回调我们的</font><font face="Times New Roman">handle_call</font><font face="宋体">方法：</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">handle_msg({&#39;$gen_call&#39;,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">From</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">},&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Parent</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">catch</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">:handle_call(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">From</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">&#8230;&#8230;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">至此，整个<font face="Times New Roman">gen_server</font><font face="宋体">的运行流程就清楚了（晕的话，多看几遍）。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">回头再来看看<font face="Times New Roman">terminate</font><font face="宋体">的处理</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">terminate(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">catch</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Mod</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">:terminate(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{&#39;EXIT&#39;,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">R</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;error_info(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">R</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">R</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">_</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">case</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">of</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">normal&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit(normal);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">shutdown&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit(shutdown);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">{shutdown,</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">_</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">}=</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Shutdown</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Shutdown</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">);</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">_</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;-&gt;</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;error_info(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Name</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Msg</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">State</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">,&nbsp;</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Debug</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">),</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="font-family: 'courier new'; color: rgb(184,134,11); font-size: 10.5pt; mso-spacerun: 'yes'">Reason</span><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">)</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,0); font-size: 10.5pt; mso-spacerun: 'yes'">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(160,32,240); font-size: 10.5pt; font-weight: bold; mso-spacerun: 'yes'">end</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'">.</span><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; margin-bottom: 0pt"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">这里<font face="Times New Roman">terminate</font><font face="宋体">在回调了</font><font face="Times New Roman">gen_server</font><font face="宋体">的</font><font face="Times New Roman">terminate</font><font face="宋体">函数后，又</font><font face="Times New Roman">exit</font><font face="宋体">了一次，目的是为了产生一个</font><font face="Times New Roman">&#39;EXIT&#39;</font><font face="宋体">消息给</font><font face="Times New Roman">supervisor</font><font face="宋体">，以便让</font><font face="Times New Roman">supervisor</font><font face="宋体">做相应的重启策略。</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
<p class="p0" style="margin-top: 0pt; text-indent: 21pt; margin-bottom: 0pt"><span style="font-family: 'courier new'; color: rgb(0,0,255); font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p>
</div>
<p><!--EndFragment--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.qingliangcn.com/2010/04/gen_server%e4%b8%89%e4%b8%a4%e8%af%9d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erlang中日志管理三两话</title>
		<link>http://www.qingliangcn.com/2010/03/erlang%e4%b8%ad%e6%97%a5%e5%bf%97%e7%ae%a1%e7%90%86%e4%b8%89%e4%b8%a4%e8%af%9d/</link>
		<comments>http://www.qingliangcn.com/2010/03/erlang%e4%b8%ad%e6%97%a5%e5%bf%97%e7%ae%a1%e7%90%86%e4%b8%89%e4%b8%a4%e8%af%9d/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 08:05:42 +0000</pubDate>
		<dc:creator>庆亮</dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[ejabberd]]></category>
		<category><![CDATA[sasl]]></category>
		<category><![CDATA[动态日志]]></category>
		<category><![CDATA[日志]]></category>

		<guid isPermaLink="false">http://www.qingliangcn.com/?p=242</guid>
		<description><![CDATA[日志系统的重要性就不罗嗦了，直接开始吧。 &#160; 