<?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>一个故事@MySQL DBA &#187; Linux</title>
	<atom:link href="http://www.orczhou.com/index.php/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.orczhou.com</link>
	<description>一个故事@MySQL DBA</description>
	<lastBuildDate>Tue, 24 Aug 2010 01:44:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Linux下使用od查看文件</title>
		<link>http://www.orczhou.com/index.php/2010/08/linux-od-data-file/</link>
		<comments>http://www.orczhou.com/index.php/2010/08/linux-od-data-file/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 10:44:35 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.orczhou.com/?p=2407</guid>
		<description><![CDATA[<p><font color="red">
<pre>        "不积跬步，无以至千里"
                                 《劝学》
</pre>
<p></p></font></p>
<p>查看文本文件使用vim/less就足够了，但如果想要查看一些其他二进制文件（例如DB的数据文件、程序的二进制代码）则借助于od/hexdump这些工具会很方便，这里会通过一些实例来详细介绍od命令的相关参数。</p>
<div class="myt1">1. od参数详解</div>
<pre>
<div class="mycode">$od -j 49152 -N 38 -w4 -A d -t x1 -v tmp_test.ibd
0049152 fd 6f fb 70
0049156 00 00 00 03
0049160 ff ff ff ff
0049164 ff ff ff ff
0049168 00 00 00 03
0049172 ba 92 ac 0c
0049176 45 bf 00 00
0049180 00 00 00 00
0049184 00 00 00 00
</div>
</pre>
<p>[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2010/08/linux-od-data-file/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p><font color="red">
<pre>        "不积跬步，无以至千里"
                                 《劝学》
</pre>
<p></font></p>
<p>查看文本文件使用vim/less就足够了，但如果想要查看一些其他二进制文件（例如DB的数据文件、程序的二进制代码）则借助于od/hexdump这些工具会很方便，这里会通过一些实例来详细介绍od命令的相关参数。</p>
<div class="myt1">1. od参数详解</div>
<pre>
<div class="mycode">$od -j 49152 -N 38 -w4 -A d -t x1 -v tmp_test.ibd
0049152 fd 6f fb 70
0049156 00 00 00 03
0049160 ff ff ff ff
0049164 ff ff ff ff
0049168 00 00 00 03
0049172 ba 92 ac 0c
0049176 45 bf 00 00
0049180 00 00 00 00
0049184 00 00 00 00
</div>
</pre>
<p><span id="more-2407"></span></p>
<p>-j 49152 跳过前49152个字节（bytes）</p>
<p>-N 38 仅显示38个字节</p>
<p>-w4 每一行显示4个字节</p>
<p>-A d 表示最左侧的偏移量按十进制显示；-A还可以接[doxn]，其中d表示十进制，o表示8进制，x表示16进制，n表示不显示该偏移量，如：</p>
<pre>
<div class="mycode">od -j 49152 -N 8 -w4 -A n -t x1 -v ibdata1
 b4 0b c7 31
 00 00 00 03
</div>
</pre>
<p>-t x1表示如何显示文件内容。这里，x表示按照16进制输出文件内容，x后面跟的“1”表示一次显示一个字节。下面是一个-t x2的输出：</p>
<pre>
<div class="mycode">od -j 49152 -N 8 -w4 -A n -t x2 -v ibdata1
 0bb4 31c7    # 0bb4是十进制表示的两个字节
 0000 0300    #
</div>
</pre>
<p>另外，注意到这里是0bb4和前面的b40b略有不同，这是因为我这里的测试平台是little-endian的（x86_64 Linux）。</p>
<p>最后，参数-v表示，即使连续多行都是完全相同的字符0，仍然原样输出；不加该参数，则会使用星号（*）跳过多个相同的行。</p>
<p>好了，再回头看看最前面的命令，已经没那么难理解了吧。</p>
<p>参考文献：man od</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2010/08/linux-od-data-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下使用screen工作How-to</title>
		<link>http://www.orczhou.com/index.php/2010/08/linux%e4%b8%8b%e4%bd%bf%e7%94%a8screen%e5%b7%a5%e4%bd%9chow-to/</link>
		<comments>http://www.orczhou.com/index.php/2010/08/linux%e4%b8%8b%e4%bd%bf%e7%94%a8screen%e5%b7%a5%e4%bd%9chow-to/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 05:02:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.orczhou.com/?p=2396</guid>
		<description><![CDATA[<p>通过ssh在Linux终端下工作，有一个很烦的事情就是，如果需要执行一个长时间的命令（例如拷贝一个大文件，或者做DDL）时，如果终端意外断开（网络或者别的原因），一般命令就会终止，当然你可以使用nohup命令，这里提供另一个办法：使用<a href="http://www.gnu.org/software/screen/">screen</a>。</p>
<p>一般，我们创建一个screen会话，然后连接会话并在会话下工作，这时候，我们可以随时挂起会话，去做别的事情，而且这个挂起的会话会一直在后台执行。而后又可以重新连接会话。下面是一个简单的How-to：</p>
<div class="myt1">1. How-to</div>
<div class="myt2">1.1 创建一个screen会话</div>
<div class="mycode">screen -dmS supu</div>
<p>该命令，创建一个名为supu的会话，当时并不立刻进入会话。[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2010/08/linux%e4%b8%8b%e4%bd%bf%e7%94%a8screen%e5%b7%a5%e4%bd%9chow-to/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>通过ssh在Linux终端下工作，有一个很烦的事情就是，如果需要执行一个长时间的命令（例如拷贝一个大文件，或者做DDL）时，如果终端意外断开（网络或者别的原因），一般命令就会终止，当然你可以使用nohup命令，这里提供另一个办法：使用<a href="http://www.gnu.org/software/screen/">screen</a>。</p>
<p>一般，我们创建一个screen会话，然后连接会话并在会话下工作，这时候，我们可以随时挂起会话，去做别的事情，而且这个挂起的会话会一直在后台执行。而后又可以重新连接会话。下面是一个简单的How-to：</p>
<div class="myt1">1. How-to</div>
<div class="myt2">1.1 创建一个screen会话</div>
<div class="mycode">screen -dmS supu</div>
<p>该命令，创建一个名为supu的会话，当时并不立刻进入会话。<span id="more-2396"></span></p>
<div class="myt2">1.2 连入会话</div>
<div class="mycode">screen -r supu</div>
<p>连入会话后，就可以做任何想做的工作了。</p>
<div class="myt2">1.3 挂起该终端</div>
<p>如果你在会话中，做了某个需要等很久的操作，或者你需要离开一段时间，这时就需要执行挂起操作了：</p>
<p>(ctrl+a) + D  先按下Ctr+a然后按D键（screen捕获ctrl+a，后面跟一个命令键D，可以通过ctrl+a ?查看更多）</p>
<div class="t2">1.4 其他相关</div>
<p>而后，可以重新使用-r参数回到会话；在会话中，用exit可以退出并关闭这个会话；还可以使用screen -ls命令来查看当前的全部会话状态。</p>
<div class="myt1">2. 一些名词</div>
<div class="myt2">Attached和Detached</div>
<p>一般screen -ls可以看到多个会话状态，例如：</p>
<pre>
<div class="mycode">[admin@my174 ~]$ screen -ls
There are screens on:
        22872.supu      (Detached)
        18283.pts-3.my174       (Attached)
2 Sockets in /var/run/screen/S-admin.</div>
</pre>
<p>Detached表示会话处于挂起状态，Attached表示有终端在连接会话。</p>
<p>“22872.supu”这是会话名。22872是一个唯一会话ID，后面supu是自定义的会话名，可以使用screen -r 22872等同于screen -r supu。</p>
<p>Enjoy！</p>
<p>参考：<a href="http://www.ibm.com/developerworks/cn/linux/l-cn-screen/">linux 技巧：使用 screen 管理你的远程会话</a> | man screen</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2010/08/linux%e4%b8%8b%e4%bd%bf%e7%94%a8screen%e5%b7%a5%e4%bd%9chow-to/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to kill an `uninterruptible sleep` process</title>
		<link>http://www.orczhou.com/index.php/2010/05/how-to-kill-an-uninterruptible-sleep-process/</link>
		<comments>http://www.orczhou.com/index.php/2010/05/how-to-kill-an-uninterruptible-sleep-process/#comments</comments>
		<pubDate>Tue, 18 May 2010 12:49:19 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.orczhou.com/?p=1974</guid>
		<description><![CDATA[<p>很早之前就遇到一次这个故障，当时是一台主机故障，这次是上百台主机故障。当时是使用mysqldump向NFS备份时，写数据时大概是NFS出现故障，使得mysqldump进程进入uninterruptible sleep（man ps）状态：</p>
<div class="mycode">$ps axu&#124;grep mysqldump<br />
mysql     2718  0.0  0.0 51088  672 pts/0    S+   13:30   0:00 grep mysqldump<br />
mysql    14916  1.4  0.0     0    0 ?        D    02:03  10:03 [mysqldump]</div>
<p>进入该状态的进程，会一直等待NFS，不接受任何信号，当然也就无法被杀死（kill/fuser -k）。因为进程一直在运行队列（running queue）中，所以还会导致主机的Load上升（虽然主机并不繁忙）。如果由于这个原因被卡住的进程很多的话，主机的Load可能会<strong>看起来</strong>非常高。[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2010/05/how-to-kill-an-uninterruptible-sleep-process/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>很早之前就遇到一次这个故障，当时是一台主机故障，这次是上百台主机故障。当时是使用mysqldump向NFS备份时，写数据时大概是NFS出现故障，使得mysqldump进程进入uninterruptible sleep（man ps）状态：</p>
<div class="mycode">$ps axu|grep mysqldump<br />
mysql     2718  0.0  0.0 51088  672 pts/0    S+   13:30   0:00 grep mysqldump<br />
mysql    14916  1.4  0.0     0    0 ?        D    02:03  10:03 [mysqldump]</div>
<p>进入该状态的进程，会一直等待NFS，不接受任何信号，当然也就无法被杀死（kill/fuser -k）。因为进程一直在运行队列（running queue）中，所以还会导致主机的Load上升（虽然主机并不繁忙）。如果由于这个原因被卡住的进程很多的话，主机的Load可能会<strong>看起来</strong>非常高。<span id="more-1974"></span></p>
<p>上次出现这个问题时只有一台主机出了这个症状，当时Google后也注意到很多人有遇到了<a href="http://www.google.com/search?hl=en&#038;q=NFS+uninterruptible&#038;btnG=Search&#038;aq=f&#038;aqi=&#038;aql=&#038;oq=&#038;gs_rfai=">类似的问题</a>，并且都束手无策(<a href="http://linuxgazette.net/issue83/tag/6.html">There are some things even root can&#8217;t do</a>)。Google后，再尝试找了一些Linux原理方面的介绍，依然无解。</p>
<p>解决的终极办法是重启主机（reboot），所以决定等待一段时间（之前遇到过一些僵死进程Z，等待一段时间后也消失了），实在不行就择机重启主机。不过奇怪的是，等了几天过后，这个进程确实消失了（正常结束了？应该是）。</p>
<p><font color="red">1. Why is Linux so &#8220;stupid&#8221;?</font></p>
<p>有人就问，Linux设计是不是有问题，为什么会有一些进程root也无法杀死呢？</p>
<p>jra在<a href="http://linuxgazette.net/issue83/tag/6.html">How to kill a process in uninterruptible sleep state</a>中给了一个解释：</p>
<pre>
<div class="mycode">    There's fairly extensive discussion of this in a couple of the kernel
design books, and I think in Nemeth, Snyder and Seebass: the problem stems
from the fact that there are two types of device drivers -- those
for "fast" devices and those for "slow" devices：

    Slow-device drivers -- for things like terminals, and such -- are
                usually split in two pieces, and can therefore be
                interrupted while they're in the middle of something.

    Fast-device drivers -- which service things like hard drives and (I
                think) ethernet cards -- are designed to expect that
                when they call out to hardware, it will respond  instantly
                (in human terms), and that they won't have to wait
                on anything. Such drivers have, as a rule, proven
                extremely intolerant of hardware trouble -- if your hard
                drive start having to do hardware retries to read a
                sector, your system perfromance is going int he toilet,
                even if you have more than one drive...</div>
</pre>
<p>大概意思是说，Linux中设备驱动程序可以分为“slow device”和“fast device”两类。磁盘属于“fast device”（如果当作“slow device”处理效率会很低），在这类设备上操作时会以uninterruptible的方式进行。</p>
<p><font color="red">2. 真的没办法吗?</font></p>
<p>理论上，除了重启主机，貌似没什么办法了。不过，根据实际经验和运气，也还是有一些办法可以尝试的。</p>
<p><font color="blue">办法1：umount -f</font></p>
<p>如果是由于NFS故障导致的，可以尝试使用先umount/mount重新挂载NFS。如果NFS无法卸载（如果遇到上述情况，八成是这样），可以尝试使用 -f 参数卸载。最近一次遇到这个故障，有接近上百台主机出现这个故障，就是使用umount -f成功卸载NFS后，相关uninterruptible的进程也都随之正常结束。当时发现，连续重试多次 umount -f 才行：</p>
<div class="mycode">root>#umount -f /nfsdir<br />
umount2: Device or resource busy<br />
umount: /nfsdir: device is busy<br />
root>#umount -f /nfsdir<br />
umount2: Device or resource busy<br />
umount: /nfsdir: device is busy</div>
<p><font color="blue">办法2：等</font></p>
<p>最早mysqldump遇到这个问题时，束手无策后，就等了几天，发现进程确实结束了。所以如果情况不是很紧急，“等”也是一个办法。</p>
<p>遇到的僵死进程这个办法也可能有效。</p>
<p><font color="blue">办法3：killall -KILL rpciod</font></p>
<p>在<a href="http://bbs.unixall.com/thread-441-1-1.html">一篇文章</a>中，还提到，进程处于uninterruptible sleep(即ps的D状态)，进程处于rpc_execute调用状态，而rpc_execute调用是由rpciod提供，所以可以通过杀死rpciod来解决问题。（rpciod被杀死后会自动重启过来）【没有实验过，慎用，希望有经验者分享一下】</p>
<p><font color="blue">办法4：reboot</font></p>
<p>实在不行，就只能reboot了。这是最不推荐的做法，毕竟每次遇到都reboot，代价还是比较大，特别是当你在追求HA的时候。</p>
<p><font color="red">3. 能够避免这种情况吗?</font></p>
<p>在RTFM之后，发现可以通过挂载NFS时指定一些参数，尽可能的避免这个问题：</p>
<pre>
<div class="mycode">     soft       If an NFS file operation has a major timeout then report
                 an I/O error to the calling program.  The default is  to
                 continue retrying NFS file operations indefinitely.

      hard       If an NFS file operation has a major timeout then report
                 "server not responding"  on  the  console  and  continue
                 retrying indefinitely.  This is the default.

      intr       If  an  NFS file operation has a major timeout and it is
                 hard mounted, then allow signals to  interupt  the  file
                 operation  and  cause  it to return EINTR to the calling
                 program.  The default is to not allow file operations to
                 be interrupted.</div>
</pre>
<p>上面3个参数，其中hard是默认的。我们通过断开网络模拟NFS故障，测试了 intr 选项，发现能够一定程度上避免上述的情况。在测试 soft 选项时，并没有上面描述的那么好用，在实验中，使用 soft 挂载是现象和 hard 类似（不知道我是不是忽略哪些细节了）。</p>
<p>如果你被这个问题困扰，可以试试使用intr参数挂载NFS：</p>
<div class="mycode">mount -o intr 172.23.119.25:/nfs /nfsdir</div>
<p><font color="red">参考文献</font><br />
[1]. Linux Man<br />
[2]. <a href="http://linuxgazette.net/issue83/tag/6.html">How to kill a process in uninterruptible sleep state</a><br />
[3]. <a href="http://kerneltrap.org/Linux/Killing_Tasks_On_Frozen_NFS_Mounts">Linux: Killing Tasks On Frozen NFS Mounts</a><br />
[4]. <a href="http://hychen.wuweig.org/?p=30728">How to kill a process in uninterruptible sleep state</a><br />
[5]. <a href="http://bbs.unixall.com/thread-441-1-1.html">如何杀掉由NFS造成Uninterruptible的进程</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2010/05/how-to-kill-an-uninterruptible-sleep-process/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Vim使用简介</title>
		<link>http://www.orczhou.com/index.php/2010/03/vim-recording/</link>
		<comments>http://www.orczhou.com/index.php/2010/03/vim-recording/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 14:35:01 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[vi]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.orczhou.com/?p=1209</guid>
		<description><![CDATA[<p><font color="red">
<pre>        "工欲善其事,必先利其器"
                                   《论语》
</pre>
<p></p></font></p>
<p>写在前头：vim是<strong>Linux</strong>下最常用的编辑工具，一般认为vim是Vi IMproved（增强的vi）的缩写，很多时候我们也把vim称为vi。vi是一个上手比较难，但是一旦掌握，就能大大提高效率的工具。本文<strong>仅</strong>介绍一些Vim使用的基本概念，读者可以根据本文给出参考文献继续深入了解Vim。</p>
<p><font color="red">1. 认识Vi</font></p>
<p>直接使用vi（或者vim）命令，<strong>有时</strong>会看到如下的内容</p>
<pre>
<div class="mycode">                 Vim is open source and freely distributable

~                       Help poor children in Uganda!
~              type  :help iccf&#60;Enter&#62;       for information
</div>
</pre>
<p>[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2010/03/vim-recording/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p><font color="red">
<pre>        "工欲善其事,必先利其器"
                                   《论语》
</pre>
<p></font></p>
<p>写在前头：vim是<strong>Linux</strong>下最常用的编辑工具，一般认为vim是Vi IMproved（增强的vi）的缩写，很多时候我们也把vim称为vi。vi是一个上手比较难，但是一旦掌握，就能大大提高效率的工具。本文<strong>仅</strong>介绍一些Vim使用的基本概念，读者可以根据本文给出参考文献继续深入了解Vim。</p>
<p><font color="red">1. 认识Vi</font></p>
<p>直接使用vi（或者vim）命令，<strong>有时</strong>会看到如下的内容</p>
<pre>
<div class="mycode">                 Vim is open source and freely distributable

~                       Help poor children in Uganda!
~              type  :help iccf&lt;Enter&gt;       for information
</div>
</pre>
<p><span id="more-1209"></span></p>
<p>建议用户向荷兰<a href="http://iccf-holland.org/index.html">ICCF</a>捐款, 用于帮助乌干达的艾滋病患者，可以通过键入命令:help iccf<Enter>查看更多细节。</p>
<p>你可以使用如下命令开始编辑一个文本：</p>
<pre>
<div class="mycode">vi doat.txt</div>
</pre>
<p><font color="red">2. Vim中的模式</font></p>
<p>Vi和Windows下的编辑器最大的一个不同是Vi有多种模式：<font color="blue">Normal模式，编辑模式，命令模式</font>。使用命令(如 vi dota.txt)后，首先进入Normal模式（这个模式下，可以移动光标的位置）；如果准备开始编辑了，按下a（或者i）就可以进入编辑模式，这时，和普通的编辑器就差不多了；完成编辑希望保存并退出文本时，你可以先按Esc进入Normal模式，然后按:wq保存并退出。（还是有点点复杂的:）事实上还有Ex Select Visual等模式）</p>
<p><font color="red">3. Vim中的一些功能</font></p>
<p>这里将罗列一些Vi的功能，本文将不详述，因为只要你知道她有这些功能，Google大神会告诉你具体操作。</p>
<p><font color="blue">语法高亮</font>：当你编写shell代码时，高亮可以帮你发现一些明显的语法错误；<font color="blue">录制、播放</font>：当你在成百次的重复一些复杂的vi操作时，录制会帮你大忙；<font color="blue">列编辑</font>：据我知道，很多人之所以使用破解版的UE，就是因为这个；<font color="blue">搜索、替换</font>：这也是编辑器基本的功能。<font color="blue">编程函数自动补齐</font>：还在等什么，Have a try（欢迎补充）</p>
<p><font color="red">4. ctrl+s冻结Vim的问题</font></p>
<p>刚开始使用vim的人，会习惯性地使用ctrl+s保存，这将会导致Linux终端被冻结。事实上，ctrl+s会锁住Linux终端的输入和输出。可以使用<strong>crtl+q解除</strong>锁定，恢复正常。</p>
<p>参考手册：</p>
<p><a href="http://vimcdoc.sourceforge.net/doc/intro.html">sourceforge.net上的中文文档</a> | <a href="http://edyfox.codecarver.org/html/vim_edit_tips.html">滇狐大作viki</a> | <a href="http://www.vim.org/">Vim the editor</a> | <a href="http://blog.sina.com.cn/s/blog_46dac66f010005kw.html">善用佳软 介绍vim</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2010/03/vim-recording/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linux iostat监测IO状态</title>
		<link>http://www.orczhou.com/index.php/2010/03/iostat-detail/</link>
		<comments>http://www.orczhou.com/index.php/2010/03/iostat-detail/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 05:13:28 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技术细节]]></category>

		<guid isPermaLink="false">http://www.orczhou.com/?p=1228</guid>
		<description><![CDATA[<p>Linux系统出现了性能问题，一般我们可以通过top、iostat、free、vmstat等命令来查看初步定位问题。其中iostat可以给我们提供丰富的IO状态数据。</p>
<p><font color="red">1. 基本使用</font></p>
<pre>
<div class="mycode">$iostat -d -k 1 10</div>
</pre>
<p>参数 -d 表示，显示设备（磁盘）使用状态；-k某些使用block为单位的列强制使用Kilobytes为单位；1 10表示，数据显示每隔1秒刷新一次，共显示10次。[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2010/03/iostat-detail/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>Linux系统出现了性能问题，一般我们可以通过top、iostat、free、vmstat等命令来查看初步定位问题。其中iostat可以给我们提供丰富的IO状态数据。</p>
<p><font color="red">1. 基本使用</font></p>
<pre>
<div class="mycode">$iostat -d -k 1 10</div>
</pre>
<p>参数 -d 表示，显示设备（磁盘）使用状态；-k某些使用block为单位的列强制使用Kilobytes为单位；1 10表示，数据显示每隔1秒刷新一次，共显示10次。<span id="more-1228"></span></p>
<pre>
<div class="mycode">$iostat -d -k 1 10
Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              39.29        21.14         1.44  441339807   29990031
sda1              0.00         0.00         0.00       1623        523
sda2              1.32         1.43         4.54   29834273   94827104
sda3              6.30         0.85        24.95   17816289  520725244
sda5              0.85         0.46         3.40    9543503   70970116
sda6              0.00         0.00         0.00        550        236
sda7              0.00         0.00         0.00        406          0
sda8              0.00         0.00         0.00        406          0
sda9              0.00         0.00         0.00        406          0
sda10            60.68        18.35        71.43  383002263 1490928140

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda             327.55      5159.18       102.04       5056        100
sda1              0.00         0.00         0.00          0          0
</div>
</pre>
<p><font color="blue">tps</font>：该设备每秒的传输次数（Indicate  the  number  of  transfers  per  second that were issued to the device.）。“一次传输”意思是“一次I/O请求”。多个逻辑请求可能会被合并为“一次I/O请求”。“一次传输”请求的大小是未知的。</p>
<p><font color="blue">kB_read/s</font>：每秒从设备（drive expressed）读取的数据量；<font color="blue">kB_wrtn/s</font>：每秒向设备（drive expressed）写入的数据量；<font color="blue">kB_read</font>：读取的总数据量；<font color="blue">kB_wrtn</font>：写入的总数量数据量；这些单位都为Kilobytes。</p>
<p>上面的例子中，我们可以看到磁盘sda以及它的各个分区的统计数据，当时统计的磁盘总TPS是39.29，下面是各个分区的TPS。（因为是瞬间值，所以总TPS并不严格等于各个分区TPS的总和）</p>
<p><font color="red">2. -x 参数</font></p>
<p>使用-x参数我们可以获得更多统计信息。</p>
<pre>
<div class="mycode">iostat -d -x -k 1 10
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          1.56  28.31  7.80 31.49   42.51    2.92    21.26     1.46     1.16     0.03    0.79   2.62  10.28
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          2.00  20.00 381.00  7.00 12320.00  216.00  6160.00   108.00    32.31     1.75    4.50   2.17  84.20
</div>
</pre>
<p><font color="blue">rrqm/s</font>：每秒这个设备相关的读取请求有多少被Merge了（当系统调用需要读取数据的时候，VFS将请求发到各个FS，如果FS发现不同的读取请求读取的是相同Block的数据，FS会将这个请求合并Merge）；wrqm/s：每秒这个设备相关的写入请求有多少被Merge了。</p>
<p><font color="blue">rsec/s</font>：每秒读取的扇区数；<font color="blue">wsec/</font>：每秒写入的扇区数。<font color="blue">r/s</font>：The number of read requests that were issued to the device per second；<font color="blue">w/s</font>：The number of write requests that were issued to the device per second；</p>
<p><font color="blue">await</font>：每一个IO请求的处理的平均时间（单位是微秒）。这里可以理解为IO的响应时间，一般地系统IO响应时间应该低于5ms，如果大于10ms就比较大了。</p>
<p><font color="blue">%util</font>：在统计时间内所有处理IO时间，除以总共统计时间。例如，如果统计间隔1秒，该设备有0.8秒在处理IO，而0.2秒闲置，那么该设备的%util = 0.8/1 = 80%，所以该参数暗示了设备的繁忙程度。一般地，如果该参数是100%表示设备已经接近满负荷运行了（当然如果是多磁盘，即使%util是100%，因为磁盘的并发能力，所以磁盘使用未必就到了瓶颈）。</p>
<p><font color="red">3. -c 参数</font></p>
<p>iostat还可以用来获取cpu部分状态值：</p>
<pre>
<div class="mycode"><strong>iostat -c 1 10</strong>
avg-cpu:  %user   %nice    %sys %iowait   %idle
           1.98    0.00    0.35   11.45   86.22
avg-cpu:  %user   %nice    %sys %iowait   %idle
           1.62    0.00    0.25   34.46   63.67</div>
</pre>
<p><font color="red">4. 常见用法</font></p>
<pre>
<div class="mycode">$iostat -d -k 1 10        #查看TPS和吞吐量信息
iostat -d -x -k 1 10      #查看设备使用率（%util）、响应时间（await）
iostat -c 1 10            #查看cpu状态
</div>
</pre>
<p><font color="red">5. 实例分析</font></p>
<pre>
<div class="mycode">$$iostat -d -k 1 |grep sda10
Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda10            60.72        18.95        71.53  395637647 1493241908
sda10           299.02      4266.67       129.41       4352        132
sda10           483.84      4589.90      4117.17       4544       4076
sda10           218.00      3360.00       100.00       3360        100
sda10           546.00      8784.00       124.00       8784        124
sda10           827.00     13232.00       136.00      13232        136</div>
</pre>
<p>上面看到，磁盘每秒传输次数平均约400；每秒磁盘读取约5MB，写入约1MB。</p>
<pre>
<div class="mycode">iostat -d -x -k 1
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          1.56  28.31  7.84 31.50   43.65    3.16    21.82     1.58     1.19     0.03    0.80   2.61  10.29
sda          1.98  24.75 419.80  6.93 13465.35  253.47  6732.67   126.73    32.15     2.00    4.70   2.00  85.25
sda          3.06  41.84 444.90 54.08 14204.08 2048.98  7102.04  1024.49    32.57     2.10    4.21   1.85  92.24</div>
</pre>
<p>可以看到磁盘的平均响应时间<5ms，磁盘使用率>80。磁盘响应正常，但是已经很繁忙了。</p>
<p>参考文献：</p>
<ol>
<li>Linux man iostat</li>
<li><a href="http://www.xaprb.com/blog/2010/01/09/how-linux-iostat-computes-its-results/">How Linux iostat computes its results</a></li>
<li><a href="http://www.mjmwired.net/kernel/Documentation/iostats.txt">Linux iostat</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2010/03/iostat-detail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux本地磁盘（硬盘）介绍</title>
		<link>http://www.orczhou.com/index.php/2010/02/linux-disk-hardware/</link>
		<comments>http://www.orczhou.com/index.php/2010/02/linux-disk-hardware/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 12:05:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技术细节]]></category>

		<guid isPermaLink="false">http://www.orczhou.com/?p=1243</guid>
		<description><![CDATA[<p>本文试图从硬件结构、逻辑结构两方面来介绍Linux中本地磁盘的基本知识。</p>
<p><font color="red">1. 硬件结构</font></p>
<p>一块磁盘由多个盘面组成，每个盘面有一个对应的<strong>磁头（heads）</strong>，我们可以在该盘面上存储我们需要的信息。</p>
<p>每一个盘面，被分成多个圆环，我们称之为<strong>柱面（cylinders）</strong>。每一个柱面又被分割为多个扇形区域，简称<strong>扇区（sectors）</strong>，参见下图：</p>
<p><a href="http://www.flickr.com/photos/26825745@N06/4381155033/" title="磁盘扇区 by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2725/4381155033_048953a69d_o.png" width="392" height="275" alt="磁盘扇区" /></a>（图片来源<a href="http://www.eygle.com/">www.eygle.com/</a>）</p>
<p>两个红色环形之间是一个柱面；图中黄色标记部分是一个扇区。[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2010/02/linux-disk-hardware/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>本文试图从硬件结构、逻辑结构两方面来介绍Linux中本地磁盘的基本知识。</p>
<p><font color="red">1. 硬件结构</font></p>
<p>一块磁盘由多个盘面组成，每个盘面有一个对应的<strong>磁头（heads）</strong>，我们可以在该盘面上存储我们需要的信息。</p>
<p>每一个盘面，被分成多个圆环，我们称之为<strong>柱面（cylinders）</strong>。每一个柱面又被分割为多个扇形区域，简称<strong>扇区（sectors）</strong>，参见下图：</p>
<p><a href="http://www.flickr.com/photos/26825745@N06/4381155033/" title="磁盘扇区 by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2725/4381155033_048953a69d_o.png" width="392" height="275" alt="磁盘扇区" /></a>（图片来源<a href="http://www.eygle.com/">www.eygle.com/</a>）</p>
<p>两个红色环形之间是一个柱面；图中黄色标记部分是一个扇区。<span id="more-1243"></span></p>
<p><font color="red">2. fdisk -l 查看磁盘情况</font></p>
<pre>
<div class="mycode">#fdisk -l
Disk /dev/sda: 73.2 GB, 73274490880 bytes
255 heads, 63 sectors/track, 8908 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          16      128488+  83  Linux
/dev/sda2              17        1928    15358140   83  Linux
/dev/sda3            1929        2189     2096482+  82  Linux swap / Solaris
/dev/sda4            2190        8908    53970367+   5  Extended
/dev/sda5            2190        2450     2096451   82  Linux swap / Solaris
/dev/sda6            2451        2711     2096451   82  Linux swap / Solaris
/dev/sda7            2712        2972     2096451   82  Linux swap / Solaris
/dev/sda8            2973        8908    47680888+  83  Linux
</div>
</pre>
<p>可以看到，上面的磁盘/dev/sda有255个磁头，8908个柱面，每个柱面轨道上有63个扇区。因为每个扇区大小为512bytes，所以总大小约为：8908 * 63 * 512 * 255 = 73270794240(和上面的73274490880 相差3696640，不知道是什么地方多出来的)。</p>
<p><font color="red">3. 磁盘分区、文件系统、挂载点</font></p>
<p>我们继续看上面的例子，磁盘/dev/sda共分为8个分区：/dev/sda1，/dev/sda2，&#8230;&#8230;，/dev/sda8，Start和End分别为各个分区的起始和结束柱面。例如分区/dev/sda2从柱面17开始到柱面1928结束，则大小约为（1928-17）* 63 * 512 * 255 = 14.6G。</p>
<p>可以通过df -h来查看分区/dev/sda2的挂载目录：</p>
<pre>
<div class="mycode">#df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              15G   13G  1.1G  92% /
/dev/sda1             122M   20M   96M  17% /boot
tmpfs                 2.0G  669M  1.4G  33% /dev/shm
/dev/sda8              45G   26G   17G  62% /u01
</div>
</pre>
<p>可以看到，分区/dev/sda2挂载根目录 / 上。然后，通过文件/etc/fstab来查看该分区的文件系统：</p>
<pre>
<div class="mycode">#more /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot1            /boot                   ext3    defaults        1 2
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
sysfs                   /sys                    sysfs   defaults        0 0
LABEL=/u01              /u01                    ext3    defaults        1 2
LABEL=SWAP-sda5         swap                    swap    defaults        0 0
LABEL=SWAP-sda6         swap                    swap    defaults        0 0
LABEL=SWAP-sda7         swap                    swap    defaults        0 0
LABEL=SWAP-sda3         swap                    swap    defaults        0 0
</div>
</pre>
<p>看到根目录 / 使用了Linux ext3文件系统。</p>
<p>至此，我们看到磁盘/dev/sda共分为八个分区。其中第二个分区/dev/sda2从柱面17到柱面1928结束，大小约为15G，该分区挂载在根目录 / 上，使用了ext3的文件系统。</p>
<p><font color="red">4. 其他磁盘分区</font></p>
<p>在上面的fdisk -l 列表中我们一共可以看到八个磁盘分区。上面已经分析了/dev/sda2，我们再看来看看其他的分区。</p>
<ul>
<li>在Linux中第一个分区/dev/sda1，为引导扇区，挂载在/boot上</li>
<li>第二个分区挂载在根目录 / 上，大小15G，为ext3文件系统</li>
<li>第三个分区为交换分区，从柱面1929到2189，大小约：（2189 &#8211; 1929）* 63 * 512 * 255 = 2G。</li>
<li>第四个分区为扩展分区，后面四个分区均是该分区的一部分。该分区从柱面2190到8908结束。</li>
<li>分区五、六、七为扩展分区的子分区，均为交换分区，单个大小均为2G。所以全部的交换分区大小共2G + 2G*3 = 8G。</li>
<li>第八个分区为扩展分区的最后一个子分区，挂载在/u01上，大小约为 （8908 &#8211; 2973）* 63 * 512 * 255 = 45G。</li>
</ul>
<p>以上为示例主机上的全部磁盘分区，以及挂载情况。</p>
<p><font color="red">5. 小结</font></p>
<p>有了以上信息，我们就基本清楚了硬件结构以及对应的逻辑结构，需要使用的命令其实也很少：</p>
<div class="mycode">
#fdisk -l<br />
#df -h<br />
#more /etc/fstab
</div>
<p><font color="red">6. 补充</font></p>
<pre>
<div class="mycode"># This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/1                /                       ext3    defaults        1 1
LABEL=/boot1            /boot                   ext3    defaults        1 2
......
</div>
</pre>
<p>关于/etc/fstab的简单补充：</p>
<ul>
<li>第一列是：一般是设备（分区），如也有是LABEL=×××的，这是ext2 ext3特有的卷标，可以通过e2label来查看各个设备的卷标。</li>
<li>第二列是：挂载点</li>
<li>第三列是：文件系统</li>
<li>第四列是：文件系统挂载时候的参数（例如NFS有时候需要用户名密码等）</li>
<li>第五列是：标志是否需要备份1为需要，0为不需要</li>
<li>第六列是：启动时，是否需要fsck检查磁盘1为先检查，2为后检查，0为不检查</li>
</ul>
<p>在fstab文件还有部分第一列是none的，这些都是不需要物理磁盘的文件系统。典型的如/proc文件系统：</p>
<pre>
<div class="mycode">none                    /dev/shm                tmpfs   defaults        0 0
none                    /proc                   proc    defaults        0 0
none                    /sys                    sysfs   defaults        0 0
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2010/02/linux-disk-hardware/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Linux下C语言连接MySQL</title>
		<link>http://www.orczhou.com/index.php/2010/01/linux-c-mysql-api/</link>
		<comments>http://www.orczhou.com/index.php/2010/01/linux-c-mysql-api/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 11:21:30 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[技术细节]]></category>
		<category><![CDATA[Linux Programming]]></category>

		<guid isPermaLink="false">http://www.orczhou.com/?p=1323</guid>
		<description><![CDATA[<p>相对于Window下的设置，Linux要简单的很多。</p>
<p><font color="red">1. 示例程序</font></p>
<pre>
<div class="mycode">$ vi mysql-c-api.c
#include &#60;stdio.h&#62;
#include "mysql/mysql.h"
int main(){
        MYSQL mysql;
        mysq[......]</div></pre><p class='read-more'><a href='http://www.orczhou.com/index.php/2010/01/linux-c-mysql-api/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>相对于Window下的设置，Linux要简单的很多。</p>
<p><font color="red">1. 示例程序</font></p>
<pre>
<div class="mycode">$ vi mysql-c-api.c
#include &lt;stdio.h&gt;
#include "mysql/mysql.h"
int main(){
        MYSQL mysql;
        mysql_init(&#038;mysql);
        mysql_options(&#038;mysql,MYSQL_OPT_COMPRESS,0);
        mysql_options(&#038;mysql,MYSQL_INIT_COMMAND,"SET autocommit=0");
        if (!mysql_real_connect(&#038;mysql,"10.2.3.4","user","passwd","database",0,NULL,0))
        {
                fprintf(stderr, "Failed to connect to database: Error: %sn",
                mysql_error(&#038;mysql));
        }
        return 0;
}
</div>
</pre>
<p><font color="red">2. 编译命令</font></p>
<p>在MySQL编译后的二进制文件中，有一个很有用的二进制文件“<a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-config.html">mysql_config</a>”（一般和mysql命令在同一个目录下），我们可以通过这个程序找到需要的头文件和连接库：</p>
<pre>
<div class="mycode">$ gcc -o a.out $(mysql_config --cflags) <strong>mysql-c-api.c</strong> $(mysql_config --libs)
$ ./a.out
</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2010/01/linux-c-mysql-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>迥异的Linux Shell Script</title>
		<link>http://www.orczhou.com/index.php/2009/09/linux-shell-script/</link>
		<comments>http://www.orczhou.com/index.php/2009/09/linux-shell-script/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 07:44:28 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技术细节]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://orczhou.com/?p=774</guid>
		<description><![CDATA[<p style="text-indent:0">
<strong>作者：</strong><a href="http://www.flickr.com/photos/26825745@N06/3933896112/" title="mail by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2614/3933896112_8ebfd42177_o.png" width="163" height="22" alt="mail" /></a><br />
<strong>摘要：</strong>如果你已经习惯编写Shell脚本，那么一切都显得很自然了。但像我这样，之前已经习惯了C语言(风格)的编程，就觉得Shell并不是那么友好。这里将记录一些Shell和&#8221;C风格&#8221;<strong>迥异</strong>的地方，以供参考。本文测试环境：GNU bash, version 3.00.15(1)-release (i386-redhat-linux-gnu)。文章中很多实例直接来在参考文件[1]、[2]。
</p>
<div style="margin-left:120px">
<a href="http://www.flickr.com/photos/26825745@N06/3930881408/" title="Linux by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2622/3930881408_5033a56de1_o.png" width="318" height="218" alt="Linux" /></a>
</div>
<p>[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2009/09/linux-shell-script/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p style="text-indent:0">
<strong>作者：</strong><a href="http://www.flickr.com/photos/26825745@N06/3933896112/" title="mail by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2614/3933896112_8ebfd42177_o.png" width="163" height="22" alt="mail" /></a><br />
<strong>摘要：</strong>如果你已经习惯编写Shell脚本，那么一切都显得很自然了。但像我这样，之前已经习惯了C语言(风格)的编程，就觉得Shell并不是那么友好。这里将记录一些Shell和&#8221;C风格&#8221;<strong>迥异</strong>的地方，以供参考。本文测试环境：GNU bash, version 3.00.15(1)-release (i386-redhat-linux-gnu)。文章中很多实例直接来在参考文件[1]、[2]。
</p>
<div style="margin-left:120px">
<a href="http://www.flickr.com/photos/26825745@N06/3930881408/" title="Linux by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2622/3930881408_5033a56de1_o.png" width="318" height="218" alt="Linux" /></a>
</div>
<p><span id="more-774"></span></p>
<p style="text-indent:0"><font size=3>1、变量定义等号两边不能有空格</font></p>
<blockquote><p>
#!/bin/bash<br />
myvar=3        #正确<br />
<del datetime="2009-09-16T08:58:09+00:00">myvar   =   3;</del> #等号边多了空格，是错误的！很<strong>迥异</strong>吧
</p></blockquote>
<p style="text-indent:0"><font size=3>1.1、还是空格，这次是不能没有</font></p>
<blockquote><pre>
#!/bin/sh
myVar="OFF"
if [   $myVar = 'OFF'    ];then
#这里[]中括起来的内容<strong>两端必须有</strong>空格，<del datetime="2009-09-17T07:30:53+00:00">if [$myVar = 'OFF']</del>是不能正常工作的。也很<strong>迥异</strong>吧
#注意 if 和 [ 之间也是有空格的！
        echo "works"
else
        echo "Not works"
fi
</pre>
</blockquote>
<p style="text-indent:0"><font size=3>2、双引号和单引号</font></p>
<blockquote><p>
testvar=5<br />
myvar=&#8217;Haha$test&#8217;      #shell<strong>不</strong>会解释$test<br />
myvar2=&#8221;Haha$test&#8221;    #shell会解释$test<br />
echo $myvar $myvar2  #输出：Haha$test Haha5
</p></blockquote>
<p>双引号中的字符如果有变量，shell会尝试解释它，单引号中不会。所以，如果字符串中没有要解释的变量尽量使用单引号，据说速度会快些。</p>
<p>这个到不算很迥异，还有很多其他的语言也都有这样的约定。</p>
<p style="text-indent:0"><font size=3>3、奇怪的算术运算</font></p>
<p>shell中算术运算需要使用$((和))将算术运算括起来</p>
<blockquote><p>
$(( $myvar + 12 ))   #这个非常<strong>迥异</strong>
</p></blockquote>
<p style="text-indent:0"><font size=3>4、case语句</font></p>
<blockquote>
<pre>
case "${x##*.}" in
      gz)
            gzunpack ${SROOT}/${x}
            ;;
      bz2)
            bz2unpack ${SROOT}/${x}
            ;;
      *)
            echo "Archive format not recognized."
            exit
            ;;
esac           #这个比较<strong>迥异</strong> "esac"、";;"、"bz2)"
</pre>
</blockquote>
<p style="text-indent:0"><font size=3>5、函数中的变量作用范围</font></p>
<blockquote>
<pre>
#!/usr/bin/env bash
myvar="hello"
myfunc() {
     myvar="one two three"
     for x in $myvar
     do
         echo $x
     done
}
myfunc
echo $myvar $x
输出：
one
two
three
one two three three  #函数myfunc中的变量，在函数之外仍然存在。
#你可以通过关键字 local 限制变量只在函数中有效果 #这个比较<strong>迥异</strong>
</pre>
</blockquote>
<p>还有更迥异的吗？</p>
<p>参考文献：</p>
<ol>
<li>http://www.ibm.com/developerworks/cn/linux/shell/bash/bash-1/index.html</li>
<li>http://www.ibm.com/developerworks/cn/linux/shell/bash/bash-2/index.html</li>
<li>http://www.ibm.com/developerworks/cn/linux/shell/bash/bash-3/index.html</li>
<li>http://www.linuxsir.org/main/?q=node/135</li>
<li>BASH Programming − Introduction HOW−TO</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2009/09/linux-shell-script/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
