﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-On The Road</title><link>http://www.cppblog.com/darkdestiny/</link><description>(cond ((less 'code) (less 'bug)))</description><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 11:18:09 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 11:18:09 GMT</pubDate><ttl>60</ttl><item><title>感谢cppblog陪我多年，我走了</title><link>http://www.cppblog.com/darkdestiny/archive/2013/08/06/202375.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Tue, 06 Aug 2013 15:02:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2013/08/06/202375.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/202375.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2013/08/06/202375.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/202375.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/202375.html</trackback:ping><description><![CDATA[cppblog是一个好平台，技术氛围浓烈，引擎、编译器、服务器后台的各种牛人此起彼伏。<br />在这里的时候，我是<strong>On The Road</strong>，一直在学习。<br />如今自立门户，只是一粒abc。但我还是要走的，走的时候，得在这里留个外链。<br />从今以后，请你<strong><a href="http://hwh008.github.io/" title="叫我ABC">叫我ABC</a></strong>。<img src ="http://www.cppblog.com/darkdestiny/aggbug/202375.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2013-08-06 23:02 <a href="http://www.cppblog.com/darkdestiny/archive/2013/08/06/202375.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>TCP协议流的理解</title><link>http://www.cppblog.com/darkdestiny/archive/2013/03/21/tcpmtu.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Thu, 21 Mar 2013 03:02:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2013/03/21/tcpmtu.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/198661.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2013/03/21/tcpmtu.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/198661.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/198661.html</trackback:ping><description><![CDATA[<p>TCP是流协议，不像UDP那样sendto发一次消息，另一端必然会收到完整消息，或者没有收到任何消息。<br />
当用TCP send发一次消息的时候，可能另一端在某时刻可能只收到一部分消息，下一时刻才能收到另一部分。那如果一个消息很小，是否可以保证另一端在某时刻能收到这条完整消息？</p>
<ol>
     <li>调用send后，TCP将数据拷贝到缓冲区。缓冲区内可能不止一条用户消息。</li>
     <li>
     <p>TCP按照一定算法，将缓冲区的数据打包到1-n个TCP报文中，交给IP层发送。TCP报文是TCP协议的最小发送单位，大小应该是可变的，并且丢失的话会重发。</p>
     <ul style="margin: 0px; padding: 0px; list-style: none;">
         <li>#并不能保证一个TCP报文中必然包含一条用户消息的全部，所以即使消息很小，另一端也有可能在某时刻只收到部分</li>
     </ul>
     </li>
     <li>
     <p>IP层将TCP报文装进IP包，然后再交给链路层发送以太帧</p>
     <ul style="margin: 0px; padding: 0px; list-style: none;">
         <li>#理论上IP包的大小应该会选择比MTU小。一旦IP包比MTU大，意味着网络上的路由要帮你缓存多个以太帧，拼出IP包后才知道如何路由到下一个节点。向下一节点路由的时候还要再拆分成多个以太帧发送</li>
         <li>#所以TCP报文应该会比选择比MTU小<br />
         <br />
         </li>
     </ul>
     </li>
</ol>
全文收集到<a href="http://note.sdo.com/u/huangwenhai/">我的知识共享</a>
<img src ="http://www.cppblog.com/darkdestiny/aggbug/198661.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2013-03-21 11:02 <a href="http://www.cppblog.com/darkdestiny/archive/2013/03/21/tcpmtu.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>人生常有迷惑时</title><link>http://www.cppblog.com/darkdestiny/archive/2012/06/06/177831.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Wed, 06 Jun 2012 13:34:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2012/06/06/177831.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/177831.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2012/06/06/177831.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/177831.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/177831.html</trackback:ping><description><![CDATA[<style type="text/css">
p {font-size:18px;}
</style>
<h3>最近大姨夫又来了。</h3>
<p>工作再次失去目标。失去目标加闲来无事，人变得很焦躁。<br>
一方面原因是公司缺少程序员的更高阶段的培养方向和条件，另一方面则是个人眼界和心态所限，在没活时就不知道去做些什么才能对项目有所贡献，进而影响到了平时的学习目标。<br>
这就是一般人常说的工作没有挑战性。当然，其实多数工作都隐藏着挑战性领域，要靠自己去深入挖掘。
</p>

<p>在事业上目标也迷惑了。<br>
流行的成功学都说成功的第一步是树立一个非常明确的长期目标，其实这个命题具有欺骗性。就我自己体会而言，不是每个人都有能力找到所谓的长期目标，要非常明确就更难了。实际上我入这行成为一个还凑合的开发人员曾经是我大学订的事业目标，那时以为是长期目标。结果几年下来，发现已经实现了。<br>
然后又不停的去找新的目标，此事不顺，许多看似长期目标，要么慢慢都实现了，要么就甩开了。当然甩开的事情更多一些，毕竟常常是浮躁和功利心主导自己的心智。
</p>

<p>沉静下来，想了一些整理思路的方式：<br>
首先是从现实角度考虑，如果现在温饱还解决不了，那么首要任务则应该是找份能吃上饭的工作，事业什么的先甩一边去吧。饱暖才能思淫欲，是不？<br>
接着是尝试排除功利心，应该不少人的第一理性目标总是从拥有很多钱开始，至少我难免其俗。不过多数人这辈子只能手头略紧的活着，所以大可先做出想象，现在有1000W，2000W，或者过亿，或者有个某部局的干爹干娘，总之拥有到你满足为止，然后你打算做什么。如果只是想疯玩疯买，这套思考方式不太适合；如果还是打算拥有更多的钱，这套思考方式也解决不了。<br>
接着是尝试排除休闲心，排除一些梦想。比如想去趟南极，已经可以从阿根廷组团去了，或者上次珠峰，或者去些人间仙境，天上人间什么的。你假设你都已经做完所有这些事情了，就像假设你已经拥有很多钱一样，你开过飞机，上过宇宙，见过ET，打过怪兽。<br>
好了，然后还追求什么呢，是习惯无所事事呢，还是闲不住？
</p>

<p>终于，闲不住的人，考虑到自己一辈子都想做的一些事情了。<br>
但是，要继续从事现在的行业或者工作吗，或者换一个行业试试。无论是否喜欢现在的行业，都可以假设自己被迫去做了其他行业，并且被努力做好。做技术的，可以想想去做销售是什么样子，或者想想只是开个小卖部或者卖衣服，做律师吵架，要用什么形式才能做好那份工作。<br>
其实很多事情，只要做好了就有充实感和满足感。我觉得自己是乐于做很多行业的。<br>
最后无论是选择留在当前行业或者换一个行业，要做的就是努力去做些能让自己不断有满足感，不断的被需要，不断的可以改进的事情。
</p>

<p>我呢，暂时会在编程和互联网应用这块去挖掘一些满足用户需求的事情。同时，也会去学一些当前没用途但是感兴趣的知识，多数时候学习实在太有功利性了。<br>
公司的活，打算将想在下个项目要改进的内容挪到这个项目来。
</p><img src ="http://www.cppblog.com/darkdestiny/aggbug/177831.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2012-06-06 21:34 <a href="http://www.cppblog.com/darkdestiny/archive/2012/06/06/177831.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android ndk调试知识</title><link>http://www.cppblog.com/darkdestiny/archive/2012/03/12/ndk_gdb_arm.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Mon, 12 Mar 2012 09:33:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2012/03/12/ndk_gdb_arm.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/167726.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2012/03/12/ndk_gdb_arm.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/167726.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/167726.html</trackback:ping><description><![CDATA[<p>
ndk-gdb<br>
最近用NDK开发一些东西，结果调试相关的内容学习了不少。因为自己也手生，所以就不保证接下来介绍的内容完全正确。
</p>

<h3>编译可调试代码</h3>
<p>
NDK_DEBUG=1；apk的androidmanifest.xml也要配置为debugable=true。<br>
遇上麻烦的时候NDK_LOG=1,--verbose，V=1可以输出更详细的信息排查问题。
</p>

<h3>调试符号debug symbol</h3>
<p>
./obj/local/armeabi。如果动态库不放到这里，就会提示no debug symbol。<br>
如果想知道当前哪些动态库包含了调试信息，使用shared指令。<br>
<ins>gdb)shared</ins>
</p>

<h3>汇编调试</h3>
<p>
<ol>
	<li>disass，dump函数的全部汇编</li>
	<li>ni，单步调试汇编</li>
	<li>si，进入汇编子函数</li>
<li>display/5i $pc，这是我调试前喜欢的设置，这样每调试一步，就会自动打印下5条指令，很舒适。</li>
</ol>
</p>

<h3>arm汇编</h3>
<p>
arm的汇编和x86的汇编有些不一样，比较常见的是这几条：
<ol>
	<li>bl，类似call，函数调用。r0-rn是传入参数，调用后r0是返回值。</li>
	<li>ldr，将内存载入寄存器。</li>
	<li>str，将寄存器写入内存。</li>
<li>ldr rn,[pc,#offset]<br>
add rn,pc,rn<br>
这种指令组合比较特别，其实是将这个函数外的变量地址加载进来，也就是访问全局变量。
</li>
<li>
局部变量，包括当前函数参数，使用sp+#offset表示其内存位置。
</li>
</ol>

其他的就跟x86的差不多了。
</p><img src ="http://www.cppblog.com/darkdestiny/aggbug/167726.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2012-03-12 17:33 <a href="http://www.cppblog.com/darkdestiny/archive/2012/03/12/ndk_gdb_arm.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>how to fix "cannot locate cxa_begin_catch" in Android NDK</title><link>http://www.cppblog.com/darkdestiny/archive/2012/03/02/ndk_libstdc.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Fri, 02 Mar 2012 07:50:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2012/03/02/ndk_libstdc.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/166983.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2012/03/02/ndk_libstdc.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/166983.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/166983.html</trackback:ping><description><![CDATA[<h2>reproduce problem:</h2>
<p>
NDK version: r7<br>
link to libstdc++.so or -lstdc++<br>
</p>

<h2>output: (need high version SDK)</h2>
<p>
reloc_library cannot locate cxa_begin_catch
</p>

<h2>reason:</h2>
<p>
they renamed libstdc++.a to libgnustl_static.a starting from NDK r7, also inserting a new dummy libstdc++.so that contain these symbols when in the device emulator does not have. 
</p>

<h2>how to fix:</h2>
<p>
LOCAL_LDFLAGS += $(MY_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi/libgnustl_static.a
</p>

<h2>
WTF</h2><img src ="http://www.cppblog.com/darkdestiny/aggbug/166983.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2012-03-02 15:50 <a href="http://www.cppblog.com/darkdestiny/archive/2012/03/02/ndk_libstdc.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>paxos算法的理解</title><link>http://www.cppblog.com/darkdestiny/archive/2012/02/24/paxos.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Fri, 24 Feb 2012 12:36:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2012/02/24/paxos.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/166448.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2012/02/24/paxos.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/166448.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/166448.html</trackback:ping><description><![CDATA[<p>
一个分布式修改数据的一致性算法。
</p>
<h2>主要角色</h2>
<p>
决策者：是否批准修改申请。对一个资源一次只能批准一个修改申请，不能做墙头草。<br>
申请者：提出修改申请。<br>
学习者：记录被批准的修改。
</p>

<h2>主要过程</h2>
<p>
多个申请者向多个决策者提出修改申请，获得多数派批准的申请将交给学习者进行学习。
</p>
<p>
这个民主的过程将经过两轮表决，在第2轮表决中获得多数派批准的申请可以被整体接受，保障数据在各个节点上的一致性。
<ol>
<li>申请者要决策者做第一轮表决，尝试获得多数派决策者的支持，同时获得已经进入第二轮表决的修改申请内容。</li>
<li>申请者根据收集到的其他申请者的申请内容的数量，在他们的修改申请和自己的修改申请中选一个最可能通过的申请内容，发起第二轮表决。</li>
</ol>
</p> 

<h2>决策者服务</h2>
<p>
决策者的工作实际和申请者，学习者之间没有太多关系，决策者对一个修改申请无非要求以下内容：
<ul>
<li>申请者ID</li>
<li>申请编号</li>
<li>资源ID</li>
<li>修改内容</li>
</ul>
因此决策者这个角色可以做成一个相对独立的服务，为各种类型的申请者提供一致性支持。
</p>
<p>
另外由于多个学习者的学习可能出现不一致，所以学习编号可以由决策者这边通过唯一数据库递增管理。
</p>

<br>
<p>
看过上文但又不是很懂的就不要多看几次了。google一下能找到很多人的心得，但是中文的心得普遍不容易理解。所以推荐阅读英文原版论文
<a href="http://research.microsoft.com/en-us/um/people/lamport/pubs/paxos-simple.pdf">paxos simple</a>
</p><img src ="http://www.cppblog.com/darkdestiny/aggbug/166448.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2012-02-24 20:36 <a href="http://www.cppblog.com/darkdestiny/archive/2012/02/24/paxos.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vim插件：快速生成函数定义</title><link>http://www.cppblog.com/darkdestiny/archive/2011/12/05/vim_plugin.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Mon, 05 Dec 2011 13:03:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2011/12/05/vim_plugin.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/161528.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2011/12/05/vim_plugin.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/161528.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/161528.html</trackback:ping><description><![CDATA[今天一直想找一个vim插件，功能是在头文件声明了一个函数后，可以通过简易的操作在对应的cpp文件中生成这个函数的无实现定义。<br>
没能找到自己想用的那种，其中一个csupport，通过交互输入类名和函数名在当前缓冲插入函数定义，弱爆了；另一个snipemate，是将预先定义的模板复制到当前缓冲区，类似与预定义的代码补完，东西不算坏，但不是我想要的那种。<br>
理论上应该有完成这种任务的vim插件，可惜插件库实在太庞大了，随便google几下大海捞针，决定自己动手，丰衣足食。<br>
<br>
<h2>基本思路如下：</h2>
<div style="font-size:24px">
<li style="font-size:16px">取当前行作为函数声明行，然后通过正则表达式去掉virtual等修饰符。</li>
<li style="font-size:16px">往前搜索第一个class关键字，能读到的话，通过正则表达式提取出类名，然后和函数声明结合起来，形成一个函数定义。</li>
<li style="font-size:16px">取出当前文件的缓冲名，通过正则表达式去掉文件名上的目录和.h后缀，然后拼成对应的cpp文件。</li>
<li style="font-size:16px">在缓冲区里搜索生成的cpp文件，搜索到后将函数声明追加到该文件中。</li>
</div>

<a href="http://www.cppblog.com/Files/darkdestiny/c.vim.tar">c.vim插件下载</a>

<img src ="http://www.cppblog.com/darkdestiny/aggbug/161528.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2011-12-05 21:03 <a href="http://www.cppblog.com/darkdestiny/archive/2011/12/05/vim_plugin.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>网络组件支持telnet检测</title><link>http://www.cppblog.com/darkdestiny/archive/2011/06/12/telnet_netlib.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Sun, 12 Jun 2011 14:44:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2011/06/12/telnet_netlib.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/148557.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2011/06/12/telnet_netlib.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/148557.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/148557.html</trackback:ping><description><![CDATA[<h2>这是什么？</h2>
我的意思是，一个网络组件在接受新连接后，先以文本协议等候消息，以实现支持telnet查看的功能。<br>
<br>

<h2>telnet查看功能</h2>
<ol>
<li><strong>echo value。</strong>
网络组件收到消息后，像echo服务器那样直接返回value。value还可以是组件预置的变量，如$time返回服务器的当前时间。
</li>
<li><strong>name value。</strong>
网络组件收到消息后，将当前连接绑定到value这个名字上，其目的是为下一条heartbeat指令提供操作对象。
</li>
<li><strong>heartbeat value。</strong>
网络组件收到消息后，向value绑定的连接发起一个心跳检测，将回执通知telnet端。
</li>
</ol>
<br>

<h2>这有什么用？</h2>
以往telnet在开发中的作用就是ping具体的服务器地址和端口，无法进一步使用。有时候想实时的从服务器中了解一些简单的连接信息，但是网络组件只处理专有的二进制消息，只能实现一个不通用的客户端。<br>
若网络组件在接收二进制消息之前能够处理一些简单的文本协议，那么telnet就可进一步使用，查看组件状态甚至简单调试组件。<br>
还有一种就是服务器程序监控服务，通常这种监控服务只能判断服务器程序是否运行或者挂掉，但是无法判断服务器是否遇上死锁而无法提供服务。当网络组件支持这种文本协议之后，监控服务就能够通过echo和heartbeat两种消息检测网络组件listen方和connect方是否卡死。<br>
<br>


<h2>内置一个http服务器不是更好？</h2>
其实在网络组件中内置一个http服务器不是更好，可以通过wget,curl甚至浏览器进行操作，可视化程度也比较高。<br>
我不这么认为。其实内置一个http服务器有点大了，搞不好比组件本身还大。再者http服务是和业务连接共用一个端口呢还是拥有独立的服务端口，独立的服务端口增加了太多的配置，共用端口的话从HTTP协议变迁到二进制协议是不是太麻烦了点。<br><img src ="http://www.cppblog.com/darkdestiny/aggbug/148557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2011-06-12 22:44 <a href="http://www.cppblog.com/darkdestiny/archive/2011/06/12/telnet_netlib.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>bash的不同启动方式导致不同的设置</title><link>http://www.cppblog.com/darkdestiny/archive/2010/12/20/bash_shell_types.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Mon, 20 Dec 2010 15:07:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2010/12/20/bash_shell_types.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/137074.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2010/12/20/bash_shell_types.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/137074.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/137074.html</trackback:ping><description><![CDATA[这两天遇上了一个问题,可惜解决晚了,导致场景服务器的一个未知隐患要留到下次外部测试才能查出来了.<br>
一个通过ssh连接启停指定服务器程序的管理程序,其中一组启动的程序发生崩溃后无法dumpcore文件,但是改用手动启动的方式程序则会在崩溃后dumpcore.<br>
在shell环境下检测core文件大小设置:<br>
<div style="position:relative;left:40px;border:solid thin blue;width:100px">
$ulimit -c<br>
unlimited
</div><br>
让管理程序读取core文件大小设置:<br>
<div style="position:relative;left:40px;border:solid thin blue;width:300px">
o = machine.StartApp('ulimit -c');<br>
print(o.readline());
</div><br>
<div style="position:relative;left:40px;border:solid thin blue;width:100px">
$python test.py<br>
0
</div>
设置值是0,不是预期的.但是在终端看到的却是unlimited.其中ulimit -c的初始设置是写在.bash_profile里的.<br>
<hr>
很幸运的看到.bashrc里提到2种类型的shells:login shell,interactive shell.其中login shell加载.bash_profile,interactive shell加载.bashrc.<br>
管理程序连接到机器后,没有使用tty或者bash,因为不需要交互,同时,管理程序执行命令的方式是bash -c,所以管理程序没有执行.bash_profile中的设置,以致于子进程继承的core文件大小设置不符合期望.<br>
其中的一个解决办法是在每个执行命令前添加 ulimit -c unlimited,但是这写得有点死.另一个解决办法是发现bash -c每次都会加载.bashrc,将core文件大小设置写入.bashrc便可.<br>

问题看起来解决了,但是我觉得这里面的一个细节和man对不上:<br>
<div style="border:solid thin blue">
      An  interactive  shell  is  one started without non-option arguments and without the -c option whose standard input and error are both connected to
       terminals 
</div>
管理程序执行命令时候的bash -c表示的是non-interactive shell,应该不会加载.bashrc才是,类似于用crontab运行的脚本就不会加载.bashrc,但是管理程序执行命令的时候设置竟然生效了...求解.<br>.

<br>
<hr>
PS:最近2个月没写blog,好忙.................

<img src ="http://www.cppblog.com/darkdestiny/aggbug/137074.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2010-12-20 23:07 <a href="http://www.cppblog.com/darkdestiny/archive/2010/12/20/bash_shell_types.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一期一会[September]</title><link>http://www.cppblog.com/darkdestiny/archive/2010/09/24/month_flow.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Fri, 24 Sep 2010 12:58:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2010/09/24/month_flow.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/127533.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2010/09/24/month_flow.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/127533.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/127533.html</trackback:ping><description><![CDATA[<p>
入手milestone,主要是用来记事和todolist,全键盘打字手感很好.不过用了以后就觉得买贵了,其实只要是有物理键盘的android就可以了,但却选择了最贵的一款.
</p>

<p>
最近工作重心发生了一些变化,公司方面的就是开始接网络数据库组的任务,淡出逻辑编写.网数组的任务,需求简洁清晰,不像逻辑那样有太多纠缠不清的内容,容易达到一次编写极少修改境界.不舒服的地方则是有可能1个月都不会上一次客户端,只能对着控制台发呆.个人方面也由独立的学习分支转入公司的工作进程中,更多的考虑工作中的计划和安排,同时也兼顾着基础和erlang.<br>
每每被老大问及职业规划都无言以对,制定长期目标和长期计划本身就是一种才能,而拥有这种才能的人寥寥可数.看不到远处,就看当下,总能看到一些短期目标,好好安排,走一步算一步.这一次的重心变化,就是将目光从飘渺的远处移回了脚下,结果这个月是意外的忙碌.
</p>

<p>
中秋三天假玩得太野,1天去北奥森林公园,走了很多路;1天出去买东西+打牌,结果4点才睡.现在则处于一种不赶紧上床休息就会死的状态,所以,这个月的碎碎念就到这里,国庆回家补补.<br><br>
最后,MonthFlow系列改名为一期一会.
</p><img src ="http://www.cppblog.com/darkdestiny/aggbug/127533.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2010-09-24 20:58 <a href="http://www.cppblog.com/darkdestiny/archive/2010/09/24/month_flow.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>十步精通新语言</title><link>http://www.cppblog.com/darkdestiny/archive/2010/08/22/learn-new-language.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Sun, 22 Aug 2010 02:20:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2010/08/22/learn-new-language.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/124262.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2010/08/22/learn-new-language.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/124262.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/124262.html</trackback:ping><description><![CDATA[<div>
<p>
标题党一下.....<br>
昨天做了一个特殊抓取的爬虫,不到50行python代码,痛痛快快的给我抓取了2000个flashgame和玩法说明.除了感叹会写程序实在太好了之外,还想到了如何快速学习一门新语言的事情.<br>
严格来说,应该是学习命令式语言,和其他类型的语言可能一点交集都没有.<br>
一门语言的本质只是简单的语法和基本IO,只要稍微认知了这些内容就能开始写程序了,要精通则是一个不断进行实际应用和调试的过程.
</p>
<ol>
<li>hello world</li>
<ul>
<li>认识主函数或者入口函数,看看语言的基本风格.</li>
</ul>
<li>变量</li>
<ul>
<li>变量定义,变量类型,变量赋值.</li>
<li>数值,字符串,bool类型是最基础类型.</li>
<li>区别全局变量,局部变量.</li>
<li>结构体的使用.</li>
</ul>
<li>标准输入输出</li>
<ul>
<li>从终端给变量赋值,在终端打印变量的值.这是学习新语言时最需要的调用.</li>
</ul>
<li>函数</li>
<ul>
<li>函数定义语法,参数的格式,返回值的格式.</li>
</ul>
<li>分支,循环</li>
<ul>
<li>判断表达式的语法.</li>
</ul>
<li>字符串操作</li>
<ul>
<li>format操作,字符串连接符.</li>
<li>搜索和提取子串.</li>
<li>字符集编码规定和接口.</li>
<li>再高级一点,正则表达式.</li>
</ul>
<li>容器</li>
<ul>
<li>list和dict,类似的东西,他们的使用方式.</li>
</ul>
<li>文件读写</li>
<ul>
<li>打开,关闭文件.文件数据的读取和写入.</li>
<li>读取一行数据.</li>
</ul>
<li>runtime</li>
<ul>
<li>语言自身的特殊概念.这里通常才是这门语言区别其他语言的精髓所在.</li>
<li>交互式控制台.</li>
<li>编译程序,或者由解释器执行程序.</li>
<li>运行环境,程序启动方式.</li>
</ul>
<li>模块</li>
<ul>
<li>导入模块,使用模块.</li>
<li>多文件,分模块,编写自己的模块.</li>
</ul>
</ol>
<p>
语言说到底只是工具,拥有语言之外的良好的基础能力和领域能力才是最难的地方啊.
</p>
</div>
<div style="display:none">
<style type="text/css">
ol > li {
font-weight: bold;
}
</style>
</div>
<img src ="http://www.cppblog.com/darkdestiny/aggbug/124262.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2010-08-22 10:20 <a href="http://www.cppblog.com/darkdestiny/archive/2010/08/22/learn-new-language.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>检测lua内存泄漏</title><link>http://www.cppblog.com/darkdestiny/archive/2010/08/14/lua-memory-leak.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Sat, 14 Aug 2010 07:41:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2010/08/14/lua-memory-leak.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/123436.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2010/08/14/lua-memory-leak.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/123436.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/123436.html</trackback:ping><description><![CDATA[<div style="text-indent:40px">
<h4>引子</h4>
<p>
最近用机器人做NPC的压力测试,突然发现一台机器能支持的机器人数量剧减,而且运行一段时间后整台机器直接内存耗光死机.经过观察,发现1个机器人在运行一段时间之后内存能占用到120M之多,而且还在不断增加,同时内存无法手动回收.<br>
以前1个机器人大概消耗10M-20M的内存,这次的消耗明显异常了,所以初步判断逻辑上存在lua对象泄漏:在某些没有注意到的地方长期引用着不再使用的lua对象,导致这些对象无法被gc.<br>
为了解决这个问题,google到一篇相似问题的文章,<a href="http://shavingha.blog.163.com/blog/static/10378336200822134554488/">lua内存泄漏查证</a>.文章的大概思路就是:
<ol>
	<li>资源跟踪,定位哪些资源泄漏</li>
	<li>引用检索,查找泄漏的资源被哪个模块引用</li>
</ol>
</p>

<h4>资源跟踪</h4>
<p>
定义:将应用中分配的lua对象添加到一个弱表中.执行完整的gc后,还能从弱表中索引到的对象表示它还在别的地方被引用着,可能是正常的引用,也可能是一处内存泄漏.<br>
我使用了一个弱键表,该表以要跟踪的lua对象为键,该对象的描述信息为值.其中的描述信息包含了对象描述和对象创建时间两项.对象描述用于区别不同的跟踪对象;创建时间则用来在打印弱表的时候判断对象的存活时间是否合理.<br>
我定义的接口是:function TraceMem(obj, description);
</p>
<p>
虽然机器人可以动态的加载无尽的模块,但是几乎所有的资源都是由几个基础模块开始分配的,所以添加对象跟踪相对比较简单.经过修改,运行,测试,从弱表中打印出来的数据发现,机器人中有大量的移动包和移动相关的计时器对象没有被gc掉,这些对象多数都已经存活了100秒以上.场景中NPC都是僵尸,每个移动的时间应该在5秒以下,所以可判定这些移动对象是泄漏.<br>
问题的范围缩小了,但还是看不出哪段代码造成了泄漏?泄漏的对象在哪一个模块中被引用?
</p>

<h4>引用检索</h4>
<p>
定义:从某个节点开始搜索所有该节点引用的对象以及递归搜索子节点,找到要搜索的对象,打印出引用路径.<br>
最常见的可以从_G开始搜索.搜索到的每个table,取其key和value递归搜索;搜索到的每个函数,取其upvalue递归搜索.至于是否需要搜索对象的环境表和metatable,以及全局registry表,则取决于具体需求.我因为用不上,就没有搜索这一部分.<br>
搜索的时候注意标记已经搜索过的节点,避免重复搜索.最好能缩小搜索范围,而不是从_G开始搜索,另外应该能每次只搜索指定的部分引用而非全部,可以极大的缩短等待时间.搜索所有的引用其实相当耗时.<br>
我定义的搜索接口是:function Search_r(obj, node, mark, result);
</p>
<p>
经过引用检索处理后,我看到了计时器模块引用了那些泄漏的移动包和移动计时器对象,这些对象的创建时间和引用他们的激活时间居然是相同的,这导致了这些计时器对象不会再激活,同时也失去了激活后释放的机会,造成了内存泄漏.而根本原因,则是移动处理模块在使用计时器的时候传入了0超时参数,因为僵尸走得太慢了.<br>
到此,问题就算全部解决了.
</p>
</div>

<div style="border:4px solid blue" id="my_ps_panel">
<p>
PS:发现用html编辑blog非常不错啊,比cppblog自带的所见即所得编辑器好用多了,还可以用CSS和插入一些有趣的js.
</p>
</div>
<button id="mybutton">click me</button>

<style type="text/css">
h4 { text-align:center; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script>
$(function()
{
$("#mybutton").click(function(){
$("#my_ps_panel").toggle('slow');			
})
}
)
</script>
<img src ="http://www.cppblog.com/darkdestiny/aggbug/123436.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2010-08-14 15:41 <a href="http://www.cppblog.com/darkdestiny/archive/2010/08/14/lua-memory-leak.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux下如何提取mp3</title><link>http://www.cppblog.com/darkdestiny/archive/2010/07/19/extra_mp3_in_linux.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Mon, 19 Jul 2010 00:02:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2010/07/19/extra_mp3_in_linux.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/120748.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2010/07/19/extra_mp3_in_linux.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/120748.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/120748.html</trackback:ping><description><![CDATA[<p>
事情的起因大概是,女流在某个游戏视频里哼哼了几句,想到用来做信息铃声可能会挺赞的,于是就动手了.
</p>
<p>
首先是将视频down下来,用的是firefox上的某个插件,格式是flv.下载后首先要做的就是格式转换到mp3,网上搜索了3种方法,只有最后一种成功了....
</p>
<ol>
<li>用mplayer的转换,可耻的失败鸟</li>
<li>用ffmpeg转换,可耻的失败鸟</li>
<li>用mencoder转换,总算成功了</li>
</ol>
<p>
接下来,开始提取音乐的片段.因为女流就哼哼了大概7,8秒吧,要从整个文件里提取这7,8秒,其他什么凤姐啊著姐啊专家啊的最讨厌了.提取的软件用的是audacity,所见所得,随便尝试了几下就提取出来了.过程大概是:
</p>
<ol>
<li>在音轨上选中要导出的区域,反复试听,满意为止.可以通过数值输入微调</li>
<li>在菜单上选中export selection,导出</li>
</ol>
<p>
导出后立即装入手机享受一下,结果声音太大,感觉糟糕.要降低音量才行,搜索出可以用mp3gain降低音量,默认是89db,降音后感觉很棒,声音刚刚好,柔柔的.
</p><img src ="http://www.cppblog.com/darkdestiny/aggbug/120748.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2010-07-19 08:02 <a href="http://www.cppblog.com/darkdestiny/archive/2010/07/19/extra_mp3_in_linux.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>month-flow [6]</title><link>http://www.cppblog.com/darkdestiny/archive/2010/06/27/118836.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Sun, 27 Jun 2010 13:56:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2010/06/27/118836.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/118836.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2010/06/27/118836.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/118836.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/118836.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 6月碎碎念&nbsp;&nbsp;<a href='http://www.cppblog.com/darkdestiny/archive/2010/06/27/118836.html'>阅读全文</a><img src ="http://www.cppblog.com/darkdestiny/aggbug/118836.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2010-06-27 21:56 <a href="http://www.cppblog.com/darkdestiny/archive/2010/06/27/118836.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>python code snippet</title><link>http://www.cppblog.com/darkdestiny/archive/2010/05/24/116247.html</link><dc:creator>LOGOS</dc:creator><author>LOGOS</author><pubDate>Mon, 24 May 2010 12:05:00 GMT</pubDate><guid>http://www.cppblog.com/darkdestiny/archive/2010/05/24/116247.html</guid><wfw:comment>http://www.cppblog.com/darkdestiny/comments/116247.html</wfw:comment><comments>http://www.cppblog.com/darkdestiny/archive/2010/05/24/116247.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/darkdestiny/comments/commentRss/116247.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/darkdestiny/services/trackbacks/116247.html</trackback:ping><description><![CDATA[class LuaTable:<br>
-- def __init__(self, **argss):<br>
---- self.__dict__ = dict(argss)<br>
<hr>
<pre>
player = LuaTable(name = 'p1', hp = 10)
print player.name
print player.hp

dog = LuaTable(name='dog', type='dog')
print dog.name
dog.food = 'bone'

I hate python dict, so make something like lua table.
</pre><img src ="http://www.cppblog.com/darkdestiny/aggbug/116247.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/darkdestiny/" target="_blank">LOGOS</a> 2010-05-24 20:05 <a href="http://www.cppblog.com/darkdestiny/archive/2010/05/24/116247.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>