<?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>16hot 的博客 &#187; 开发</title>
	<atom:link href="http://www.16hot.com/category/dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.16hot.com</link>
	<description>技术、工作、生活，坚持一种信念，一切皆有可能……</description>
	<lastBuildDate>Sat, 07 Jan 2012 11:09:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>lua日期与时间操作</title>
		<link>http://www.16hot.com/2011/12/1302/</link>
		<comments>http://www.16hot.com/2011/12/1302/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 12:14:16 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[LUA]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1302</guid>
		<description><![CDATA[os.time()]]></description>
			<content:encoded><![CDATA[<p>os.time()                <== 返回当前系统的日历时间<br />
os.date()                <== 返回本地化的时间字符串，这里是&#8221;11/28/08 17:23:37&#8243;<br />
os.date(&#8220;%x&#8221;, os.time()) <== 返回自定义格式化时间字符串（完整的格式化参数），这里是&#8221;11/28/08&#8243;<br />
os.clock()               <== 返回执行该程序CPU花去的时钟秒数，这里是1156.726<br />
附录<br />
完整的格式化参数<br />
这些时间输出的字符串表示是经过本地化的。所以如果是在巴西（葡萄牙语系），&#8221;%B&#8221; 得到的就是 &#8220;setembro&#8221;（译者按：大概是葡萄牙语九月？），&#8221;%x&#8221; 得到的就是 &#8220;16/09/98&#8243;（月日次序不同）。标记的意义和显示实例总结如下表。实例的时间是在1998年九月16日，星期三，23:48:10。返回值为数字形式的还列出了它们的范围。（都是按照英语系的显示描述的，也比较简单，就不烦了）<br />
%a abbreviated weekday name (e.g., Wed)<br />
%A full weekday name (e.g., Wednesday)<br />
%b abbreviated month name (e.g., Sep)<br />
%B full month name (e.g., September)<br />
%c date and time (e.g., 09/16/98 23:48:10)<br />
%d day of the month (16) [01-31]<br />
%H hour, using a 24-hour clock (23) [00-23]<br />
%I hour, using a 12-hour clock (11) [01-12]<br />
%M minute (48) [00-59]<br />
%m month (09) [01-12]<br />
%p either &#8220;am&#8221; or &#8220;pm&#8221; (pm)<br />
%S second (10) [00-61]<br />
%w weekday (3) [0-6 = Sunday-Saturday]<br />
%x date (e.g., 09/16/98)<br />
%X time (e.g., 23:48:10)<br />
%Y full year (1998)<br />
%y two-digit year (98) [00-99]<br />
%% the character &#8216;%&#8217;<br />
事实上如果不使用任何参数就调用date，就是以%c的形式输出。这样就是得到经过格式化的完整时间信息。<br />
注意%x、%X和%c由所在地区和计算机系统的改变会发生变化。<br />
如果该字符串要确定下来（例如确定为mm/dd/yyyy），可以使用明确的字符串格式方式（例如&#8221;%m/%d/%Y&#8221;）。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2011/12/1302/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LUA中的字符串函数库</title>
		<link>http://www.16hot.com/2011/12/1300/</link>
		<comments>http://www.16hot.com/2011/12/1300/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 07:03:33 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[LUA]]></category>
		<category><![CDATA[转载]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1300</guid>
		<description><![CDATA[Lua解释器对字符串的支持很有限。一个程序可以创建字符串并连接字符串，但不能截取子串，检查字符串的大小，检测字符串的内容。在Lua中操纵字符串的功能基本来自于string库。 字符串库中的一些函数是非常简单的： string.len(s) 返回字符串s的长度； string.rep(s, n) 返回重复n次字符串s的串；你使用string.rep(&#8220;a&#8221;, 2^20)可以创建一个1M bytes的字符串（比如，为了测试需要）； string.lower(s) 将s中的大写字母转换成小写（string.upper将小写转换成大写）。如果你想不关心大小写对一个数组进行排序的话，你可以这样： table.sort(a, function (a, b) return string.lower(a) < string.lower(b) end) string.upper(s) 将s中的小写字母转换成大写 string.upper和string.lower都依赖于本地环境变量。所以，如果你在 European Latin-1环境下，表达式： string.upper("a??o") --> &#8220;A??O&#8221; string.sub(s,i,j) 函数截取字符串s的从第i个字符到第j个字符之间的串。Lua中，字符串的第一个字符索引从1开始。你也可以使用负索引，负索引从字符串的结尾向前计数：-1指向最后一个字符，-2指向倒数第二个，以此类推。所以， string.sub(s, 1, j)返回字符串s的长度为j的前缀；string.sub(s, j, -1)返回从第j个字符开始的后缀。如果不提供第3个参数，默认为-1，因此我们将最后一个调用写为string.sub(s, j)；string.sub(s, 2, -2)返回去除第一个和最后一个字符后的子串。 s = &#8220;[in brackets]&#8221; print(string.sub(s, 2, -2)) &#8211;> in brackets 记住：Lua中的字符串是恒定不变的。string.sub函数以及Lua中其他的字符串操作函数都不会改变字符串的值，而是返回一个新的字符串。一个常见的错误是： string.sub(s, 2, -2) 认为上面的这个函数会改变字符串s的值。如果你想修改一个字符串变量的值，你必须将变量赋给一个新的字符串： s = [...]]]></description>
			<content:encoded><![CDATA[<p>Lua解释器对字符串的支持很有限。一个程序可以创建字符串并连接字符串，但不能截取子串，检查字符串的大小，检测字符串的内容。在Lua中操纵字符串的功能基本来自于string库。</p>
<p>字符串库中的一些函数是非常简单的：</p>
<p>string.len(s)          返回字符串s的长度；<br />
string.rep(s, n)      返回重复n次字符串s的串；你使用string.rep(&#8220;a&#8221;, 2^20)可以创建一个1M bytes的字符串（比如，为了测试需要）；<br />
string.lower(s)       将s中的大写字母转换成小写（string.upper将小写转换成大写）。如果你想不关心大小写对一个数组进行排序的话，你可以这样：<br />
                             table.sort(a, function (a, b) return string.lower(a) < string.lower(b) end)<br />
string.upper(s)       将s中的小写字母转换成大写<br />
                            string.upper和string.lower都依赖于本地环境变量。所以，如果你在 European Latin-1环境下，表达式：<br />
                            string.upper("a??o")    --> &#8220;A??O&#8221;<br />
string.sub(s,i,j)      函数截取字符串s的从第i个字符到第j个字符之间的串。Lua中，字符串的第一个字符索引从1开始。你也可以使用负索引，负索引从字符串的结尾向前计数：-1指向最后一个字符，-2指向倒数第二个，以此类推。所以， string.sub(s, 1, j)返回字符串s的长度为j的前缀；string.sub(s, j, -1)返回从第j个字符开始的后缀。如果不提供第3个参数，默认为-1，因此我们将最后一个调用写为string.sub(s, j)；string.sub(s, 2, -2)返回去除第一个和最后一个字符后的子串。<br />
s = &#8220;[in brackets]&#8221;<br />
print(string.sub(s, 2, -2)) &#8211;> in brackets<br />
记住：Lua中的字符串是恒定不变的。string.sub函数以及Lua中其他的字符串操作函数都不会改变字符串的值，而是返回一个新的字符串。一个常见的错误是：<br />
string.sub(s, 2, -2)<br />
认为上面的这个函数会改变字符串s的值。如果你想修改一个字符串变量的值，你必须将变量赋给一个新的字符串：<br />
s = string.sub(s, 2, -2)<br />
string.char函数和string.byte函数用来将字符在字符和数字之间转换。string.char获取0个或多个整数，将每一个数字转换成字符，然后返回一个所有这些字符连接起来的字符串。string.byte(s, i)将字符串s的第i个字符的转换成整数；第二个参数是可选的，缺省情况下i=1。下面的例子中，我们假定字符用ASCII表示：</p>
<p>print(string.char(97)) &#8211;> a<br />
i = 99; print(string.char(i, i+1, i+2)) &#8211;> cde<br />
print(string.byte(&#8220;abc&#8221;)) &#8211;> 97<br />
print(string.byte(&#8220;abc&#8221;, 2)) &#8211;> 98<br />
print(string.byte(&#8220;abc&#8221;, -1)) &#8211;> 99 </p>
<p>上面最后一行，我们使用负数索引访问字符串的最后一个字符。<br />
Lua提供了string.format()函数来生成具有特定格式的字符串, 函数的第一个参数是格式(formatstring), 之后是对应格式中每个代号的各种数据. 由于格式字符串的存在, 使得产生的长字符串可读性大大提高了. 这个函数的格式很像C语言中的printf().函数string.format在用来对字符串进行格式化的时候，特别是字符串输出，是功能强大的工具。这个函数有两个参数，你完全可以照C语言的printf来使用这个函数。第一个参数为格式化串：由指示符和控制格式的字符组成。指示符后的控制格式的字符可以为：十进制&#8217;d'；十六进制&#8217;x'；八进制&#8217;o'；浮点数&#8217;f'；字符串&#8217;s'。在指示符&#8217;%'和控制格式字符之间还可以有其他的选项：用来控制更详细的格式，比如一个浮点数的小数的位数：<br />
格式字符串可能包含以下的转义码:<br />
%c &#8211; 接受一个数字, 并将其转化为ASCII码表中对应的字符<br />
%d, %i &#8211; 接受一个数字并将其转化为有符号的整数格式<br />
%o &#8211; 接受一个数字并将其转化为八进制数格式<br />
%u &#8211; 接受一个数字并将其转化为无符号整数格式<br />
%x &#8211; 接受一个数字并将其转化为十六进制数格式, 使用小写字母<br />
%X &#8211; 接受一个数字并将其转化为十六进制数格式, 使用大写字母<br />
%e &#8211; 接受一个数字并将其转化为科学记数法格式, 使用小写字母e<br />
%E &#8211; 接受一个数字并将其转化为科学记数法格式, 使用大写字母E<br />
%f &#8211; 接受一个数字并将其转化为浮点数格式<br />
%g(%G) &#8211; 接受一个数字并将其转化为%e(%E, 对应%G)及%f中较短的一种格式<br />
%q &#8211; 接受一个字符串并将其转化为可安全被Lua编译器读入的格式<br />
%s &#8211; 接受一个字符串并按照给定的参数格式化该字符串<br />
为进一步细化格式, 可以在%号后添加参数. 参数将以如下的顺序读入:<br />
(1) 符号: 一个+号表示其后的数字转义符将让正数显示正号. 默认情况下只有负数显示符号.<br />
(2) 占位符: 一个0, 在后面指定了字串宽度时占位用. 不填时的默认占位符是空格.<br />
(3) 对齐标识: 在指定了字串宽度时, 默认为右对齐, 增加-号可以改为左对齐.<br />
(4) 宽度数值<br />
(5) 小数位数/字串裁切: 在宽度数值后增加的小数部分n, 若后接f(浮点数转义符, 如%6.3f)则设定该浮点数的小数只保留n位, 若后接s(字符串转义符, 如%5.3s)则设定该字符串只显示前n位.<br />
在这些参数的后面则是上述所列的转义码类型(c, d, i, f, &#8230;).</p>
<p>print(string.format(&#8220;pi = %.4f&#8221;, PI))<br />
      &#8211;> pi = 3.1416<br />
d = 5; m = 11; y = 1990<br />
print(string.format(&#8220;%02d/%02d/%04d&#8221;, d, m, y))<br />
        &#8211;> 05/11/1990<br />
tag, title = &#8220;h1&#8243;, &#8220;a title&#8221;<br />
print(string.format(&#8220;<%s>%s</%s>&#8220;, tag, title, tag))<br />
        &#8211;><br />
<h1>a title</h1>
<p>第一个例子，%.4f代表小数点后面有4位小数的浮点数。第二个例子%02d代表以固定的两位显示十进制数，不足的前面补0。而%2d前面没有指定0，不足两位时会以空白补足。对于格式串部分指示符得详细描述清参考lua手册，或者参考C手册，因为Lua调用标准C的printf函数来实现最终的功能。</p>
<p>以下是一些例子:</p>
<p>string.format(&#8220;%%c: %c&#8221;, 83)            输出S<br />
string.format(&#8220;%+d&#8221;, 17.0)              输出+17<br />
string.format(&#8220;%05d&#8221;, 17)               输出00017<br />
string.format(&#8220;%o&#8221;, 17)                 输出21<br />
string.format(&#8220;%u&#8221;, 3.14)               输出3<br />
string.format(&#8220;%x&#8221;, 13)                 输出d<br />
string.format(&#8220;%X&#8221;, 13)                 输出D<br />
string.format(&#8220;%e&#8221;, 1000)               输出1.000000e+03<br />
string.format(&#8220;%E&#8221;, 1000)               输出1.000000E+03<br />
string.format(&#8220;%6.3f&#8221;, 13)              输出13.000<br />
string.format(&#8220;%q&#8221;, &#8220;One\nTwo&#8221;)         输出&#8221;One\<br />
                                        　　Two&#8221;<br />
string.format(&#8220;%s&#8221;, &#8220;monkey&#8221;)           输出monkey<br />
string.format(&#8220;%10s&#8221;, &#8220;monkey&#8221;)         输出    monkey<br />
string.format(&#8220;%5.3s&#8221;, &#8220;monkey&#8221;)        输出  mon</p>
]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2011/12/1300/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解决FreeBSD下编译LuaJIT的问题</title>
		<link>http://www.16hot.com/2011/10/1287/</link>
		<comments>http://www.16hot.com/2011/10/1287/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 15:30:47 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[BSD/linux]]></category>
		<category><![CDATA[LUA]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[luajit]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1287</guid>
		<description><![CDATA[在FreeBSD下编译LuaJIT时，报如下错误： CC lj_err.o lj_err.c:189:20: error: unwind.h: No such file or directory lj_err.c:199: error: expected declaration specifiers or '...' before '_Unwind_Action' lj_err.c:200: error: expected declaration specifiers or '...' before '_Unwind_Exception_Class' lj_err.c:201: warning: 'struct _Unwind_Context' declared inside parameter list lj_err.c:201: warning: its scope is only this definition or declaration, which is probably not what you want lj_err.c:201: [...]]]></description>
			<content:encoded><![CDATA[<p>在FreeBSD下编译LuaJIT时，报如下错误：<br />
<code><br />
CC        lj_err.o<br />
lj_err.c:189:20: error: unwind.h: No such file or directory<br />
lj_err.c:199: error: expected declaration specifiers or '...' before '_Unwind_Action'<br />
lj_err.c:200: error: expected declaration specifiers or '...' before '_Unwind_Exception_Class'<br />
lj_err.c:201: warning: 'struct _Unwind_Context' declared inside parameter list<br />
lj_err.c:201: warning: its scope is only this definition or declaration, which is probably not what you want<br />
lj_err.c:201: warning: 'struct _Unwind_Exception' declared inside parameter list<br />
lj_err.c: In function 'lj_err_unwind_dwarf':<br />
lj_err.c:206: error: '_URC_FATAL_PHASE1_ERROR' undeclared (first use in this function)<br />
lj_err.c:206: error: (Each undeclared identifier is reported only once<br />
lj_err.c:206: error: for each function it appears in.)<br />
lj_err.c:207: error: 'uexclass' undeclared (first use in this function)<br />
lj_err.c:208: warning: implicit declaration of function '_Unwind_GetCFA'<br />
lj_err.c:208: warning: cast to pointer from integer of different size<br />
lj_err.c:210: error: 'actions' undeclared (first use in this function)<br />
lj_err.c:210: error: '_UA_SEARCH_PHASE' undeclared (first use in this function)<br />
lj_err.c:213: error: '_URC_CONTINUE_UNWIND' undeclared (first use in this function)<br />
lj_err.c:218: error: '_URC_HANDLER_FOUND' undeclared (first use in this function)<br />
lj_err.c:220: error: '_UA_CLEANUP_PHASE' undeclared (first use in this function)<br />
lj_err.c:225: error: '_UA_HANDLER_FRAME' undeclared (first use in this function)<br />
lj_err.c:226: warning: implicit declaration of function '_Unwind_DeleteException'<br />
lj_err.c:231: error: '_UA_FORCE_UNWIND' undeclared (first use in this function)<br />
lj_err.c:234: warning: implicit declaration of function '_Unwind_SetGR'<br />
lj_err.c:235: warning: implicit declaration of function '_Unwind_SetIP'<br />
lj_err.c:235: error: '_Unwind_Ptr' undeclared (first use in this function)<br />
lj_err.c:238: error: '_URC_INSTALL_CONTEXT' undeclared (first use in this function)<br />
lj_err.c:246: error: expected ')' before 'lj_vm_unwind_rethrow'<br />
lj_err.c: In function 'err_raise_ext':<br />
lj_err.c:271: error: invalid use of undefined type 'struct _Unwind_Exception'<br />
lj_err.c:271: error: '_Unwind_Exception_Class' undeclared (first use in this function)<br />
lj_err.c:272: error: invalid use of undefined type 'struct _Unwind_Exception'<br />
lj_err.c:273: warning: implicit declaration of function '_Unwind_RaiseException'<br />
gmake: *** [lj_err.o] 错误 1<br />
</code></p>
<p>只需要拷贝一个头文件，并且改名即可：</p>
<p>/usr/src/contrib/gcc/unwind-generic.h /usr/include/unwind.h</p>
]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2011/10/1287/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用LUA做程序配置文件</title>
		<link>http://www.16hot.com/2011/10/1277/</link>
		<comments>http://www.16hot.com/2011/10/1277/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 07:57:19 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[LUA]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1277</guid>
		<description><![CDATA[本来想用bison、flex来写一个配置文件的。但是看了看资料，不容易懂，而且也不灵活。还是放弃了。 后来想起了lua，现在流行用lua来做服务程序的配置文件。强大、灵活，而且与C可以紧密结合。 下面是C程序： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 [...]]]></description>
			<content:encoded><![CDATA[<p>本来想用bison、flex来写一个配置文件的。但是看了看资料，不容易懂，而且也不灵活。还是放弃了。<br />
后来想起了lua，现在流行用lua来做服务程序的配置文件。强大、灵活，而且与C可以紧密结合。</p>
<p>下面是C程序：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">/*
 * getcfg.c
 * cc -o getcfg getcfg.c -I/usr/local/include/lua51 -L/usr/local/lib/lua51 -llua -lm
 */</span>
&nbsp;
<span style="color: #339933;">#include &lt;lua.h&gt;</span>
<span style="color: #339933;">#include &lt;lauxlib.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">int</span>
main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> status<span style="color: #339933;">,</span> result<span style="color: #339933;">,</span> ind<span style="color: #339933;">;</span>
	<span style="color: #993333;">const</span> <span style="color: #993333;">char</span>       <span style="color: #339933;">*</span>key<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>value<span style="color: #339933;">;</span>
    <span style="color: #993333;">double</span> sum<span style="color: #339933;">;</span>
    lua_State <span style="color: #339933;">*</span>L<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/*
     * All Lua contexts are held in this structure. We work with it almost
     * all the time.
     */</span>
    L <span style="color: #339933;">=</span> luaL_newstate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    luaL_openlibs<span style="color: #009900;">&#40;</span>L<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* Load Lua libraries */</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Load the file containing the script we are going to run */</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> luaL_loadfile<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;server.cfg&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> lua_pcall<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #808080; font-style: italic;">/* If something went wrong, error message is at the top of */</span>
        <span style="color: #808080; font-style: italic;">/* the stack */</span>
        fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Couldn't load file: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		lua_pop<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
	lua_getglobal<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;socket&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>socket <span style="color: #339933;">=</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;socket %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	lua_pop<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	lua_getglobal<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;servers&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>lua_istable<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		lua_pop<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// remove the error-msg </span>
		<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
	ind <span style="color: #339933;">=</span> lua_gettop<span style="color: #009900;">&#40;</span>L<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;index: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> ind <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	lua_pushnil<span style="color: #009900;">&#40;</span>L<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>lua_next<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #808080; font-style: italic;">/** 获取服务索引名 */</span>
			key <span style="color: #339933;">=</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;key name: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> key <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>lua_istable<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			ind <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
			lua_pushnil<span style="color: #009900;">&#40;</span>L<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
			<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>lua_next<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #808080; font-style: italic;">/** 获取服务配置 */</span>
				key <span style="color: #339933;">=</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;bin&quot;</span><span style="color: #339933;">,</span> key<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;bin %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;pid&quot;</span><span style="color: #339933;">,</span> key<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;pid %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;params&quot;</span><span style="color: #339933;">,</span> key<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;params %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>strcmp<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;config&quot;</span><span style="color: #339933;">,</span> key<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;config %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> lua_tostring<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Unkonw key: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> key <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				lua_pop<span style="color: #009900;">&#40;</span> L<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		lua_pop<span style="color: #009900;">&#40;</span>L<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    lua_close<span style="color: #009900;">&#40;</span>L<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #808080; font-style: italic;">/* Cya, Lua */</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>下面是LUA代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="lua" style="font-family:monospace;">&nbsp;
daemon <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">false</span>
&nbsp;
socket <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;/var/run/daemon-server.sock&quot;</span>
&nbsp;
servers <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;phpd&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> 
		pid <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;/var/run/phpd.pid&quot;</span>,
		bin <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;/usr/local/sbin/phpd&quot;</span>,
		delay <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">300</span>, 
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2011/10/1277/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FreeBSD下根据进程名称获取PID</title>
		<link>http://www.16hot.com/2011/10/1272/</link>
		<comments>http://www.16hot.com/2011/10/1272/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 07:44:40 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[BSD/linux]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[KVM]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1272</guid>
		<description><![CDATA[想通过进程名称来监控进程是否健在，在网上找了一个小例子，改成如下： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 [...]]]></description>
			<content:encoded><![CDATA[<p>想通过进程名称来监控进程是否健在，在网上找了一个小例子，改成如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * 
 * gcc getproc.c -I/usr/include -I/usr/local/include -L/usr/lib/ -L/usr/local/lib/ -lkvm -o getproc
 */</span>
&nbsp;
<span style="color: #339933;">#include &lt;stdio.h&gt;   </span>
<span style="color: #339933;">#include &lt;string.h&gt;   </span>
<span style="color: #339933;">#include &lt;err.h&gt;   </span>
<span style="color: #339933;">#include &lt;kvm.h&gt;   </span>
<span style="color: #339933;">#include &lt;sys/param.h&gt;   </span>
<span style="color: #339933;">#include &lt;sys/sysctl.h&gt;   </span>
<span style="color: #339933;">#include &lt;sys/user.h&gt;   </span>
<span style="color: #339933;">#include &lt;sys/param.h&gt;   </span>
<span style="color: #339933;">#include &lt;fcntl.h&gt;   </span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;   </span>
<span style="color: #339933;">#include &lt;sysexits.h&gt;    </span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>  
get_pid_of_process<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>process_name<span style="color: #009900;">&#41;</span>   
<span style="color: #009900;">&#123;</span>   
 <span style="color: #993333;">static</span> kvm_t <span style="color: #339933;">*</span>kd <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>   
 <span style="color: #993333;">struct</span> kinfo_proc <span style="color: #339933;">*</span>p<span style="color: #339933;">;</span>   
 <span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> n_processes<span style="color: #339933;">,</span> processes_found<span style="color: #339933;">;</span>   
 processes_found <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>   
&nbsp;
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>kd <span style="color: #339933;">=</span> kvm_open<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/null&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;/dev/null&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;/dev/null&quot;</span><span style="color: #339933;">,</span> O_RDONLY<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;kvm_open&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>    
    <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>errx<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s&quot;</span><span style="color: #339933;">,</span> kvm_geterr<span style="color: #009900;">&#40;</span>kd<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
 <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>   
  p <span style="color: #339933;">=</span> kvm_getprocs<span style="color: #009900;">&#40;</span>kd<span style="color: #339933;">,</span> KERN_PROC_PROC<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>n_processes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> n_processes<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>   
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strncmp<span style="color: #009900;">&#40;</span>process_name<span style="color: #339933;">,</span> p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">ki_comm</span><span style="color: #339933;">,</span> COMMLEN<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>   
    <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span><span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;progame: %s, pid: %d <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> process_name<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">ki_pid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
    processes_found<span style="color: #339933;">++;</span>   
   <span style="color: #009900;">&#125;</span>   
<span style="color: #666666; font-style: italic;">//~ if (p[i].ki_pid == pid){</span>
  <span style="color: #666666; font-style: italic;">//~ (void)printf(&quot;%s &quot;, p[i].ki_comm);</span>
  <span style="color: #666666; font-style: italic;">//~ processes_found++;</span>
 <span style="color: #666666; font-style: italic;">//~ }</span>
  kvm_close<span style="color: #009900;">&#40;</span>kd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">return</span> processes_found<span style="color: #339933;">;</span>   
<span style="color: #009900;">&#125;</span>   
&nbsp;
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> pf <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> argc <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">2</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;Please input a process name!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    pf <span style="color: #339933;">=</span> get_pid_of_process<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;have found %d proess<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> pf <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2011/10/1272/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx + luafcgid 运行lua</title>
		<link>http://www.16hot.com/2011/09/1258/</link>
		<comments>http://www.16hot.com/2011/09/1258/#comments</comments>
		<pubDate>Sat, 24 Sep 2011 10:13:03 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[BSD/linux]]></category>
		<category><![CDATA[LUA]]></category>
		<category><![CDATA[fastcgi]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1258</guid>
		<description><![CDATA[可以配置nginx和luafcgid来运行lua脚本WEB程序。 网站： https://github.com/STPeters/luafcgid 安装和配置都很简单，在该网站下载源码包回来，直接gmake 就可以编译了。前提是已经安装好fcgi-2.4.0。 nginx部分的配置也及其简单，基本照抄文档里的配置即可。 location ~ \.lua$ { # for BSD/Linux fastcgi_pass unix:/var/tmp/luafcgid.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }]]></description>
			<content:encoded><![CDATA[<p>可以配置nginx和luafcgid来运行lua脚本WEB程序。</p>
<p>网站： <a href="https://github.com/STPeters/luafcgid">https://github.com/STPeters/luafcgid</a></p>
<pre>安装和配置都很简单，在该网站下载源码包回来，直接gmake 就可以编译了。前提是已经安装好fcgi-2.4.0。</pre>
<pre>nginx部分的配置也及其简单，基本照抄文档里的配置即可。</pre>
<pre>
   location ~ \.lua$ {

	  # for BSD/Linux
      fastcgi_pass   unix:/var/tmp/luafcgid.sock;

	  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
   }</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2011/09/1258/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>joolma 的tab扩展语法</title>
		<link>http://www.16hot.com/2011/03/1195/</link>
		<comments>http://www.16hot.com/2011/03/1195/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 15:02:01 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1195</guid>
		<description><![CDATA[{jkefel kefelui=[tabs] title=[Remotely fetched page] url=[http://jproven.com/images/stories/jproven/examples/jkefel-ajax-example.html]} Content of first tab, this paragraph, is going to be followed by content fetched from given URL. {/jkefel} {jkefel title=[Title 2]} Content of second tab... {jkefel title=[Title 2.1] kefelui=[tabs]} content of tab 2.1 {/jkefel} {jkefel title=[Title 2.2]} content of tab 2.2 {/jkefelend} {/jkefel} {jkefel title=[Module container] mod=[211]} Content of [...]]]></description>
			<content:encoded><![CDATA[<pre>{jkefel kefelui=[tabs] title=[Remotely fetched page] url=[http://jproven.com/images/stories/jproven/examples/jkefel-ajax-example.html]}
Content of first tab, this paragraph, is going to be followed by content fetched from given URL.
{/jkefel}    

{jkefel title=[Title 2]}
  Content of second tab...
  {jkefel title=[Title 2.1] kefelui=[tabs]}
  content of tab 2.1
  {/jkefel}
  {jkefel title=[Title 2.2]}
  content of tab 2.2
  {/jkefelend}
{/jkefel}

{jkefel title=[Module container] mod=[211]}
Content of third tab and is followed by a loaded module with...
{/jkefelend}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2011/03/1195/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解决redmine不能浏览svn仓库的问题</title>
		<link>http://www.16hot.com/2010/11/1175/</link>
		<comments>http://www.16hot.com/2010/11/1175/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 07:07:41 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[BSD/linux]]></category>
		<category><![CDATA[开发]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1175</guid>
		<description><![CDATA[之前配置过，不能浏览也没有太在意。今天搜索了下，原来是svn路径的问题。 # vi ./lib/redmine/scm/adapters/subversion_adapter.rb # SVN_BIN = &#8220;svn&#8221; SVN_BIN = &#8220;/usr/local/bin/svn&#8221; 给svn命令加上完整路径就可以了。]]></description>
			<content:encoded><![CDATA[<p>之前配置过，不能浏览也没有太在意。今天搜索了下，原来是svn路径的问题。</p>
<blockquote><p># vi ./lib/redmine/scm/adapters/subversion_adapter.rb</p>
<p># SVN_BIN = &#8220;svn&#8221;<br />
SVN_BIN = &#8220;/usr/local/bin/svn&#8221;</p></blockquote>
<p>给svn命令加上完整路径就可以了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2010/11/1175/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关注HipHop移植到FreeBSD</title>
		<link>http://www.16hot.com/2010/11/1166/</link>
		<comments>http://www.16hot.com/2010/11/1166/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 13:41:15 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[BSD/linux]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[HIpHop]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1166</guid>
		<description><![CDATA[从一个博客上看到，已经在着手移植了。 http://huichen.org/en/2010/07/hiphop-for-freebsd/]]></description>
			<content:encoded><![CDATA[<p>从一个博客上看到，已经在着手移植了。</p>
<p><a href="http://huichen.org/en/2010/07/hiphop-for-freebsd/" target="_blank">http://huichen.org/en/2010/07/hiphop-for-freebsd/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2010/11/1166/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解决了 pam_fedns.so 加载失败的问题</title>
		<link>http://www.16hot.com/2010/11/1163/</link>
		<comments>http://www.16hot.com/2010/11/1163/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 06:13:33 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[BSD/linux]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[pam]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.16hot.com/?p=1163</guid>
		<description><![CDATA[为连接ssh，自己开发了个 pam 模块，命名为 pam_fedns.so。在i386环境，连接ssh没问题，amd64的环境连接就提示加载pam_fedns.so失败。 在网上找了个测试例子，检测发现少md5的连接库。加上-lmd 就搞定了。 #include &#60;dlfcn.h&#62; #include &#60;stdio.h&#62; int main (int argc, char **argv) { void *dlh; dlh = dlopen(argv[1], RTLD_NOW); if (dlh) { printf(&#8220;dlopen %s worked\n&#8221;, argv[1]); } else { printf(&#8220;dlopen %s failed: %s\n&#8221;, argv[1], dlerror()); } return 0; } 原文链接： http://freebsd.monkey.org/freebsd-stable/200709/msg00136.html]]></description>
			<content:encoded><![CDATA[<p>为连接ssh，自己开发了个 pam 模块，命名为 pam_fedns.so。在i386环境，连接ssh没问题，amd64的环境连接就提示加载pam_fedns.so失败。</p>
<p>在网上找了个测试例子，检测发现少md5的连接库。加上-lmd 就搞定了。</p>
<blockquote><p>#include &lt;dlfcn.h&gt;<br />
#include &lt;stdio.h&gt;</p>
<p>int<br />
main (int argc, char **argv) {</p>
<p>void *dlh;</p>
<p>dlh = dlopen(argv[1], RTLD_NOW);<br />
if (dlh) {<br />
printf(&#8220;dlopen %s worked\n&#8221;, argv[1]);<br />
} else {<br />
printf(&#8220;dlopen %s failed: %s\n&#8221;, argv[1], dlerror());<br />
}<br />
return 0;<br />
}</p></blockquote>
<p>原文链接：</p>
<p>http://freebsd.monkey.org/freebsd-stable/200709/msg00136.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2010/11/1163/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

