<?xml version="1.0" encoding="gb2312" ?><rss version="2.0">

<channel>
	<title>芽雨快跑</title>
	<link>http://www.yayu.org</link> 
	<description>今天你跑了吗？-- 芽雨快跑 PHP Linux MySQL 原来如此 风之舞 论坛 精美网文 </description>
	<language>zh-cn</language>
	<pubDate>Fri, 03 Jul 2009 09:09:49 +0800</pubDate>
	<copyright>Copyright (C) 2004 - 2009 芽雨快跑 - 本页面所有内容，未经芽雨许可，欢迎转载，但请注明出处</copyright>
	<generator>Yayu'blog</generator>
	<lastBuildDate>Fri, 03 Jul 2009 09:09:49 +0800</lastBuildDate>

	<item>
		<title>整型（int）数字溢出在程序和数据库设计中的考虑</title>
		<link>http://www.yayu.org/look.php?id=175</link>
		<author>yayu</author>
		<pubDate>2009-07-02 20:13:07</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=3">PHP心得</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 在数据库设计和程序中需要考虑数字的范围，否则可能导致一些问题。主要是考虑溢出的问题，比如如果数据库中有一个整型的数字字段，里面的数据可能随着业务的增长而膨胀，而这个数字有可能会超出列属性的范围，也就是溢出，与此同时，程序中也需要处理这个日益庞大的数字，如果其中有运算、数字类型的逻辑比较等等，也可能导致某天就出现了异常。而这种错误又是难以发现的。</P>
<P>&nbsp;&nbsp;&nbsp; 以下试以整型（int）抛砖引玉：</P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>一：MySQL5</STRONG></P>
<P>&nbsp;&nbsp;&nbsp; 以MySQL5版本为例，大多数管理员可能把自增数字、或者其它应用数字字段的列属性设置为int类型，int占用4个字节，而int又分为无符号型和有符号性。对于无符号型的范围是0 到 4294967295；有符号型的范围是-2147483648 到 2147483647。参考资料可见mysql手册：<A href="http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#numeric-types">11.2. 数值类型</A>.</P>
<P>&nbsp;&nbsp;&nbsp; 当要在一个数值列内保存一个超出该列允许范围的值时，MySQL的操作取决于此时有效的SQL模式。如果模式未设置，MySQL将值裁剪到范围的相应端点，并保存裁减好的值。但是，如果模式设置为traditional(“严格模式”)，超出范围的值将被拒绝并提示错误，并且根据SQL标准插入会失败。请参见mysql手册5.3.2节：“<A href="http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#server-sql-mode">SQL服务器模式</A>”。</P>
<P>&nbsp;&nbsp;&nbsp; 如果INT列是UNSIGNED，列范围的大小相同，但其端点会变为到0和4294967295。如果你试图保存-9999999999和9999999999，以非严格模式保存到列中的值是0和4294967296。</P>
<P>&nbsp;&nbsp;&nbsp; 如果在浮点或定点列中分配的值超过指定(或默认)精度和标度规定的范围，MySQL以非严格模式保存表示范围相应端点的值。</P>
<P>&nbsp;&nbsp;&nbsp; 当MySQL没有工作在严格模式时，对于ALTER TABLE、LOAD DATA INFILE、UPDATE和多行INSERT语句，由于裁剪发生的转换将报告为警告。当MySQL工作在严格模式时，这些语句将失败，并且部分或全部值不会插入或更改，取决于是否表为事务表和其它因素。详情参见mysql手册5.3.2节：“<A href="http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#server-sql-mode">SQL服务器模式</A>”。</P>
<P>&nbsp;&nbsp;&nbsp; 二：<STRONG>php5：<BR></STRONG>&nbsp;<BR>&nbsp;&nbsp;&nbsp; 1：整型数的字长和平台有关，PHP 不支持无符号整数。<BR>&nbsp;&nbsp;&nbsp; 2：如果给定的一个数超出了 integer 的范围，将会被解释为 float。同样如果执行的运算结果超出了 integer 范围，也会返回 float。<FONT color=#6809f7>如果在程序中有对数字类型做比较，可能会产生问题。<BR></FONT>&nbsp;&nbsp;&nbsp; 3：可以查看PHP_INT_SIZE、PHP_INT_MAX，以确定整数的范围。<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; 以下列子可供参考：<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; 在32位服务器下：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT><BR>[shengting@localhost ~]$ php -r "echo PHP_INT_SIZE;" <BR>4<BR>[shengting@localhost ~]$ php -r "echo PHP_INT_MAX;" <BR>2147483647<BR>[shengting@localhost ~]$ php -r "var_dump(2147483647);" <BR>int(2147483647)<BR>[shengting@localhost ~]$ php -r "var_dump(2147483648);"<BR>float(2147483648)<BR>[shengting@localhost ~]$ php -r "var_dump(-2147483647);"<BR>int(-2147483647)<BR>[shengting@localhost ~]$ php -r "var_dump(-2147483648);"<BR>float(-2147483648)<BR>[shengting@localhost ~]$ php -r "var_dump(4294967295);"<BR>float(4294967295)<BR>[shengting@localhost ~]$ php -r "var_dump(4294967296);"<BR>float(4294967296)</TD></TR></TBODY></TABLE></P>
<P><BR>&nbsp;&nbsp;&nbsp; 在64位服务器下：<BR>&nbsp;<BR>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT><BR>[root@login shengting]# php -r "echo PHP_INT_SIZE;" <BR>8<BR>[root@login shengting]# php -r "echo PHP_INT_MAX;" <BR>9223372036854775807<BR>[root@login shengting]# php -r "var_dump(2147483647);" <BR>int(2147483647)<BR>[root@login shengting]# php -r "var_dump(2147483648);"<BR>int(2147483648)<BR>[root@login shengting]# php -r "var_dump(-2147483647);"<BR>int(-2147483647)<BR>[root@login shengting]# php -r "var_dump(-2147483648);"<BR>int(-2147483648)<BR>[root@login shengting]# php -r "var_dump(4294967295);"<BR>int(4294967295)<BR>[root@login shengting]# php -r "var_dump(4294967296);"<BR>int(4294967296)<BR></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>三：C/C++</STRONG><BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; 对C/C++也存在有符号和无符号类型的问题。<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; 对于32位系统，如果使用有符号int、long来定义变量保存唯一号就可能出现溢出，并出现上述问题。</P>
<P>&nbsp;&nbsp;&nbsp; 对于64位系统，如果使用int来定义变量保存唯一号就可能出现溢出，并出现上述问题。<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; 可参考 <A href="http://www.ibm.com/developerworks/cn/linux/l-port64.html">http://www.ibm.com/developerworks/cn/linux/l-port64.html</A></P> ]]></description>
	</item>
	<item>
		<title>利用find和sed批量替换文件内容</title>
		<link>http://www.yayu.org/look.php?id=174</link>
		<author>yayu</author>
		<pubDate>2009-06-12 23:49:28</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 这是这个连锁反应：发现apache的log没有分日期、分正误记录 --&gt; 改为分日期、分正误记录log --&gt; 观察错误log，发现有大量404错误 --&gt; 需要修正程序，发现文件路径错误 --&gt; 本机使用Dreamweaver替换路径，提交SVN --&gt; 部署到服务器上时发现文件太多、且分散在子目录中</P>
<P>&nbsp;&nbsp;&nbsp; 怎么办？一个一个找一个一个上传？傻子才干！既然是在FreeBSD下，那就是用强大的命令行工具吧！实践中发现这个方法真的很实用，记录下来！</P>
<P>&nbsp;&nbsp;&nbsp; 需求：把本目录下，包括子目录下的文件，把所有含有“/adm/images/c.gif”的地方替换为“/Admin/Images/c.gif”。</P>
<P>&nbsp;&nbsp;&nbsp; 步骤：找出文件，找到地方，替换。</P>
<P>&nbsp;&nbsp;&nbsp; 寻找命令：找到文件（find，ls），找到地方（grep），替换（sed）。</P>
<P>&nbsp;&nbsp;&nbsp; 现在需要做的，就是组合起来。</P>
<P>&nbsp;&nbsp;&nbsp; 查找资料，有前辈告诫：“find 命令是所有 Linux 命令中最有用的一个，同时也是最混乱的一个”，顿时奔溃。</P>
<P>&nbsp;&nbsp;&nbsp; 还好，发现find命令有个叫“-exec”的，很是强大：find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为'command' {} \;，注意{}和\;之间的空格。</P>
<P>&nbsp;&nbsp;&nbsp; 个人理解：-exec参数中的“{}”是该参数前命令产生的结果的一个变量。感觉类似管道的作用了。</P>
<P>&nbsp;&nbsp;&nbsp; 而且还可以有多个-exec参数，很是强大。基本上grep和sed都可以作为子命令在其中运行了。</P>
<P>&nbsp;&nbsp;&nbsp; 如此一来，可以使用以下命令列出需要替换的字符串所在的行了：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>find ./ -exec grep "/adm/images/c.gif" '{}' \;</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 然后再使用一个-exec参数吧sed包含进来吧。</P>
<P>&nbsp;&nbsp;&nbsp; sed 的工作方式：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>sed 实用工具按顺序逐行将文件读入到内存中。然后，它执行为该行指定的所有操作，并在完成请求的修改之后将该行放回到内存中，以将其转储至终端。完成了这一行上的所有操作之后，它读取文件的下一行，然后重复该过程直到它完成该文件。默认输出是将每一行的内容输出到屏幕上。在这里，开始涉及到两个重要的因素—首先，输出可以被重定向到另一文件中，以保存变化；第二，源文件（默认地）保持不被修改。sed 默认读取整个文件并对其中的每一行进行修改。不过，可以按需要将操作限制在指定的行上。</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 注意后面提到的源文件不会修改，不过sed提供了-i参数，可以做到控制是否可以修改源文件。-i参数的描述，Linux和FreeBSD下不太一样，后来也发现Linux在命令的使用方便上的确是要强于FreeBSD的。分述如下：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>&nbsp;FreeBSD 4.7-STABLE下：<BR>&nbsp;&nbsp;&nbsp;&nbsp; -i extension<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edit files in-place, saving backups with the specified extension.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If a zero-length extension is given, no backup will be saved.&nbsp; It<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; is not recommended to give a zero-length extension when in-place<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; editing files, as you risk corruption or partial content in situ-<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ations where disk space is exhausted, etc.</P>
<P>Linux下：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -i[SUFFIX], --in-place[=SUFFIX]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; edit files in place (makes backup if extension supplied)</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; FreeBSD下说如果-i参数后面的后缀如果为0，则不产生备份文件，结果我试了好几次都没有搞定，不得已，使用了一个备份文件来存储源文件，然后修改源文件：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT><BR>find ./ -exec grep "/adm/images/c.gif" '{}' \; -exec sed -i .bak 's/\/adm\/images\/c.gif/\/Admin\/Images\/c.gif/g' {} \;</TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 比如下面的就不行，老提示错误，望知情者指教：<BR>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT><BR>find ./ -exec grep "/adm/images/c.gif" '{}' \; -exec sed -i 's/\/adm\/images\/c.gif/\/Admin\/Images\/c.gif/g' {} \;</TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; Linux下，可以不产生备份文件直接修改了：<BR>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT><BR>find ./ -exec grep "/adm/images/c.gif" '{}' \; -exec sed -i 's/\/adm\/images\/c.gif/\/Admin\/Images\/c.gif/g' {} \;</TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 当然，需要强调的是：备份还是很重要的！切记切记！</P>
<P>&nbsp;&nbsp;&nbsp; 本文环境如下：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>FreeBSD：<BR>FreeBSD 4.7-STABLE
<P>Linux：<BR>[root@bsso Admin_bak]# cat /etc/issue<BR>CentOS release 4.1 (Final)<BR>Kernel \r on an \m<BR>[root@bsso Admin_bak]# sed --version<BR>GNU sed version 4.1.2<BR>Copyright (C) 2003 Free Software Foundation, Inc.<BR>This is free software; see the source for copying conditions.&nbsp; There is NO<BR>warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,<BR>to the extent permitted by law.</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 另：<BR>&nbsp;&nbsp;&nbsp; 1：FreeBSD下如何查看sed的版本呢？<BR>&nbsp;&nbsp;&nbsp; 2：网上看见资料说，类似下面的语句应该是可以达到目的，当我在FreeBSD和Linux下都没有运行成功<BR>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT><BR>sed -i 's/\/adm\/images\/c.gif/\/Admin\/Images\/c.gif/g' `grep -rf "/adm/images/c.gif"`</TD></TR></TBODY></TABLE></P>
<P><BR>&nbsp;&nbsp;&nbsp; 参考资料：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>
<P>Linux文件查找命令find,xargs详述<BR><A href="http://www.linuxsir.org/main/?q=node/137">http://www.linuxsir.org/main/?q=node/137</A><BR>Linux Find 命令精通指南<BR><A href="http://www.oracle.com/technology/global/cn/pub/articles/calish-find.html">http://www.oracle.com/technology/global/cn/pub/articles/calish-find.html</A><BR>使用 sed 编辑器<BR><A href="http://www.oracle.com/technology/global/cn/pub/articles/dulaney_sed.html">http://www.oracle.com/technology/global/cn/pub/articles/dulaney_sed.html</A><BR>linux sed 批量替换多个文件中的字符串<BR><A href="http://www.admin99.net/read.php/108.htm">http://www.admin99.net/read.php/108.htm</A></P></TD></TR></TBODY></TABLE></P> ]]></description>
	</item>
	<item>
		<title>在北京混那可是奋斗的一生哇！</title>
		<link>http://www.yayu.org/look.php?id=173</link>
		<author>yayu</author>
		<pubDate>2009-05-19 23:43:09</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=2">随便说说</category>
		<description><![CDATA[ &nbsp;&nbsp;&nbsp; 看北京房价，有感，如题。 ]]></description>
	</item>
	<item>
		<title>sort命令分析日志</title>
		<link>http://www.yayu.org/look.php?id=172</link>
		<author>yayu</author>
		<pubDate>2009-04-28 22:52:31</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 很久没有更新blog了，上来冒个泡。</P>
<P>&nbsp;&nbsp;&nbsp; 之前，常用cut,sort,uniq命令的组合分析程序的log，或者查看数据以便统计。例如：cut -d "|" -f 4 | sort | uniq -n -r。</P>
<P>&nbsp;&nbsp;&nbsp; 今天遇到一个问题，需要查看多个用户的操作记录。数据第一列可顺利的按照时间排序，然而用户名在中间，既然是log，那源数据便可能是多个用户的交叉记录了。比如：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>time0 | userA | action<BR>time1 | userB | action<BR>time2 | userC | action<BR>time3 | userA | action<BR>time4 | userC | action<BR>time5 | userB | action<BR>time6 | userC | action<BR>time7 | userB | action</TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 很显然，我们希望的顺序是:</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>time0 | userA | action<BR>time3 | userA | action<BR>time1 | userB | action<BR>time5 | userB | action<BR>time7 | userB | action<BR>time2 | userC | action<BR>time4 | userC | action<BR>time6 | userC | action</TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 我们既想按照中间的数据的排序又要保持数据的完整性！也许可以用其他的命令实现这个，但我更倾向于使用常用的命令搞定复杂的事情。</P>
<P>&nbsp;&nbsp;&nbsp; 其实sort命令是可以实现这个的。sort的-t选项可以实现cut的-d功能，再利用+m -n参数可以实现cut的-f的功能，只是，sort的这个+m -n是从0开始计数的。+m -n是指从第m个字段开始，到第n个字段排序，其中包含第m个但不包含第n个。比如:sort -t "|" +1 -2 filename 就可以得到我们想要的结果了。</P>
<P>&nbsp;&nbsp;&nbsp; sort的功能是排序，应用起来会有很多种排序的方式，可以用指定的参数来控制：</P>
<P>&nbsp;&nbsp;&nbsp; - d 按字典顺序排序，比较时仅字母、数字、空格和制表符有意义。这个选项对 uniq -d 后的结果尤为有用。<BR>&nbsp;&nbsp;&nbsp; - f 将小写字母与大写字母同等对待。也就是忽略大小写。<BR>&nbsp;&nbsp;&nbsp; - I 忽略非打印字符。<BR>&nbsp;&nbsp;&nbsp; - M 作为月份比较：“JAN”&lt;“FEB”<BR>&nbsp;&nbsp;&nbsp; - r 按逆序输出排序结果。这个可与 -d 同时使用，实现数字从大到小的排列</P>
<P>&nbsp;&nbsp;&nbsp; 还有一个很实用的功能，如果你想把一个过滤后的文件内容重新写入到原文件，那么- o 参数可以达到这个要求，但是效率呢？嗯，是个问题，看取舍了！毕竟这种情况重定向是不行的。</P>
<P>&nbsp;&nbsp;&nbsp; - o 输出文件 将排序输出写到输出文件中而不是标准输出，如果输出文件是输入文件之一，sort先将该文件的内容写入一个临时文件，然后再排序和写输出结果。</P>
<P>&nbsp;&nbsp;&nbsp; 很多系统实用小工具就是用这种常用名字组建的，嗯哼。</P> ]]></description>
	</item>
	<item>
		<title>在招行专业版查看信用卡信息</title>
		<link>http://www.yayu.org/look.php?id=171</link>
		<author>yayu</author>
		<pubDate>2009-03-31 14:41:52</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=2">随便说说</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 晕菜，想在招行专业版上信用卡的信息，看了专业版给的提示，提示我要么去柜台，要么先自动关联自动还款的一卡通。不想关联自动还款，于是去柜台，结果一进门就被工作人员忽悠到打招行信用卡800电话，然后被接线生很温柔地忽悠说招行专业版的客户服务里面就可以搞定。Y的，一群骗子。</P>
<P>&nbsp;&nbsp;&nbsp; 最后通过招行的网站客服搞定了事情，没办法，还是得先关联自动还款的一卡通。下面是网上客服的解释。</P>
<P>&nbsp;&nbsp;&nbsp; 招行网上客服的效率还是不错的，于是想想天朝的备案什么时候也能有这个效率呢？！从事互联网，还是这个备案的单位轻松啊。</P>
<P>------------------------ 喜欢忽悠的分割线 ------------------------</P>
<P>&nbsp;&nbsp;&nbsp; 您可以通过大众版或者电话办理。</P>
<P>&nbsp;&nbsp;&nbsp; 请您登录信用卡网上银行<A href="http://www.8008205555.com/">www.8008205555.com</A>，点击“系统登录”输入身份证件号码、查询密码和附加码就能登录网上银行，然后在“还款管理”的下拉框中选择“自动还款设置”即可设置自动还款功能。向您说明一下：到期还款日前一天24点之前申请，当期自动还款才能生效，生效后即会从您一卡通上扣除本期帐款。需提醒您，您只能关联本人的一卡通，且一卡通证件号码、证件类型需与信用卡的一致，同时自扣当日勿往信用卡内存款，以免引起重复扣款。</P>
<P>&nbsp;&nbsp;&nbsp; 或请您致电客服热线800-820-5555，手机用户拨打021-38784800或者4008205555，在语音中选择“1”中文服务后，选择“1”持卡人服务，选择“1”帐务查询与还款，选择“2”自动还款，再选择“1”申请自动还款，即可开通一卡通自动扣款功能。</P>
<P>&nbsp;&nbsp;&nbsp; 绑定后就可以在“专业版管理”--“证书关联信用卡操作”，把信用卡关联到专业版了。</P> ]]></description>
	</item>
	<item>
		<title>估算Apache所需要的内存</title>
		<link>http://www.yayu.org/look.php?id=170</link>
		<author>yayu</author>
		<pubDate>2009-03-25 19:21:45</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 精确的计算所需要的内存是很困难的，为了尽可能的精确，需要观察类似线上环境下观察服务器的负载和进程。毕竟如果不同的服务器配置和装的模块是有差异的，只有查看自己才可靠，所谓核心的东西要掌握在自己手里大概如此。。。。</P>
<P>&nbsp;&nbsp;&nbsp; 一个简单可靠的法子是，在压力测试时，找到httpd进程，查看一个进程使用了多少的内存，然后看看总的进程，即可估算一下。</P>
<P>&nbsp;&nbsp;&nbsp; 比如：<BR>&nbsp;&nbsp;&nbsp; ps aux | grep httpd<BR>&nbsp;&nbsp;&nbsp; 查看每个httpd进程使用了多少内存，数字在第四列，格式为百分之几。</P>
<P>&nbsp;&nbsp;&nbsp; ps aux | grep httpd | wc -l<BR>&nbsp;&nbsp;&nbsp; 得到一共有多少进程，记得结果要减1，因为grep httpd也在结果中。</P>
<P>&nbsp;&nbsp;&nbsp; free<BR>&nbsp;&nbsp;&nbsp; 查看服务器内存总量，单位为K</P>
<P>&nbsp;&nbsp;&nbsp; 然后就可以估算了。比如一个进程占2%的内存，有27个httpd，总内存为4148424。那就是:<BR>php -r "echo 0.002*4148424*26/1024;"<BR>&nbsp;&nbsp;&nbsp; 结果为210.66215625M内存，这个只仅仅是为apache分配的。还得给其它服务留出足够空余的内存。而且考虑高峰期可能会比平时大12倍，这个时候仅仅考虑Apache就够了，嘿嘿。曾经出现过因磁盘IO过高导致服务器崩溃的场景。</P>
<P>&nbsp;&nbsp;&nbsp; 如果怎么算都不能让服务器有空余的内存，就得考虑限制最大进程数了。使用MaxClient指令可以用来限制。</P>
<P>&nbsp;&nbsp;&nbsp; 以上说得有误之处，还请各位指点！</P> ]]></description>
	</item>
	<item>
		<title>介绍“最好的编程字体”Monaco</title>
		<link>http://www.yayu.org/look.php?id=169</link>
		<author>yayu</author>
		<pubDate>2009-03-24 15:09:59</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=5">扩展学习</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 同事看见我的编程界面，不禁大呼“你的编程字体好丑”。立马无地自容，我真太不专业了！竟然不知道还有“编程字体”这个概念。。。。。。</P>
<P>&nbsp;&nbsp;&nbsp; 于是同事立即推荐了好几个字体，看我都不满意，于是拿出了他的压箱货：Monaco。苹果出品，据称是最好看的编程字体，主要是优化英文字体，对中文也有效。尤其能分清楚0oO，而且很锐化，看见的不再是规规矩矩了。</P>
<P>&nbsp;&nbsp;&nbsp; 为方便大家下载，我把字体放到Google上了，直接下载地址<A href="http://xieyayu.googlepages.com/MONACO.zip">http://xieyayu.googlepages.com/MONACO.zip</A>。新浪旗下产品爱问也可以下载：<A href="http://ishare.iask.sina.com.cn/f/4944524.html">http://ishare.iask.sina.com.cn/f/4944524.html</A>，但是爱问只能保存三个月，有点不爽。</P>
<P>&nbsp;&nbsp;&nbsp; Windows下，下载字体解压后放到C:\WINDOWS\Fonts下即可，然后就可以到编辑器里设置了。比如EditPlus下在字体中选择“Monaco”即可，如果不希望中文也是Monaco，第一次看见时会感觉有点奇怪，可以在language中选择“East Europe”。</P>
<P>&nbsp;&nbsp;&nbsp; Ubuntu下将字体mv至字体目录下：/usr/share/fonts/truetype/ 任一地方，建一个新目录也行。记得给每个用户/组有读权限。然后需要做的是刷新FreeType字体文件的索引。</P>
<P>&nbsp;&nbsp;&nbsp; 需要使用命令fc-cache。作用：“build font information cache files”。其实就是扫描字体目录，把信息写入缓存文件，然后应用程序在启动时会读这个文件，这样你就可以在应用程序配置中选择这个缓存文件中的字体了。这个命令可以扫描系统全部字体目录也可以只扫描更新你指定的，就看你在命令后是否给出字体目录了。</P>
<P>&nbsp;&nbsp;&nbsp; 常用的选项有:<BR>&nbsp;&nbsp;&nbsp; -f 强行重建缓存，force的意思。<BR>&nbsp;&nbsp;&nbsp; -v 显示命令执行信息，view的意思。</P>
<P>&nbsp;&nbsp;&nbsp; 正确执行命令后，在当前终端或新开一个终端，均不能选择Monaco字体，需要关掉打开的终端，再新开的终端才能进行选择。</P>
<P>&nbsp;&nbsp;&nbsp; 希望对你有用！</P> ]]></description>
	</item>
	<item>
		<title>Apache配置文件学习（一）</title>
		<link>http://www.yayu.org/look.php?id=168</link>
		<author>yayu</author>
		<pubDate>2009-03-11 21:40:22</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 1：&lt;IfDefine [!]parameter-name&gt; ... &lt;/IfDefine&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;而parameter-name是在服务启动时，通过httpd命令行的 -Dparameter 这样的形式指定的。</P>
<P>&nbsp;&nbsp;&nbsp; 2：&lt;IfModule [!]module-file|module-identifier&gt; ... &lt;/IfModule&gt;<BR>&nbsp;&nbsp;&nbsp; module可以是模块的标识符或者是编译模块时的文件名。比如，rewrite_module就是一个模块标识符，而mod_rewrite.c则是编译模块时的文件名。如果模块包含多个源代码文件，您应当使用包含 STANDARD20_MODULE_STUFF 字符串的那个。</P>
<P>&nbsp;&nbsp;&nbsp; 而STANDARD20_MODULE_STUFF请参考：《<A href="http://hi.baidu.com/kylelee/blog/item/f13fef2c7366bceb8b1399c9.html">编写第一个Apache模块——mod_helloworld</A>》</P>
<P>&nbsp;&nbsp;&nbsp; 3：User/Group指令用于设置实际提供服务的子进程的用户/组。为了使用这个指令，服务器必须以root身份启动和初始化。如果你以非root身份启动服务器，子进程将不能够切换至非特权用户/组，并继续以启动服务器的原始用户身份运行。如果确实以root用户启动了服务器，那么父进程将仍然以root身份运行。</P>
<P>&nbsp;&nbsp;&nbsp; Unix-userid是下列值之一：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>&nbsp;1：一个用户名/组：通过用户名/组引用用户/组 <BR>&nbsp;2："#"号后面跟一个用户/组编号 ：通过用户/组编号引用用户/组 </P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 用于运行子进程的用户必须是一个没有特权的用户/组，这样才能保证子进程无权访问那些不想为外界所知的文件，同样的，该用户/组亦需没有执行那些不应当被外界执行的程序的权限。</P>
<P>&nbsp;&nbsp;&nbsp; 进程的用户及层次关系可见：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>[root@login yayu]# pstree -apu | grep http <BR>&nbsp; |-httpd,10914 -DSSL<BR>&nbsp; |&nbsp;&nbsp; |-httpd,8483,web -DSSL<BR>&nbsp; |&nbsp;&nbsp; |-httpd,8489,web -DSSL<BR>&nbsp; |&nbsp;&nbsp; |-httpd,8551,web -DSSL<BR>&nbsp; |&nbsp;&nbsp; |-httpd,8552,web -DSSL<BR>&nbsp; |&nbsp;&nbsp; |-httpd,8553,web -DSSL<BR>&nbsp; |&nbsp;&nbsp; |-httpd,8554,web -DSSL<BR>&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |-grep,8558 http</TD></TR></TBODY></TABLE></P>
<P><BR>&nbsp;&nbsp;&nbsp; 4：如果在&lt;VirtualHost&gt;外设置了一个ServerName，而一个请求不能与某个ServerName指令相匹配，它将会由第一个&lt;VirtualHost&gt;段所伺服。</P>
<P>&nbsp;&nbsp;&nbsp; 5：ServerRoot指令设置了服务器所在的目录。一般来说它将包含conf/和logs/子目录。其它配置文件的相对路径即基于此目录 (比如Include或LoadModule)。而指定ServerRoot、DocumentRoot时不应包括最后的"/"。</P>
<P>&nbsp;&nbsp;&nbsp; 6：Order指令控制默认的访问状态与Allow和Deny指令生效的顺序，变态的命令。</P>
<P>&nbsp;&nbsp;&nbsp; 下面例子中，apache.org域中所有主机，除了foo.apache.org子域包含的主机被拒绝以外，其他都允许访问。而所有不在apache.org域中的主机都不允许访问，因为默认状态是拒绝对服务器的访问。</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>Order Allow,Deny<BR>Allow from apache.org<BR>Deny from foo.apache.org </TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 另一方面，如果上个例子中的Order指令改变为"Deny,Allow"，将允许所有主机的访问。这是因为，不管配置文件中指令的实际顺序如何，"Allow from apache.org"指令会最后被评估到并覆盖之前的"Deny from foo.apache.org"。所有不在apache.org域中的主机也允许访问是因为默认状态被改变到了允许。说白了就是控制Allow和Deny两个指定的顺序。</P> ]]></description>
	</item>
	<item>
		<title>Apache配置之ServerType的standalone和inetd模式</title>
		<link>http://www.yayu.org/look.php?id=167</link>
		<author>yayu</author>
		<pubDate>2009-03-09 18:35:49</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 不仔细看httpd.conf配置文件还不知道有这回事，汗。</P>
<P>&nbsp;&nbsp;&nbsp; ServerType这个配置选项指定如何运行Apache。Apache可以使用两种方法来运行：standalone(独立式)和inetd(超级守护进程式)。 </P>
<P>&nbsp;&nbsp;&nbsp; standalone模式表示Apache进程以一个单独的守护进程方式在后台监听是否有客户端的请求，如果有则生成一个子进程来为其服务。在standalone模式下，apache进程一次性启动，运行期间一直驻留在内存中，尽管损耗了一定的系统资源，但接入信号反应快；而且子httpd进程在http请求完毕后并没有直接断掉，这样就可以重新用来接受新的http请求，请参考apache的keepalive指令（<A href="http://www.ourapache.com/archives/tag/keepalive">请看这里</A>）。由于不存在对每个请求都启动新的apache根进程，所以它的效率更高。</P>
<P>&nbsp;&nbsp;&nbsp; inetd模式表示Apache服务不是以一个单独的守候进程的形式支持。而是由Inetd这个超级守候进程进行代劳，当它监听一个客户端的http请求的时候，再启动一个httpd进程为其服务。一个由inted运行的服务器进程在它结束对请求服务的同时立刻退出，虽然不占用了系统资源，但是也由此不适合应用在同时连接数量较多的系统。因为如果请求完毕后就结束httpd进程，会使服务器负担加重。 </P>
<P>&nbsp;&nbsp;&nbsp; 具体使用如下：</P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>standalone模式</STRONG></P>
<P>&nbsp;&nbsp;&nbsp; 此种模式下，Apache服务器监听特定端口的连接请求。当用户发起特定端口地址的连接请求时，主服务器进程启动子httpd进程来响应该请求。</P>
<P>&nbsp;&nbsp;&nbsp; 这样还需要告诉主服务器进程侦听的特定端口地址，使用命令： </P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>Port [number] （缺省值为80）</P></TD></TR></TBODY></TABLE>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>inetd模式</STRONG> </P>
<P>&nbsp;&nbsp;&nbsp; inetd是监听所有小于1024的端口连接请求的Internet守护进程(一个服务器进程)。与standalone模式不同，当客户系统发出到Apache服务器的连接请求时，inetd启动一个httpd进程，由此进程服务此请求，完成服务后即退出。</P>
<P>&nbsp;&nbsp;&nbsp; 如果选择通过inetd服务器来运行Apache，需要编辑/etc/inetd.conf文件为Apache添加一条新的记录： </P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>httpd stream tcp nowait httpd /etc/httpd/bin/httpd –f /etc/httpd/conf/httpd.conf </P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 修改了/etc/inetd.conf文件后，就需要修改/etc/services中添加一行 </P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>httpd 80/tcp httpd </P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 做完以上修改后，需要重新启动inetd进程。首先，使用以下命令取得inetd的进程ID： </P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>ps auxw | grep inetd </P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 然后执行命令：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>kill -HUP pid</P></TD></TR></TBODY></TABLE></P> ]]></description>
	</item>
	<item>
		<title>Linux进程的层次关系</title>
		<link>http://www.yayu.org/look.php?id=166</link>
		<author>yayu</author>
		<pubDate>2009-02-16 19:40:04</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 前段时间在看清华大学出版社出版的《Linux教程》（05年6月第一版）。在248页第十三章《进程》有一节是简述Linux进程的层次关系的，把操作系统自启动后都做了什么，说得比较清晰，看过后受益匪浅。</P>
<P>&nbsp;&nbsp;&nbsp; 就是喜欢看这种能把整个框架说得比较清楚的文章！特抄来以共享：</P>
<P>&nbsp;&nbsp;&nbsp; 当打开Linux系统，LILO（LInux LOader）找到Linux内核把它加载到内存。它初始化各种硬件，包括磁盘控制器。然后转到保护模式，加载操作系统，执行初始化各种内核数据结构的代码，例如inode和文件表。此进程的PID为0。它启动初试进程（init进程，PID为1）完成引导过程的其余工作。init进程启动守护进程kflushd、kupdate、kpiod和kswapd，其PID分别为2、3、4、5。Init进程然后初始化文件系统，安装根文件系统。接下来试着执行/sbin/init程序，在每一个激活的终端上执行minegetty进程（经常被称为getty进程）。getty进程设置终端属性，如波特率，这些属性在/etc/termcap文件中都有定义。它显示login:提示符，等待用户登录。</P>
<P>&nbsp;&nbsp;&nbsp; 在login:提示符下，输入登录名并按回车键，getty进程产生一个子进程。它转变为以登录名为参数的登录进程。登录进程提示输入密码，并检查输入名和密码的有效性。如果两者均正确，登录进程产生一个子进程，它将转变为登录shell。如果登录进程没有在/etc/passwd文件中找到登录名或者输入的密码与/etc/passwd文件中（或者/etc/shadow文件）存放的密码不匹配，他将显示错误提示信息然后终止。控制权又回到getty进程，重新显示login:提示符。一旦进入登录shell，就可以完成自己的工作，还可以按&lt;ctrl-D&gt;键终止当前shell。如果这样做了，shell进程会终止，控制权又回到getty进程，再次显示login:提示符，又开始循环。</P>
<P>&nbsp;&nbsp;&nbsp; 就是说，当登录到Linux系统，系统产生第一个进程，称为登录进程，它又创建登录shell。登录shell为所输入的命令创建进程，用以解释/执行命令。</P>
<P>&nbsp;&nbsp;&nbsp; 两个Linux进程贯穿系统生命周期：swapper和init进程。监视终端行的getty进程，只要终端与系统关联上就会一直存在。登录进程和登录shell进程只有在登录时才存在。所有其它进程生存期较短，只在命令或者程序执行时短暂存在。</P>
<P>&nbsp;&nbsp;&nbsp; ps -ef 命令或者pstree命令可以用图的形式显示当前系统中执行进程的进程树，勾勒出进程间的父子关系。pstree命令显示的图比ps -ef命令更简洁。pstree显示的结果，前有“+”的是当前的后台进程，而前面的有“-”的是后续后台进程。pstree命令使用-h参数，输出用粗体（加亮）显示当前进程。使用“-a”选项，pstree显示带参数的命令。如“pstree 402 -a”可以显示PID为402的进程的那个的层次关系。</P>
<P>&nbsp;&nbsp;&nbsp; Bash shell可以使用ulimit显示用户可以同时执行的最大进程个数。TC shell下为limit。两个命令都可以用来显示硬件和操作系统资源的使用限制。</P> ]]></description>
	</item>
	<item>
		<title>与君共勉：有想法 就行动</title>
		<link>http://www.yayu.org/look.php?id=165</link>
		<author>yayu</author>
		<pubDate>2009-02-13 18:56:33</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=2">随便说说</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 与君共勉：有想法 就行动。</P>
<P>&nbsp;&nbsp;&nbsp; 蜀之鄙有二僧，其一贫，其一富。贫者语于富者曰：“吾欲之南海，何如？”。富者曰：“子何恃而往？”曰：“吾一瓶一钵足矣”。富者曰：“吾数年来欲买舟而下，犹未&shy;能也。子何恃而往？”。越明年，贫者自南海还，以告富者。富者有惭色。</P> ]]></description>
	</item>
	<item>
		<title>查看、分析memcached使用状态</title>
		<link>http://www.yayu.org/look.php?id=164</link>
		<author>yayu</author>
		<pubDate>2009-02-12 22:44:51</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 访问量上升，数据库压力大，怎么办？好办法是在中间挡一层缓存！这个缓存要求高效，不能比数据库慢，否则服务质量受影响；如果能把数据用hash打散存储到硬盘，也是可以的，不过在内存越来越便宜的今天，还是使用内存吧！</P>
<P>&nbsp;&nbsp;&nbsp; mysql也有自己的缓存，也是存储在内存的，但是有一个说法是：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>只能有一个实例<BR>意味着你能存储内容的上限就是你服务器的可用内存，一台服务器能有多少内存？你又能存多少呢？ </P>
<P>只要有写操作，mysql的query cache就失效<BR>只要数据库内容稍有改变，那怕改变的是其他行，mysql的query cache也会失效</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 再说，如果mysql都抗不住了，怎么还能指望它提供的缓存呢？</P>
<P>&nbsp;&nbsp;&nbsp; 所以我可以使用memcached了！他的好处和如何用可以参考：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>
<P>1：《<A href="http://www.ourmysql.com/archives/415">Memcache和mysql交互流程操作原理</A>》</P>
<P>2：《<A href="http://www.ourmysql.com/archives/195">让memcached和mysql更好的工作</A>》</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 开发时面对需求是个麻烦事，更漫长而闹心的是维护，所以我更关心的是memcached运行中的情况。还好的是，memcached的作者给我们提供查看运行情况的命令。主要是“stats”，使用方法为 “telnet ip 端口号”，登录后使用“stats”命令。</P>
<P>&nbsp;&nbsp;&nbsp; 然后你可以看见很多内容，具体可以参考：《<A href="http://lists.danga.com/pipermail/memcached/2006-March/002065.html">memcacche stats</A>》</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>pid = process id<BR>uptime = number of seconds since the process was started<BR>time = current time<BR>version = memcached version<BR>rusage_user = seconds the cpu has devoted to the process as the user<BR>rusage_system = seconds the cpu has devoted to the process as the system<BR>curr_items = total number of items currently in memcache<BR>total_items = total number of items that have passed through the cache<BR>bytes = total number of bytes currently in use by curr_items<BR>curr_connections = total number of open connections to memcached<BR>connection_structures = ???<BR>cmd_get = total GET commands issued to the server<BR>cmd_set = total SET commands issued to the server<BR>get_hits = total number of times a GET command was able to retrieve and<BR>return data<BR>get_misses = total number of times a GET command was unable to retrieve and<BR>return data<BR>bytes_read = total number of bytes input into the server<BR>bytes_written = total number of bytes written by the server<BR>limit_maxbytes = total storage bytes available to the server.</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 着重说一下几个对观测很有用的项。</P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>limit_maxbytes、bytes</STRONG></P>
<P>&nbsp;&nbsp;&nbsp; memcached在存储的时候是可以设置失效时间的，但如果存储已经满了，那旧数据即使没有到过期时间，也会被移除。所以需要观察memcached存储是否已经满了，同时这对扩容也是有意义的参考。limit_maxbytes即总的存储大小，而bytes就是已经使用的大小，从这两个数据就可以看出在memcached启动时，我们为它分配的内存是否足够使用。</P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>cmd_get、cmd_set</STRONG></P>
<P>&nbsp;&nbsp;&nbsp; memcached启动后，我们对它一共做了多少次读取操作呢？从这两个参数可以观察出来。</P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>get_hits、get_misses</STRONG></P>
<P>&nbsp;&nbsp;&nbsp; 使用memcached后，我们需要评估我们使用的策略是否合理。不能够使用中间缓存后，后端的数据库还是有较大的访问量，这样的话中间缓存就变得没有意义了。get_hits表示命中了多少次读取，即来memcached取到了多少有效数据；get_misses表示没有命中的次数，即此次来取数据的时候，memcached并没有你所查询的数据。如果没有清零统计数据的话，cmd_get = get_hits + get_misses。</P>
<P>&nbsp;&nbsp;&nbsp; memcached 的状态查询还有其它的命令，可以参考：《<A href="http://blog.alwaysmylove.net/2008/04/10/stats-command-in-memcached/">Memcached的stats命令</A>》</P>
<P>&nbsp;&nbsp;&nbsp; 如下：</P>
<P>stats reset<BR>清空统计数据</P>
<P>stats malloc<BR>显示内存分配数据</P>
<P>stats maps<BR>这个不太确定，看源代码是把/proc/self/maps的数据显示出来。</P>
<P>stats cachedump slab_id limit_num<BR>显示某个slab中的前limit_num个key列表，显示格式如下<BR>ITEM key_name [ value_length b; expire_time|access_time s]<BR>其中，memcached 1.2.2及以前版本显示的是&nbsp; 访问时间(timestamp)<BR>1.2.4以上版本，包括1.2.4显示 过期时间(timestamp)<BR>如果是永不过期的key，expire_time会显示为服务器启动的时间</P>
<P>stats cachedump 7 2<BR>ITEM copy_test1 [250 b; 1207795754 s]<BR>ITEM copy_test [248 b; 1207793649 s]</P>
<P>stats slabs<BR>显示各个slab的信息，包括chunk的大小、数目、使用情况等</P>
<P>stats items<BR>显示各个slab中item的数目和最老item的年龄(最后一次访问距离现在的秒数)</P>
<P>stats detail [on|off|dump]<BR>设置或者显示详细操作记录</P>
<P>参数为on，打开详细操作记录<BR>参数为off，关闭详细操作记录<BR>参数为dump，显示详细操作记录(每一个键值get、set、hit、del的次数)</P>
<P>stats detail dump<BR>PREFIX copy_test2 get 1 hit 1 set 0 del 0<BR>PREFIX copy_test1 get 1 hit 1 set 0 del 0<BR>PREFIX cpy get 1 hit 0 set 0 del 0</P> ]]></description>
	</item>
	<item>
		<title>实时观察Apache访问情况的工具Apachetop</title>
		<link>http://www.yayu.org/look.php?id=163</link>
		<author>yayu</author>
		<pubDate>2009-02-11 20:39:44</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; Linux服务器的负载、进程等信息可以通过top命令查看。而Apache的运转如何实时的观察呢？“tail -f”log文件？这是个好方法，但是太累了！</P>
<P>&nbsp;&nbsp;&nbsp; 所以，感谢Chris Elsworth为我们提供了类似top命令的apachetop命令！官网地址：<A href="http://www.webta.org/projects/apachetop/">http://www.webta.org/projects/apachetop/</A></P>
<P>&nbsp;&nbsp;&nbsp; apachetop可以查看最近一段时间和自命令执行以来的apache访问情况，信息包括被访问的文件、次数、流量大小。</P>
<P>&nbsp;&nbsp;&nbsp; 命令安装、使用可以查看官网提供的说明：<A href="http://www.webta.org/projects/apachetop/browser/README">http://www.webta.org/projects/apachetop/browser/README</A>,或者查看一个中文的解释：《<A href="http://www.ourapache.com/archives/130">实时跟踪log变化的工具Apachetop</A>》。 </P>
<P>&nbsp;&nbsp;&nbsp; 在此我对命令显示信息和一些好用的参数做一下说明。</P>
<P>&nbsp;&nbsp;&nbsp; 先看命令显示：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>
<P>last hit: 11:19:12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; atop runtime:&nbsp; 0 days, 07:12:27&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 11:19:13<BR>All:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1553476 reqs (&nbsp; 59.9/sec)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3566.4M (&nbsp; 140.7K/sec)&nbsp;&nbsp;&nbsp; 2407.3B/req<BR>2xx: 1458916 (93.9%) 3xx:&nbsp;&nbsp; 93768 ( 6.0%) 4xx:&nbsp;&nbsp; 787 ( 0.1%) 5xx:&nbsp;&nbsp;&nbsp;&nbsp; 5 ( 0.0%)<BR>R ( 30s):&nbsp;&nbsp;&nbsp; 1692 reqs (&nbsp; 56.4/sec)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4342.8K (&nbsp; 144.8K/sec)&nbsp;&nbsp;&nbsp; 2628.3B/req<BR>2xx:&nbsp;&nbsp;&nbsp; 1606 (94.9%) 3xx:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 85 ( 5.0%) 4xx:&nbsp;&nbsp;&nbsp;&nbsp; 1 ( 0.1%) 5xx:&nbsp;&nbsp;&nbsp;&nbsp; 0 ( 0.0%)</P>
<P>&nbsp;REQS REQ/S&nbsp;&nbsp;&nbsp; KB KB/S URL<BR>&nbsp; 916 30.53&nbsp; 1202 40.1*/api/chk.php<BR>&nbsp;&nbsp; 71&nbsp; 2.37 433.7 14.5 /login.php<BR>&nbsp;&nbsp; 50&nbsp; 1.67&nbsp; 44.6&nbsp; 1.5 /css/css.css<BR>&nbsp;&nbsp; 39&nbsp; 1.50 506.4 19.5 /js/js.js</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 第一行的“last hit: 11:19:12”和“11:19:13”分别显示此次显示时的最后观察时间，和现在的时间。不过我对这个时间很不理解，因为这个世界和系统的时间是不一致的。不知道是我理解有误还是怎么回事，忘有知情的朋友留言告诉我。</P>
<P>&nbsp;&nbsp;&nbsp; 第一行中间的部分表示这个命令运行了多长时间。</P>
<P>&nbsp;&nbsp;&nbsp; 第二、三行显示的是自命令执行以来观察到的所有数据汇总。第四、五行显示的是近30表的数据汇总。前一行表示：总请求数、每秒处理的请求数、总的数据传输量、每个请求的数据传输量。后一行显示http响应类型、此类型的总数、每秒的此类型的响应数。这个还是很好理解的。</P>
<P>&nbsp;&nbsp;&nbsp; 再往后的数据则从访问量大小排列出了是哪些程序在被访问。格式照上也很好理解。</P>
<P>&nbsp;&nbsp;&nbsp; 有几个很有用的参数值的学习一下。</P>
<P>&nbsp;&nbsp;&nbsp; -f：这个参数指定了apachetop命令观察的对象。并不是每个人的apache的日志都在默认的位置，甚至你为了统计的方便，使用多个日志文件来区分不同的端口（80、443）、正确和错误的访问日志、等等。这个时候可以使用这个参数来指定log文件。尤其有用的是，你可能需要同时查看多个log的情况，这时你可以多次使用-f参数来制定，如： apachetop -f file1 -f file2。</P>
<P>&nbsp;&nbsp;&nbsp; -d：默认情况下，显示界面每5秒刷新一次，如果你觉得刷新频率不爽，你可以使用这个参数来做改变。</P>
<P>&nbsp;&nbsp;&nbsp; -T：上面的例子中，我们在最后面看到的是最近30秒的情况。如果你觉得密度不够，可以使用这个参数来做改变。</P>
<P>&nbsp;&nbsp;&nbsp; -H：还是上面的例子，可以看到最近30秒的请求总数是：1606+85+1+0=1692次。如果你想让每请求N次刷新一次界面怎么办？哈，就是使用这个命令了！</P>
<P>&nbsp;&nbsp;&nbsp; 注意：-T和-H参数是不能同时使用的，否则会提示你：“-T and -H are mutually exclusive. Specify only one.”</P>
<P>&nbsp;&nbsp;&nbsp; -q：有一些程序，在使用的时候是可以带参数的，即get方式。如果你想看看都是些什么参数，就可以使用这个命令了！</P>
<P>&nbsp;&nbsp;&nbsp; 看完以后，不要忘了，如果你知道第一行的“last hit: 11:19:12”和“11:19:13”分别显示的是什么，别忘了告诉我。。。。。</P> ]]></description>
	</item>
	<item>
		<title>Linux下查看文件和文件夹大小的df和du命令</title>
		<link>http://www.yayu.org/look.php?id=162</link>
		<author>yayu</author>
		<pubDate>2009-02-09 18:07:41</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 当磁盘大小超过标准时会有报警提示，这时如果掌握df和du命令是非常明智的选择。</P>
<P>&nbsp;&nbsp;&nbsp; df可以查看一级文件夹大小、使用比例、档案系统及其挂入点，但对文件却无能为力。<BR>&nbsp;&nbsp;&nbsp; du可以查看文件及文件夹的大小。</P>
<P>&nbsp;&nbsp;&nbsp; 两者配合使用，非常有效。比如用df查看哪个一级目录过大，然后用df查看文件夹或文件的大小，如此便可迅速确定症结。</P>
<P>&nbsp;&nbsp;&nbsp; 下面分别简要介绍</P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>df命令可以显示目前所有文件系统的可用空间及使用情形</STRONG>，请看下列这个例子：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>[yayug@yayu ~]$ df -h<BR>Filesystem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Size&nbsp; Used Avail Use% Mounted on<BR>/dev/sda1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.9G&nbsp; 300M&nbsp; 3.4G&nbsp;&nbsp; 8% /<BR>/dev/sda7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 100G&nbsp; 188M&nbsp;&nbsp; 95G&nbsp;&nbsp; 1% /data0<BR>/dev/sdb1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 133G&nbsp;&nbsp; 80G&nbsp;&nbsp; 47G&nbsp; 64% /data1<BR>/dev/sda6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7.8G&nbsp; 218M&nbsp; 7.2G&nbsp;&nbsp; 3% /var<BR>/dev/sda5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7.8G&nbsp; 166M&nbsp; 7.2G&nbsp;&nbsp; 3% /tmp<BR>/dev/sda3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9.7G&nbsp; 2.5G&nbsp; 6.8G&nbsp; 27% /usr<BR>tmpfs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.0G&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp; 2.0G&nbsp;&nbsp; 0% /dev/shm</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 参数 -h 表示使用「Human-readable」的输出，也就是在档案系统大小使用 GB、MB 等易读的格式。</P>
<P>&nbsp;&nbsp;&nbsp; 上面的命令输出的第一个字段（Filesystem）及最后一个字段（Mounted on）分别是档案系统及其挂入点。我们可以看到 /dev/sda1 这个分割区被挂在根目录下。</P>
<P>&nbsp;&nbsp;&nbsp; 接下来的四个字段 Size、Used、Avail、及 Use% 分别是该分割区的容量、已使用的大小、剩下的大小、及使用的百分比。 FreeBSD下，当硬盘容量已满时，您可能会看到已使用的百分比超过 100%，因为 FreeBSD 会留一些空间给 root，让 root 在档案系统满时，还是可以写东西到该档案系统中，以进行管理。</P>
<P>&nbsp;&nbsp;&nbsp;<STRONG> du：查询文件或文件夹的磁盘使用空间 </STRONG></P>
<P>&nbsp;&nbsp;&nbsp; 如果当前目录下文件和文件夹很多，使用不带参数du的命令，可以循环列出所有文件和文件夹所使用的空间。这对查看究竟是那个地方过大是不利的，所以得指定深入目录的层数，参数：--max-depth=，这是个极为有用的参数！如下，注意使用“*”，可以得到文件的使用空间大小.</P>
<P>&nbsp;&nbsp;&nbsp; <STRONG>提醒</STRONG>：一向命令比linux复杂的FreeBSD，它的du命令指定深入目录的层数却是比linux简化，为 -d。</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>[root@bsso yayu]# du -h --max-depth=1 work/testing<BR>27M&nbsp;&nbsp;&nbsp;&nbsp; work/testing/logs<BR>35M&nbsp;&nbsp;&nbsp;&nbsp; work/testing</P>
<P>[root@bsso yayu]# du -h --max-depth=1 work/testing/*<BR>8.0K&nbsp;&nbsp;&nbsp; work/testing/func.php<BR>27M&nbsp;&nbsp;&nbsp;&nbsp; work/testing/logs<BR>8.1M&nbsp;&nbsp;&nbsp; work/testing/nohup.out<BR>8.0K&nbsp;&nbsp;&nbsp; work/testing/testing_c.php<BR>12K&nbsp;&nbsp;&nbsp;&nbsp; work/testing/testing_func_reg.php<BR>8.0K&nbsp;&nbsp;&nbsp; work/testing/testing_get.php<BR>8.0K&nbsp;&nbsp;&nbsp; work/testing/testing_g.php<BR>8.0K&nbsp;&nbsp;&nbsp; work/testing/var.php</P>
<P>[root@bsso yayu]# du -h --max-depth=1 work/testing/logs/<BR>27M&nbsp;&nbsp;&nbsp;&nbsp; work/testing/logs/</P>
<P>[root@bsso yayu]# du -h --max-depth=1 work/testing/logs/*<BR>24K&nbsp;&nbsp;&nbsp;&nbsp; work/testing/logs/errdate.log_show.log<BR>8.0K&nbsp;&nbsp;&nbsp; work/testing/logs/pertime_show.log<BR>27M&nbsp;&nbsp;&nbsp;&nbsp; work/testing/logs/show.log</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 值得注意的是，看见一个针对du和df命令异同的文章：《<A href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008716/133217.html">du df 差异导致文件系统误报解决</A>》。</P>
<P>&nbsp;&nbsp;&nbsp; du 统计文件大小相加 <BR>&nbsp;&nbsp;&nbsp; df&nbsp; 统计数据块使用情况 </P>
<P>&nbsp;&nbsp;&nbsp; 如果有一个进程在打开一个大文件的时候,这个大文件直接被rm 或者mv掉，则du会更新统计数值，df不会更新统计数值,还是认为空间没有释放。直到这个打开大文件的进程被Kill掉。</P>
<P>&nbsp;&nbsp;&nbsp; 如此一来在定期删除 /var/spool/clientmqueue下面的文件时，如果没有杀掉其进程，那么空间一直没有释放。</P>
<P>&nbsp;&nbsp;&nbsp; 使用下面的命令杀掉进程之后，系统恢复。<BR>&nbsp;&nbsp;&nbsp; fuser -u /var/spool/clientmqueue</P> ]]></description>
	</item>
	<item>
		<title>不是每个人都和你想的一样</title>
		<link>http://www.yayu.org/look.php?id=161</link>
		<author>yayu</author>
		<pubDate>2009-02-09 15:57:12</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=2">随便说说</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 不是每个人都和你想的一样，从上到下皆是。</P>
<P>&nbsp;&nbsp;&nbsp; 大的方面说。</P>
<P>&nbsp;&nbsp;&nbsp; 2008年2月5日晚，央视一套播出2008年《感动中国》人物的颁奖仪式，颁奖仪式打破常规（其实学老外：<A href="http://news.sina.com.cn/w/2006-12-17/113111813350.shtml">在这里</A>），将年度特别奖授予了全体中国人（<A href="http://news.sina.com.cn/c/2009-02-06/104717161633.shtml">在这里</A>）。白岩松的颁奖说词如下（<A href="http://blog.sina.com.cn/s/blog_49daf0ea0100c7t7.html">这里有</A>）:</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>我们每一个人都有权接过这个奖杯，因为我们都是获奖者。然而，我们每一个人都没有理由，让这个奖杯，在我们的身边停留得太久，因为我们只是十三亿分之一。历史会认同，2008年这份特殊的奖励，此刻我们看到这个奖杯，真的觉得它意味深长，这是因为它是在孩子手里。</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 可是，很多有独立思考的人并不这么想。</P>
<P>&nbsp;&nbsp;&nbsp; 著名律师刘晓原在博文《<A href="http://blog.sina.com.cn/s/blog_49daf0ea0100c7t7.html">拒领“2008感动中国”年度特别奖</A>》里以一个中国普通公民身份表达自己的声音：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>
<P>　　我是一个无贡献者，也是一个守法公民。与有功绩者一起获奖，我感到受之有愧；与腐败分子一同获奖，我感到无地自容。作为一个有自知之明的公民，我在此郑重地声明，拒绝领取中央电视台颁发的“感动中国”年度特别奖。基于奖项是授予全体中国人的，我拒绝领取其中的十三亿分之一“份额”。<BR>　　我只是一名普通公民，做不了感动国家的事情，敬请中央电视台予以谅解!</P>
<P>　　　　　　　　　　　　　　　　　　　　北京市忆通律师事务所刘晓原律师</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 童话大王郑渊洁似乎也赞同这个观点。当然，搞文学的比较含蓄，于是借咬文嚼字的提出了抗议：（“抗议”是我的臆断）（<A href="http://blog.sina.com.cn/s/blog_473abae60100ct05.html">原文在这里</A>）</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>“中国人”的概念应该是所有持有中华人民共和国护照（包括台湾护照）的人。“全体中国人”当选2008年感动中国年度特别奖，自然也必须包括陈水扁和两岸所有东窗事发和尚未穿帮的贪官。</P>
<P>........................</P>
<P>&nbsp;&nbsp;&nbsp; 我国今年的《国防白皮书》就因为使用错了一个标点符号，引起外国误解。那句话是这样的：“中国主张所有核武器国家明确承诺全面、彻底销毁核武器，并承诺停止研发新型核武器，降低核武器在国家安全政策中的作用。”结果外国各大媒体都使用通栏大标题争先恐后报道：中国承诺停止研发新型核武器！</P>
<P>........................</P>
<P>&nbsp;&nbsp;&nbsp; 作为中国人，说好中国话写好中国文很重要。语言是民族的立身之本，秦始皇最伟大的功绩是在中国统一了文字。为什么中国到现在还没分裂？统一的文字是头功。全体中国人在没有充分到位掌握母语之前趋之若鹜本末倒置学外文，对民族不是幸事。无源之水无本之木多了，民族就有成为海市蜃楼的风险。</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp; 如果你不了解“神奇的国度”的含义，你可能理解不了他们为啥要挑刺，“给脸不要脸”。不过你可以看看这个《<A href="http://www.somelog.com/index.php?id=371">不是我说的</A>》来理解一下，然后看看《<A href="http://www.somelog.com/index.php?id=368">专家又变卦了……</A>》来加深一下理解。</P>
<P>&nbsp;&nbsp;&nbsp; 小的方面说。</P>
<P>&nbsp;&nbsp;&nbsp; 上网的用户都是怎么想的呢？许晓辉说“<A href="http://blog.sina.com.cn/s/blog_59199cb50100c2q4.html">你和用户其实想得不一样·白天不懂夜的黑</A>”：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>&nbsp;用户不关心流氓。春节回家用大姐的电脑，发现首页是1616.net导航站；刚上一年级的外甥女很流利的打开2144.cn玩flash小游戏；而地址栏搜索是QQ的天下。就在我们高谈阔论流氓推广的时候，广大网民已经在大大小小的网站上乐不思蜀了。对于像大姐家小孩一样的初级网民而言，他们根本就不关心什么流氓推广，只要产品好用就行，即使不好用他们也不知道如何卸载。这也就是网址导航站、网络实名等能够迅速普及的原因。（诸如1616、2144这类网站，你从网上很难找到他们的作者是谁，但却真真实实的安装到了无数电脑之中，并为幕后作者提供着源源不断的广告收入）</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;可是我回家在网吧上网看见的不是这样的，用户貌似很明确自己的目的。网吧的系统一般请一个公司来装，然后这个公司就把这个机器的IE主页设置为自己做的。比如我来的这个网吧，他弄的主页类似百度，正中是一个百度的搜索框，四周再整点导航，百度的搜索框很很醒目。然而，我看见左边座位上先后两个人都是打开默认主页后，无视醒目的百度搜索框，而是很熟练的在地址栏里面敲入“www.baidu.com”。动作之熟练，令我汗颜：）</P>
<P>&nbsp;&nbsp;&nbsp; 不过，我和许晓辉看见的用户数很少，不足以作为数据说明。或许，这也就是我一直所想的，做网站不一定要功能全面，能够满足一部分的用户的需求，就已经足够了。</P>
<P>&nbsp;&nbsp;&nbsp; 一直不敢多议他人，皆源于此。</P> ]]></description>
	</item>
	<item>
		<title>小糊涂了一把，哈哈</title>
		<link>http://www.yayu.org/look.php?id=160</link>
		<author>yayu</author>
		<pubDate>2009-01-19 19:30:44</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=2">随便说说</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 以前遇到过这种事情，今天又糊涂了一把。</P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>[root@login yayu]# ls -la<BR>.............................<BR>-rw-r--r--&nbsp; 1 root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 49 Jan 19 19:20 loglog<BR>[root@login yayu]# <BR>[root@login yayu]# cat loglog <BR>Directory "/data2/logs/error" is not exists<BR>[root@login yayu]# <BR>[root@login yayu]# ls -l /data2/logs/error<BR>ls: /data2/logs/error: No such file or directory</P></TD></TR></TBODY></TABLE> ]]></description>
	</item>
	<item>
		<title>PHP的变量也不是随意能转化的及bash的算术运算</title>
		<link>http://www.yayu.org/look.php?id=159</link>
		<author>yayu</author>
		<pubDate>2008-12-30 20:47:02</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=3">PHP心得</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一直以为PHP的变量是很灵活的，类型想怎么变换就怎么变换。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 但实际上并不是这样，当一个变量被赋值为数字时，是变换不了数组的，比如：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT></P>
<P>[root@localhost shengting]# cat test.php<BR>&lt;?php<BR>$a = 454;<BR>$b = 6;<BR>$a['gfgo'] = $b;</P>
<P>var_dump($a);<BR>?&gt;</P>
<P>[root@localhost shengting]# php test.php <BR><STRONG>PHP Warning:&nbsp; Cannot use a scalar value as an array in /usr/home/shengting/test.php on line 4</STRONG></P>
<P>Warning: Cannot use a scalar value as an array in /usr/home/shengting/test.php on line 4<BR><STRONG><FONT color=#ff0033>int(454)</FONT></STRONG></P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 从var_dump的结果看，不仅有Warning级的错误，赋值也没有成功。而，如果变量一开始是字符串的话，就没这回事情了：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>[root@localhost shengting]# cat test.php<BR>&lt;?php<BR>$a = `454`;<BR>$b = 6;<BR>$a['gfgo'] = $b;</P>
<P>var_dump($a);<BR>?&gt;<BR>[root@localhost shengting]# php test.php <BR>sh: 454: command not found<BR>array(1) {<BR>&nbsp; ["gfgo"]=&gt;<BR>&nbsp; int(6)<BR>}</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 可以看出，赋值是成功的。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 应该，这个是和存储的类型是有联系的。同样，在Shell的Bash中，所有的变量的值都是以字符串方式存储的。尽管这个特性使得bash的数据处理起来很容易，但是也使得数字运算比较困难。原因就是数字也是以字符串的形式存储的，</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在Bash中，如果要对数字进行算术运算和逻辑操作，必须先转化为整数（可视为中间值），得到运算结果后再转化为字符串，以便正确的保存在Bash变量中。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bash提供了三种方式的数字数据进行算术变量：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>1：使用let命令。<BR>2：使用shell扩展 $((expression))<BR>3：使用expr命令</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 具体用法就不说了，哈哈。偶比较喜欢使用第二种。</P> ]]></description>
	</item>
	<item>
		<title>做个有意思的小网站，看着它长大</title>
		<link>http://www.yayu.org/look.php?id=158</link>
		<author>yayu</author>
		<pubDate>2008-12-29 21:16:29</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=2">随便说说</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp; 今天通过Google Reader看见<A title='“一米六二的北漂生活"' href="http://www.162cm.com/archives/756.html">一米六二的北漂生活</A>里的一个文章，说他“一直梦想着做一个NB的不行帅到让人拉一裤子的小东西”，看完文章，突然觉得很感动，这不也是我想做的么？！</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 他弄的是一个叫做“<A href="http://xiaoqianbao.com/">小钱包</A>”的网站，是“一个好玩的、简单的不能再简单了的在线记账应用”的网站。应用的确是很简单，可是当你自己根据兴趣去做一件事情的时候，难道不觉得很有成就感么？这个也是我从事互联网的引子，可是这种感觉随着工作而消逝，想着不禁觉得茫茫然。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 其实很早以前，我就一直想做一个小应用，管他几个人用，自己觉得爽就行。或许发展以后就成了潮流的东西，比如Google的“friend connect”，不就一个跨网站的友情链接么？这也是两年前我已经想到的东西，哈哈，YY一下！</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 今天的一切，来自昨天的努力；明天的一切，来自今天的努力。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 坚持是一种美德，我一直在想根据现有的人力物力做一个小网站，初步功能已经成型，那就是一个博客导航的网站，地址：<A href="http://www.blogread.cn/">http://www.blogread.cn/</A>。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这个小网站说白了，一个网址导航。在这里你可以提交你喜欢的博客，记得不要忘记写上博客的标签（又名“tag”），<STRONG>写上标签，你可以找到与之相似的博客</STRONG>。现在的功能很简单，但是我会一步一步在业余时间逐步增加功能，说不定你下次来，会发现它给了你一个惊喜！</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 或许你会觉得界面不太好看，这的确是个郁闷的话题。不着急，美工会一步一步好的。您觉得不爽可以下次再来看看：）</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 本不想现在介绍我的博客导航，毕竟还不完善。但是看到一米六二的文章，突然有种冲动就写上以上的文字。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 做事情，是需要激情的，不然会一直拖着，直到消逝而去。</P> ]]></description>
	</item>
	<item>
		<title>Shell进制运算错误：08: value too great for base</title>
		<link>http://www.yayu.org/look.php?id=157</link>
		<author>yayu</author>
		<pubDate>2008-12-19 12:18:51</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=7">Linux/Unix</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 昨天发现一个很奇怪的bug，一个分析log的程序，一个小时产生一个log文件，文件名中含有当时的小时数以作标识，其中小时为有前导零的24 小时格式。bug是第08和09小时的log为空，甚为诧异。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 分析程序后，定位于08和09这两个数字上。程序中有一步需要对小时数进行数学运算，问题就在于此，例如：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：<BR></FONT>[root@login yayu]# echo $((08 -2))<BR>bash: 08: value too great for base (error token is "08")</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Google了一下找到了答案：<A href="http://linux.chinaunix.net/bbs/viewthread.php?tid=1025418">原文点这！[建议新窗口打开]</A></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 原因：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT><BR>Numbers starting with leading 0 are Octal numbers&nbsp;&nbsp;(base 8) in many programming<BR>languages including C, Perl and shell. Valid octal digits are <BR>0,1,2,3,4,5,6,7 so it barfs if it sees an 8 or a 9. You probably want<BR>to work in straight numbers and make a leading 0 in your output<BR>format with a sprintf("%02d") kind of formatting thing.<BR>Anything starting with 0x or 0X is a hex number.<BR><BR>So the error message means exactly as it says- it's an error from<BR>the let function complaining about the value being too big for the base.<BR><BR>Have fun,<BR>Stuart.</TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 解决方案：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#fdfddf><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是代码片段：</FONT><BR>You can explicitly state the base of a number using base#number<BR>Code:<BR>if [ $((10#$item)) -eq 0 ] ; then<BR>That will have trouble if the number starts with a minus sign.<BR>The '-' needs to be in front of the base like -10#009 for -9.</TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 原来是进制的问题，C, Perl&nbsp;和 shell中以0开头的数字是八进制了，而在运算中也是严格如此，不会做自动转化，于是就报错了。如下解决：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT><BR>[root@login shengting]# echo $((10#08 -2))<BR>6</TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 纠结问题的根源，还是我的shell写得太烂了......如果命令用得好就不会遇到这个bug了，不过写得好了，又怎么会在以后避免进制导致的问题呢？到底是先有鸡还是先有蛋呢？</P> ]]></description>
	</item>
	<item>
		<title>查看MySQL创建外键约束失败详细原因的方法</title>
		<link>http://www.yayu.org/look.php?id=156</link>
		<author>yayu</author>
		<pubDate>2008-12-10 12:24:26</pubDate>
		<category domain="http://www.yayu.org/categroy.php?id=9">MySQL学习</category>
		<description><![CDATA[ <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 首先，目前MySQL的外键约束只适用于InnoDB数据表。</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 创建外键约束时，如果把握不好，将无法创建，比如提示你：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>ERROR 1005 (HY000): Can't create table './dbname/tablename.frm' (errno: 150)</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 为了查看更详细的信息，mysql提供了一个命令：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>show innodb status;</P>
<P>或者：</P>show engine&nbsp;innodb status;</TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其中有一项“LATEST FOREIGN KEY ERROR”显示了最近的一次外键约束出错的详细信息，如：</P>
<P>
<TABLE style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>
<TBODY>
<TR>
<TD style="WORD-WRAP: break-word" bgColor=#f3f3f3>
<P><FONT style="FONT-WEIGHT: bold; COLOR: #990000">以下是引用片段：</FONT></P>
<P>LATEST FOREIGN KEY ERROR<BR>------------------------<BR>081210 11:57:40 Error in foreign key constraint of table dbname/tablename:<BR>foreign key (`gid`, `uid`) references `table2`(`gid`, `uid`)<BR>) ENGINE = InnoDB:<BR>Cannot find an index in the referenced table where the<BR>referenced columns appear as the first columns, or column types<BR>in the table and the referenced table do not match for constraint.<BR>Note that the internal storage type of ENUM and SET changed in<BR>tables created with &gt;= InnoDB-4.1.12, and such columns in old tables<BR>cannot be referenced by such columns in new tables.<BR>See <A href="http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html">http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html</A><BR>for correct foreign key definition.</P></TD></TR></TBODY></TABLE></P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; <STRONG>提问：不知道mysql其它的错误，有没有方法得到这样的提示？</STRONG></P> ]]></description>
	</item>
</channel>
</rss>