<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.5" -->
<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/"
	>

<channel>
	<title>HICK 者，乡巴佬也</title>
	<link>http://www.hickwu.com</link>
	<description>HICK 者，乡巴佬也，玩 linux, php, python, Emacs, and love open source and programming</description>
	<pubDate>Mon, 15 Jun 2009 14:18:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>
	<language>en</language>
			<item>
		<title>数据管理2(Beginning Linux Programming 笔记11)</title>
		<link>http://www.hickwu.com/?p=271</link>
		<comments>http://www.hickwu.com/?p=271#comments</comments>
		<pubDate>Mon, 15 Jun 2009 14:18:53 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>Linux 编程</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=271</guid>
		<description><![CDATA[p297 文件锁定
有两种类型的文件锁定，最常见的是非内核实现的劝告式锁定(advisory locking)，其方法是所有进程遵循一个约定，也就是下面说的文件锁。另外一种是强制锁(mandatory locking)，它是由内核强制实施的，当一个锁被创建时，其他进程对被锁文件进行读写操作时会被挂起，椅子后到锁定释放，因为锁定在 read 和 write 上，会降低系统调用的性能。
文件锁定对多用户多任务操作系统是非常重要的，进程之间经常需要通过文件来共享数据。linux 下的文件锁不仅仅可以通过创建锁定文件(lock file)的原子操作来保证操作唯一性，还能针对文件的某一部分做排他性访问的锁操作。有一种说法，分别称这俩种锁为文件锁和记录锁(record lock)。
如果程序需要排他性的访问某个资源，可以通过先创建一个约定的文件锁的方式，约定其他访问该资源的程序都先检查该文件是否存在。处理完某个资源后，把该锁文件 unlink ，以便其他进程访问该资源。linux 系统一般把文件锁创建在 /var/spool 下。使用 open 创建文件锁时，需要使用 O_CREAT 和 O_EXCL 标识，这样才能以原子操作的方式保证创建有效锁，下面的程序中，只创建了锁，没有释放锁：
#include &#60;unistd.h&#62;#include &#60;stdlib.h&#62;#include &#60;stdio.h&#62;#include &#60;fcntl.h&#62;#include &#60;errno.h&#62;int main(){&#160;&#160; &#160;int file_desc;&#160;&#160; &#160;int save_errno;&#160;&#160; &#160;file_desc = open(&#34;/tmp/LCK.test&#34;, O_RDWR &#124; O_CREAT &#124; O_EXCL, 0444);&#160;&#160; &#160;if (file_desc == -1) {&#160;&#160; &#160; &#160; &#160;save_errno = errno;&#160;&#160; &#160; &#160; &#160;printf(&#34;Open failed [...]]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=271</wfw:commentRss>
		</item>
		<item>
		<title>数据管理1(Beginning Linux Programming 笔记10)</title>
		<link>http://www.hickwu.com/?p=270</link>
		<comments>http://www.hickwu.com/?p=270#comments</comments>
		<pubDate>Sun, 14 Jun 2009 05:14:18 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>Linux 编程</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=270</guid>
		<description><![CDATA[本章主要讲 linux 的动态内存管理、文件锁定以及 dbm 数据库.
p289 linux 中最基本的内存操作为 malloc 函数:
#include &#60;stdlib.h&#62;void *malloc(size_t size);#example:#include &#60;unistd.h&#62;#include &#60;stdlib.h&#62;#include &#60;stdio.h&#62;#define A_MEGABYTE (1024 * 1024)int main() {&#160;&#160; &#160;char *some_memory;&#160;&#160; &#160;int&#160; megabyte = A_MEGABYTE;&#160;&#160; &#160;int exit_code = EXIT_FAILURE;&#160;&#160; &#160;some_memory = (char *)malloc(megabyte);&#160;&#160; &#160;if (some_memory != NULL) {&#160;&#160; &#160; &#160; &#160;sprintf(some_memory, &#34;Hello World\n&#34;);&#160;&#160; &#160; &#160; &#160;printf(&#34;%s&#34;, some_memory);&#160;&#160; &#160; &#160; &#160;exit_code = EXIT_SUCCESS;&#160;&#160; &#160;}&#160;&#160; [...]]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=270</wfw:commentRss>
		</item>
		<item>
		<title>Linux 环境2(Beginning Linux Programming 笔记9)</title>
		<link>http://www.hickwu.com/?p=269</link>
		<comments>http://www.hickwu.com/?p=269#comments</comments>
		<pubDate>Sat, 13 Jun 2009 06:33:59 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>Linux 编程</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=269</guid>
		<description><![CDATA[p181 时间和日期
linux 下时间一般用 long int 型的类型 time_t ，其定义在 time.h 中，我们可以通过 time 函数获得 UNIX 时间戳值，原型以及实例如下:
// 原型#include &#60;time.h&#62;time_t time(time_t *tloc);// 实例#include &#60;time.h&#62;#include &#60;stdio.h&#62;#include &#60;unistd.h&#62;#include &#60;stdlib.h&#62;int main(){&#160;&#160; &#160;int i;&#160;&#160; &#160;time_t the_time;&#160;&#160; &#160;for(i = 1; i &#60;= 10; i++) {&#160;&#160; &#160; &#160; &#160;the_time = time((time_t *)0);&#160;&#160; &#160; &#160; &#160;printf(&#34;The time is %ld\n&#34;, the_time);&#160;&#160; &#160; &#160; &#160;sleep(2);&#160;&#160; &#160;}&#160;&#160; &#160;exit(0);}
该函数返回时间戳，同时把时间戳保存字 tlog [...]]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=269</wfw:commentRss>
		</item>
		<item>
		<title>Linux 环境1(Beginning Linux Programming 笔记8)</title>
		<link>http://www.hickwu.com/?p=268</link>
		<comments>http://www.hickwu.com/?p=268#comments</comments>
		<pubDate>Sun, 07 Jun 2009 00:32:56 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>Linux 编程</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=268</guid>
		<description><![CDATA[p170 程序参数
先明确两个概念：选项、选项参数。比如 gcc -g -o test test.c ，这里 g 和 o 是选项，其中 test 是 o 的选项参数，一般也直接称为参数。
c 语言里最常见的 main 函数原型：
int main(int argc, char *argv[])
其中 argc 为选项和参数的个数， argv 为选项和参数字符串数组。
p171 在 main 函数中可以直接读取上面的两个变量获得参数信息：
$ myprog left right ‘and center’rgc: 4argv: {“myprog”, “left”, “right”, “and center”}
由于一些历史原因，linux/unix 下的命令的选项和参数格式并没有得到很好的统一规和范。比如解压缩命令 tar zxvf httpd-2.0.59.tar.gz ，查看当前目录文件列表命令 ls -lt 或者 ls -l -t 。一般建议使用横杠加单个字符或者数字的方式，没有附加参数的选项一般跟上面的 ls 命令一样，可以合并到横杠以后。有些命令会有相对应的反向操作命令，比如 [...]]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=268</wfw:commentRss>
		</item>
		<item>
		<title>文件操作4(Beginning Linux Programming 笔记7)</title>
		<link>http://www.hickwu.com/?p=267</link>
		<comments>http://www.hickwu.com/?p=267#comments</comments>
		<pubDate>Sat, 06 Jun 2009 00:59:14 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>Linux 编程</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=267</guid>
		<description><![CDATA[p152 stream 错误： 标准 io 库出错的时候，通常都返回一个 null 指针或者 EOF ，同时把错误的具体信息保存到全局变量 errno 中。这是个很多函数比如 fprintf 都可能改写的变量，只有当出错时，其值才具备参考价值。
#include &#60;errno.h&#62;extern int errno;
由于文件到达末尾和出错都可能返回同样的值比如 EOF ，库函数提供一些方法来区分。
#include &#60;stdio.h&#62;int ferror(FILE *stream);int feof(FILE *stream);void clearerr(FILE *stream);
ferror 用来检查 stream 上是否发生了错误，没有出错返回 0 ，出错返回非 0 值。 feof 检测是否到达了 stream 的末尾，非 0 值表示到达文件末尾。
stream 和 fd 的关系： 每个 stream 都和个 fd 相关联，甚至是 fd 的操作和 stream 的操作在转换后可以混合使用，但是这样没法利用 io 库的 buffer 等特性，如果有相关操作可能造成不可预见的问题。他们之间通过下面的函数可以进行转换：
#include [...]]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=267</wfw:commentRss>
		</item>
		<item>
		<title>xdebug 使用 tips</title>
		<link>http://www.hickwu.com/?p=266</link>
		<comments>http://www.hickwu.com/?p=266#comments</comments>
		<pubDate>Wed, 04 Mar 2009 15:55:12 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>PHP</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=266</guid>
		<description><![CDATA[平时常用 xdebug 追踪 php 的错误信息(stack trace)，还有一个所谓的 profiling ，就是统计并保存函数(包括 php 函数和自定义函数)的执行时间，内存消耗以及参数等情况都可以记录，但是开销更大，一般不要记录 。
设置如下
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
zend_extension = /usr/local/php/extensions/xdebug.so
xdebug.default_enable = Off
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_dir = &#8220;/data/xdebug/&#8221;
xdebug.profiler_output_name=trace.%R.txt
xdebug.profiler_enable = Off
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
这个设置关掉了 stack trace ，profiling 功能，只在 http 请求中有 XDEBUG_PROFILE (GET/POST/COOKIE) 的时候，才统计函数执行情况并保存成文件。如果不 disable 上面的功能，运营服务器很容易挂掉。以上设置以后， http 进程大概需要多消耗 1-2M 内存，CPU 消耗也不大。平时没有必要加载 xdebug，时不时去观察下，随机给几个用户的 COOKIE 里加个 XDEBUG_PROFILE 是很好的习惯。
关于生成的 log 文件，windows 下以前一般用 wincachegrind 来看，但是 xdebug2 某个版本以后，修改了生成文件的时间单位，直接用 wincachegrind 看时间会少一个数量级。建议用  http://code.google.com/p/webgrind/ 来看。  [...]]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=266</wfw:commentRss>
		</item>
		<item>
		<title>Internet Explorer 无法打开 Internet 站点</title>
		<link>http://www.hickwu.com/?p=265</link>
		<comments>http://www.hickwu.com/?p=265#comments</comments>
		<pubDate>Fri, 20 Feb 2009 05:03:55 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>Web 开发</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=265</guid>
		<description><![CDATA[前不久遇到的问题，收到反馈说我负责的 portal 可能出现“Internet Explorer 无法打开 Internet 站点 http://.com. 操作已中止”的提示。查了下是因为 js 操作浏览器还没有渲染完的 html 标签，就对该标签进行 appendChild  或者修改 innerHTML 的操作。 其实之前在访问 Google 的时候也有出现过类似情况，不过很少，一直以为是浏览器问题呢。
出现此问题的原因子容器 HTML 元素包含试图修改子容器的父容器元素的脚本。 脚本试图使用 innerHTML 方法或 appendChild 方法修改父容器元素。
是例如如果 DIV 元素是在 BODY 元素中的子容器，并在 DIV 元素中的一个 SCRIPT 块尝试修改 DIV 元素的父容器的 BODY 元素，可能会出现此问题。 
解决方法
要变通解决此问题，请只修改的块关闭容器，或者，修改仅脚本的立即的容器元素编写脚本。 为此，使用一个占位符，可以关闭目标容器，或可以将脚本块移动到您要修改的容器。 
本例中， DIV 元素是一个子容器元素。 SCRIPT 块在 DIV 元素内的尝试修改 BODY 元素。 BODY 元素是关闭的父容器的 DIV 元素。

 [...]]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=265</wfw:commentRss>
		</item>
		<item>
		<title>shell/命令行下的光标移动等操作快捷键</title>
		<link>http://www.hickwu.com/?p=264</link>
		<comments>http://www.hickwu.com/?p=264#comments</comments>
		<pubDate>Sat, 27 Dec 2008 06:54:15 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>Linux/Unix工具</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=264</guid>
		<description><![CDATA[shell 命令行下不少键盘操作跟 Emacs 是类似的，可能不能说是从 Emacs 借鉴过来的，这些快捷的使用，谁早谁晚还不好考证，不过思路是一致的。之前某次突然来劲试了 C-a C-e 等，刚搜索并实践了若干操作，在 SecureCRT 登录 suse 的环境验证了，整理如下(不一定是所有 shell 都支持)：
(注意下面的&#8221;前&#8221;都是指&#8221;左&#8221;或&#8221;上&#8221;，&#8221;后&#8221;是&#8221;右&#8221;或&#8221;下&#8221;)
C-r 查找历史执行命令，很便捷的调用历史命令的方式，输入历史命令关键字，就会及时显示匹配命令，enter 即可执行
C-p 前一条指令
C-n 后一条指令
C-c 终止已经运行的命令(针对还没有运行完的命令和脚本，实际为向相关进程发送中断信号)或者取消已经输入的命令
C-o/C-j/C-m 执行当前行输入的命令，跟 enter 类似
C-l 清屏，clear 命令
C-a 移动光标到行首
C-e 移动光标到行尾
C-t 交换光标前俩字符的位置
C-h 往后删除一字符
C-d 往前删除一字符
C-b 往后移动一个字符
C-f 往前移动一个字符
下面几个操作原理估计类似 emacs 的 yank 操作，可以理解为一套独立的粘贴板机制:
C-w 剪切前一个单词(空格间隔的字符串单元)
C-u 剪切到行首
C-k 剪切到行尾
C-y 粘贴剪切
]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=264</wfw:commentRss>
		</item>
		<item>
		<title>文件操作3(Beginning Linux Programming 笔记6)</title>
		<link>http://www.hickwu.com/?p=263</link>
		<comments>http://www.hickwu.com/?p=263#comments</comments>
		<pubDate>Tue, 16 Dec 2008 15:20:44 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>Linux 编程</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=263</guid>
		<description><![CDATA[原文地址: http://www.hickwu.com/?p=263  作者: Hick  转载请注明出处
p139 其他管理文件的系统调用
lseek 打开文件以后读取时，有一个文件指针的概念，文件指针决定 read 函数读取字符的开始位置，lseek 函数用来移动文件指针。
#include &#60;unistd.h&#62;#include &#60;sys/types.h&#62;off_t lseek(int fildes, off_t offset, int whence);
offset 为移动的的具体数量，whence 决定移动的方式，SEEK_SET 表示为绝对位置；SEEK_CUR 表示相对当前指针的位置；SEEK_END 表示相对文件末尾 ，移动失败返回 -1 。
有一系列的函数用来返回文件的信息： fstat, stat, lstat 返回描述文件信息的一个结构(structure)，不同的是 fstat 以 fd 为参数，而 stat 和 lstat 以文件路径为参数。lstat 相比 stat 的不同是，当文件是一个 link 时，该函数返回的是 link 的信息而不是 link 指向文件的信息:
#include &#60;unistd.h&#62;#include &#60;sys/stat.h&#62;#include &#60;sys/types.h&#62;int fstat(int fildes, struct [...]]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=263</wfw:commentRss>
		</item>
		<item>
		<title>文件操作2(Beginning Linux Programming 笔记5)</title>
		<link>http://www.hickwu.com/?p=262</link>
		<comments>http://www.hickwu.com/?p=262#comments</comments>
		<pubDate>Sat, 13 Dec 2008 00:57:29 +0000</pubDate>
		<dc:creator>Hick</dc:creator>
		
		<category>Linux 编程</category>

		<guid isPermaLink="false">http://www.hickwu.com/?p=262</guid>
		<description><![CDATA[原文地址: http://www.hickwu.com/?p=262  作者: Hick  转载请注明出处
p131 linux 中对打开的文件都用一个整型值来表示，也就是文件描述符： file descriptor, 也可以简称为 fd 。之前的 shell 编程中接触过三个最常用且固定值的 fd ： 0 为标准输入文件； 1 为标准输出文件; 2 为标准错误文件 。
使用系统调用 write 需要包含 unistd.h ，(理解为 unix standard)，函数原型： size_t write(int fildes, const void *buf, size_t nbytes) ，表示把 buf 的前 nbytes 个字节(换句话说，有自动截取的功能)写入 fildes 所表示的文件中，函数返回实际写入文件的字符串长度。返回 0 则表示没有写入任何字符，-1 表示发生错误，这时候可以从全局变量 errno 中获得错误编码。 下面是一个使用例子:
#include &#60;unistd.h&#62;#include &#60;stdlib.h&#62;int main(){&#160;&#160; [...]]]></description>
		<wfw:commentRss>http://www.hickwu.com/?feed=rss2&amp;p=262</wfw:commentRss>
		</item>
	</channel>
</rss>
