??xml version="1.0" encoding="utf-8" standalone="yes"?>中文字幕热久久久久久久,香港aa三级久久三级老师2021国产三级精品三级在 ,亚洲国产成人久久一区久久http://www.shnenglu.com/colorful/category/19275.htmlzc qq:1337220912zh-cnMon, 14 Apr 2014 05:42:28 GMTMon, 14 Apr 2014 05:42:28 GMT60linux shell 盒?/title><link>http://www.shnenglu.com/colorful/archive/2013/11/04/204082.html</link><dc:creator>多彩人生</dc:creator><author>多彩人生</author><pubDate>Mon, 04 Nov 2013 03:06:00 GMT</pubDate><guid>http://www.shnenglu.com/colorful/archive/2013/11/04/204082.html</guid><wfw:comment>http://www.shnenglu.com/colorful/comments/204082.html</wfw:comment><comments>http://www.shnenglu.com/colorful/archive/2013/11/04/204082.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/colorful/comments/commentRss/204082.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/colorful/services/trackbacks/204082.html</trackback:ping><description><![CDATA[<div>-----------------------------------------------------------------------------<br />grep 一ơ排除多?br />grep -v 'aaaa\|bbbb'  // 排除aaaa和bbbb<br /><br />-----------------------------------------------------------------------------<br />查看文g?br />ls |wc -l<br /><br />-----------------------------------------------------------------------------<br />查看文g夹大?br />du -sh *<br />du -sh /home<br />du -sh <br /><br />------------------------------------------------------------------------------<br />查找最新的文g<br /><div><p> Q?Q将文g按从新到旧排列,取第一个?/p> <p> ls -t *.cpp | head -1</p> <p> Q?Q将文g按从旧到新排列,取最后一个?/p> <p> ls -rt *.cpp | tail -1</p></div><br />------------------------------------------------------------------------------<br /><div>linux下递归删除某个文gҎ(gu)文g</div><div>今天l学校部|校庆网站,做网站的同学传给我的|站文g多wQ有很多exe文gQ而且q些exe的文件名都是原来的目录名Q看h是他的机器中了病毒。虽然exe文g在linux下无法运行,但是q是要删除这些exe文g。在|上找了一下,《linux下递归删除某个文gҎ(gu)文g》给了我满意的方法,让我可以一ơ性删除某目录及其子目录下所有的exe文g?br /><br />find . -name '*.exe' -type f -print -exec rm -rf {} \;<br /><br />(1) "."    表示从当前目录开始递归查找<br />(2) “ -name '*.exe' "Ҏ(gu)名称来查找,要查找所有以.exel尾的文件夹或者文?br />(3) " -type f "查找的类型ؓ(f)文g<br />(4) "-print" 输出查找的文件目录名<br />(5) 最主要的是?exec了,-exec选项后边跟着一个所要执行的命oQ表C将find出来的文件或目录执行该命令。exec选项后面跟随着所要执行的命o或脚本,然后是一对儿{}Q一个空格和一个\Q最后是一个分?br /><br />-----------------------------------------------------------------------------</div></div><img src ="http://www.shnenglu.com/colorful/aggbug/204082.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/colorful/" target="_blank">多彩人生</a> 2013-11-04 11:06 <a href="http://www.shnenglu.com/colorful/archive/2013/11/04/204082.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>变量在shell脚本间的传?http://www.shnenglu.com/colorful/archive/2013/09/11/203169.html多彩人生多彩人生Wed, 11 Sep 2013 05:37:00 GMThttp://www.shnenglu.com/colorful/archive/2013/09/11/203169.htmlhttp://www.shnenglu.com/colorful/comments/203169.htmlhttp://www.shnenglu.com/colorful/archive/2013/09/11/203169.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/203169.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/203169.html前几文章中已经介绍q局部变量和环境变量的含义,接下来我们来拓展下,看看变量怎样实现在shell脚本
中的传递shell脚本其实是用当前shell的子shellL行的Q所以在shell脚本中定义的普通变量只适用于当?br />shell的子shell环境Q也是说在当前shell环境中不适用Q也不适用于这个shell脚本的子shell?br />在shell脚本中定义的环境变量可以传承l它的子shellQ但是也不能传递给当前shell(不能逆向传?
如果在一个脚本中需要执行另一个脚本,q且q用其中的变量,改如何申明变量呢Q我们来看一个例子:
/root/test1.sh内容如下Q?br />#!/bin/bash
aaa=yuanfaxiang
echo "test1:$aaa"

/root/test2.sh内容如下Q?br />#!/bin/bash
/root/test1.sh
echo "test2:$aaa"
执行test2.shl果如下Q?br />[root@centos ~]# sh test2.sh
test1:yuanfaxiang
test2:
从结果可以看出test1.sh没有把变量aaa的g递给test2.sh

我们把test2.shҎ(gu)Q?br />#!/bin/bash
source /root/test1.sh
echo "test2:$aaa"
执行test2.shl果如下Q?br />[root@centos ~]# sh test2.sh
test1:yuanfaxiang
test2:yuanfaxiang
l果昄test2.shl承了test1.sh中定义的变量aaa?br />原因分析Q在W一ơ执行test2.shӞtest1.sh被作Ztest2.sh的子shell来执行,其中定义的变量只
在test1.sh中v效,不能逆向传递到test2.sh中;而在W二ơ执行中Q采用source来执行test1.sh,意?br />是直接把test1.sh在当前的test2.sh中执行,没有作ؓ(f)子shellL行,test1.sh中定义的变量Q就影响
Ctest2.sh?br />
如果我们再徏一个test3.sh
#!/bin/bash
echo "test3:$aaa"

把test2.shҎ(gu)Q?br />#!/bin/bash
source /root/test1.sh
echo "test2:$aaa"
/root/test3.sh
执行test2.shQ?br />[root@shenji ~]# sh test2.sh
test1:yuanfaxiang
test2:yuanfaxiang
test3:
l果昄test3.sh没有l承test1.sh中申明的变量Q因为source /root/test1.sh只是让test1.sh
中的变量在test2.sh中生效,aaa毕竟q是个普通局部变量,q不能被test3.shq个子shell所l承Q?br />所以我们可以想到环境变量,把aaa变成test2.shq个脚本的环境变量,让test2.sh的子q程也能l承?br />
test1.shҎ(gu)Q?br />#!/bin/bash
export aaa=yuanfaxiang
echo "test1:$aaa"
执行test2.sh后有如下l果Q?br />[root@shenji ~]# sh test2.sh
test1:yuanfaxiang
test2:yuanfaxiang
test3:yuanfaxiang
在test1.sh中声明了环境变量也就是全局变量Q在test2.sh中用source执行test1.shQ将变量带到?br />test2.sh中,q之成为test2.sh执行q程中的环境变量Q可以被test2.sh的子q程l承QvC向
传递效果?/div>

多彩人生 2013-09-11 13:37 发表评论
]]>
linux 僵尸q程http://www.shnenglu.com/colorful/archive/2013/08/12/202486.html多彩人生多彩人生Mon, 12 Aug 2013 02:31:00 GMThttp://www.shnenglu.com/colorful/archive/2013/08/12/202486.htmlhttp://www.shnenglu.com/colorful/comments/202486.htmlhttp://www.shnenglu.com/colorful/archive/2013/08/12/202486.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202486.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202486.htmlhttp://blog.csdn.net/zhuying_linux/article/details/7336662
http://blog.csdn.net/fengwei321123/article/details/9301409

如何查看q杀d进E?

最q工作过E中Q发现好几台服务器出现僵死进E(如图Q?/p>

点击查看原图 

  用下面的命o扑և僉|q程

  ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]'

  命o注解Q?br />   -A 参数列出所有进E?br />   -o 自定义输出字D?我们讑֮昄字段?statQ状态), ppidQ进E父idQ? pid(q程id)QcmdQ命令)q四个参?/p>

  -C 用来指定所执行的命令名Uͼ你这里也是让ps仅仅昄php命o所产生的进E的信息
    ps -C java -o lstart,pid,cmd【不q貌似打印的不全~?/span>
       ps -A -o lstart,pid,args |grep java【这个可以的~?/span> 
  因ؓ(f)状态ؓ(f) z或者Z 的进Eؓ(f)僵尸q程Q所以我们用grep抓取stat状态ؓ(f)zZq程
  q行l果参考如?/span>

点击查看原图

  q里一共出C9个僵死进E,我们需要把它们都干掉,执行下面的命?/p>

  kill -9 8310

  q时你再执行查找僉|的进E,发现所有僵死进E都没了Q?/p>

  补充Q?/strong>

  最q又遇到了个问题Q一台服务器上生了100多少僉|q程Q而且每一僉|q程的父q程都不一P如果用上面的Ҏ(gu)Q一条一条的杀Q那q不得篏L啊?br />   那么应该想一条简单的命oQ直接查扑փ死进E,然后父q程杀死~

   ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}' | xargs kill -9


----------------------------------------------------------------------------------------------------------

不能随便杀父进E?
ps -aux 先找到僵死进EID,?031
lsof -p 5031看看僉|在什么地?一般地讲死锁在某个文g或关联在某个q程
去除死锁文g或杀ȝ兌q程?/pre>
-----------------------------------------------------------------------------------------------------------

 

用ps和grep命oL僵尸q程
ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'
命o注解Q?br /> -A 参数列出所有进E?br /> -o 自定义输出字D?我们讑֮昄字段?statQ状态), ppidQ进E父idQ? pid(q程id)QcmdQ命令)q四个参?br /> 因ؓ(f)状态ؓ(f) z或者Z的进Eؓ(f)僵尸q程Q所以我们用grep抓取stat状态ؓ(f)zZq程
q行l果参考如?br /> Z 12334 12339 /path/cmd
q时Q我们可以?kill -HUP 12339来杀掉这个僵进E?br /> q行后,可以再次q行ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'来确认是否已l将僵尸q程杀?br /> 如果kill 子进E的无效Q可以尝试kill 其父q程来解决问题,例如上面例子父进Epid?12334Q那么我们就q行
kill -HUP 12334
来解决问?

 




多彩人生 2013-08-12 10:31 发表评论
]]>
linux signal?/title><link>http://www.shnenglu.com/colorful/archive/2013/08/12/202484.html</link><dc:creator>多彩人生</dc:creator><author>多彩人生</author><pubDate>Mon, 12 Aug 2013 01:09:00 GMT</pubDate><guid>http://www.shnenglu.com/colorful/archive/2013/08/12/202484.html</guid><wfw:comment>http://www.shnenglu.com/colorful/comments/202484.html</wfw:comment><comments>http://www.shnenglu.com/colorful/archive/2013/08/12/202484.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/colorful/comments/commentRss/202484.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/colorful/services/trackbacks/202484.html</trackback:ping><description><![CDATA[<div>转自Q?a >http://www.dbafree.net/?p=870</a><br /><div>http://news.cnblogs.com/n/146220/</div></div><div><p>我们可以使用kill -l查看所有的信号量解释,但是没有看到SIGNAL 0的解释?/p> <pre>[root@testdb~]# kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS </pre> <p><img src="http://www.dbafree.net/wp-includes/images/smilies/icon_cool.gif" alt="8)" /></p> <pre> SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX</pre> <p>|上搜了下,在这文档中扑ֈ了signal 0的解释,很不?</p> <p><a >http://www.linuxjournal.com/content/monitoring-processes-kill-0</a></p> <p>“signal 0″ is kind of like a moral equivalent of “ping”.</p> <p>Using “kill -0 NNN” in a shell script is a good way to tell if PID “NNN” is alive or not:</p> <p>signal 0 is just used to check process is exists or not.</p> <p>在关其它的信号量说明,原文:<a >http://hi.baidu.com/syqust/blog/item/cd8f6c633b8a617c0d33fa35.html</a></p> <p>信号本质<br />信号是在软g层次上对中断机制的一U模拟,在原理上Q一个进E收C个信号与处理器收C个中断请求可以说是一L(fng)。信h异步的,一个进E不必通过M操作来等待信L(fng)到达Q事实上Q进E也不知道信号到底什么时候到达?/p> <p>信号是进E间通信机制中唯一的异步通信机制Q可以看作是异步通知Q通知接收信号的进E有哪些事情发生了。信h制经qPOSIX实时扩展后,功能更加强大Q除了基本通知功能外,q可以传递附加信息?/p> <p>使用kill -l׃昄出linux支持的信号列表?br />其中列表中,~号? ~ 31的信号ؓ(f)传统UNIX支持的信P是不可靠信号(非实时的)Q编号ؓ(f)32 ~ 63的信h后来扩充的,U做可靠信号(实时信号)。不可靠信号和可靠信L(fng)区别在于前者不支持排队Q可能会造成信号丢失Q而后者不会?/p> <p>下面我们对编号小于SIGRTMIN的信可行讨论(下面的编?依次对应信号 的数gؓ(f)1 – 31Q?/p> <p>1) SIGHUP<br />本信号在用户l端q接(正常或非正常)l束时发? 通常是在l端的控制进E结束时, 通知同一session内的各个作业, q时它们与控制终端不再关联?/p> <p>dLinuxӞpȝ会分配给d用户一个终?Session)。在q个l端q行的所有程序,包括前台q程l和后台q程l,一般都属于q个 Session。当用户退出LinuxdӞ前台q程l和后台有对l端输出的进E将会收到SIGHUP信号。这个信L(fng)默认操作为终止进E,因此前台q? E组和后台有l端输出的进E就会中止。不q可以捕莯个信P比如wget能捕获SIGHUP信号Qƈ忽略它,q样q退ZLinuxdQwget? 能l下载?/p> <p>此外Q对于与l端q关系的守护进E,q个信号用于通知它重新读取配|文件?/p> <p>2) SIGINT<br />E序l止(interrupt)信号, 在用户键入INTR字符(通常是Ctrl-C)时发出,用于通知前台q程l终止进E?/p> <p>3) SIGQUIT<br />和SIGINTcM, 但由QUIT字符(通常是Ctrl-\)来控? q程在因收到SIGQUIT退出时会生core文g, 在这个意义上cM于一个程序错误信受?/p> <p>4) SIGILL<br />执行了非法指? 通常是因为可执行文g本n出现错误, 或者试图执行数据段. 堆栈溢出时也有可能生这个信受?/p> <p>5) SIGTRAP<br />由断Ҏ(gu)令或其它trap指o产生. 由debugger使用?/p> <p>6) SIGABRT<br />调用abort函数生成的信受?/p> <p>7) SIGBUS<br />非法地址, 包括内存地址寚w(alignment)出错。比如访问一个四个字长的整数, 但其地址不是4的倍数。它与SIGSEGV的区别在于后者是׃对合法存储地址的非法访问触发的(如访问不属于自己存储I间或只d储空??/p> <p><img src="http://www.dbafree.net/wp-includes/images/smilies/icon_cool.gif" alt="8)" /> SIGFPE<br />在发生致命的术q算错误时发? 不仅包括点q算错误, q包括溢出及除数?{其它所有的术的错误?/p> <p>9) SIGKILL<br />用来立即l束E序的运? 本信号不能被d、处理和忽略。如果管理员发现某个q程l止不了Q可试发送这个信受?/p> <p>10) SIGUSR1<br />留给用户使用</p> <p>11) SIGSEGV<br />试图讉K未分配给自己的内? 或试囑־没有写权限的内存地址写数?</p> <p><strong> 信号 11Q即表示E序中可能存在特定条件下的非法内存访问?/strong></p> <p>12) SIGUSR2<br />留给用户使用</p> <p>13) SIGPIPE<br />道破裂。这个信号通常在进E间通信产生Q比如采用FIFO(道)通信的两个进E,ȝ道没打开或者意外终止就往道写,写进E会收到SIGPIPE信号。此外用Socket通信的两个进E,写进E在写Socket的时候,读进E已l终止?/p> <p>14) SIGALRM<br />旉定时信号, 计算的是实际的时间或旉旉. alarm函数使用该信?</p> <p>15) SIGTERM<br />E序l束(terminate)信号, 与SIGKILL不同的是该信号可以被d和处理。通常用来要求E序自己正常退出,shell命okill~省产生q个信号。如果进E终止不了,我们才会试SIGKILL?/p> <p>17) SIGCHLD<br /><strong>子进E结束时, 父进E会收到q个信号?/strong></p> <p>如果父进E没有处理这个信P也没有等?wait)子进E,子进E虽然终止,但是q会在内核进E表中占有表,q时的子q程UCؓ(f)僵尸q程。这U情 冉|们应该避?父进E或者忽略SIGCHILD信号Q或者捕捉它Q或者wait它派生的子进E,或者父q程先终止,q时子进E的l止自动由initq程 来接??/p> <p>18) SIGCONT<br />让一个停?stopped)的进El执? 本信号不能被d. 可以用一个handler来让E序在由stopped状态变为l执行时完成特定的工? 例如, 重新昄提示W?/p> <p>19) SIGSTOP<br />停止(stopped)q程的执? 注意它和terminate以及interrupt的区?该进E还未结? 只是暂停执行. 本信号不能被d, 处理或忽?</p> <p>20) SIGTSTP<br />停止q程的运? 但该信号可以被处理和忽略. 用户键入SUSP字符?通常是Ctrl-Z)发出q个信号</p> <p>21) SIGTTIN<br />当后C业要从用L(fng)端读数据? 该作业中的所有进E会收到SIGTTIN信号. ~省时这些进E会停止执行.</p> <p>22) SIGTTOU<br />cM于SIGTTIN, 但在写终?或修改终端模?时收?</p> <p>23) SIGURG<br />?#8221;紧?#8221;数据或out-of-band数据到达socket时?</p> <p>24) SIGXCPU<br />过CPU旉资源限制. q个限制可以由getrlimit/setrlimit来读?改变?/p> <p>25) SIGXFSZ<br />当进E企图扩大文件以至于过文g大小资源限制?/p> <p>26) SIGVTALRM<br />虚拟旉信号. cM于SIGALRM, 但是计算的是该进E占用的CPU旉.</p> <p>27) SIGPROF<br />cM于SIGALRM/SIGVTALRM, 但包括该q程用的CPU旉以及pȝ调用的时?</p> <p>28) SIGWINCH<br />H口大小改变时发?</p> <p>29) SIGIO<br />文g描述W准备就l? 可以开始进行输?输出操作.</p> <p>30) SIGPWR<br />Power failure</p> <p>31) SIGSYS<br />非法的系l调用?/p> <p>在以上列出的信号中,E序不可捕获、阻塞或忽略的信hQSIGKILL,SIGSTOP<br />不能恢复至默认动作的信号有:SIGILL,SIGTRAP<br />默认会导致进E流产的信号有:SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGIOT,SIGQUIT,SIGSEGV,SIGTRAP,SIGXCPU,SIGXFSZ<br />默认会导致进E退出的信号有:SIGALRM,SIGHUP,SIGINT,SIGKILL,SIGPIPE,SIGPOLL,SIGPROF,SIGSYS,SIGTERM,SIGUSR1,SIGUSR2,SIGVTALRM<br />默认会导致进E停止的信号有:SIGSTOP,SIGTSTP,SIGTTIN,SIGTTOU<br />默认q程忽略的信hQSIGCHLD,SIGPWR,SIGURG,SIGWINCH</p> <p>此外QSIGIO在SVR4是退出,?.3BSD中是忽略QSIGCONT在进E挂h是l,否则是忽略,不能被阻?/p> <p>l止E序的时候在不得已的情况下不能用SIGKILLQ因为SIGKILL不会对子q程q行处理Q只是把对自p行处?/p> <p> </p> <p> </p> <p>Linux支持POSIX标准信号和实时信受下面给出Linux Signal的简表,详细l节可以查看man 7 signal?/p> <p> </p> <p>默认动作的含义如下:</p> <p>Term    l止q程</p> <p> </p> <table cellpadding="0" cellspacing="0" border="0"> <colgroup> <col width="101"> <col width="82"> <col width="98"> <col width="306"></colgroup> <tbody> <tr> <td><strong>信号</strong></td> <td><strong>取?/strong></td> <td><strong>默认动作</strong></td> <td><strong>含义Q发ZL(fng)原因Q?/strong></td> </tr> <tr> <td>SIGHUP</td> <td>1</td> <td>Term</td> <td>l端的挂断或q程M</td> </tr> <tr> <td>SIGINT</td> <td>2</td> <td>Term</td> <td>来自键盘的中断信?/td> </tr> <tr> <td>SIGQUIT</td> <td>3</td> <td>Core</td> <td>来自键盘的离开信号</td> </tr> <tr> <td>SIGILL</td> <td>4</td> <td>Core</td> <td>非法指o</td> </tr> <tr> <td>SIGABRT</td> <td>6</td> <td>Core</td> <td>来自abort的异怿?/td> </tr> <tr> <td>SIGFPE</td> <td>8</td> <td>Core</td> <td>点例外</td> </tr> <tr> <td>SIGKILL</td> <td>9</td> <td>Term</td> <td>杀?/td> </tr> <tr> <td>SIGSEGV</td> <td>11</td> <td>Core</td> <td>D非法错?内存引用无效)</td> </tr> <tr> <td>SIGPIPE</td> <td>13</td> <td>Term</td> <td>道损坏Q向一个没有读q程的管道写数据</td> </tr> <tr> <td>SIGALRM</td> <td>14</td> <td>Term</td> <td>来自alarm的计时器到时信号</td> </tr> <tr> <td>SIGTERM</td> <td>15</td> <td>Term</td> <td>l止</td> </tr> <tr> <td>SIGUSR1</td> <td>30,10,16</td> <td>Term</td> <td>用户自定义信?</td> </tr> <tr> <td>SIGUSR2</td> <td>31,12,17</td> <td>Term</td> <td>用户自定义信?</td> </tr> <tr> <td>SIGCHLD</td> <td>20,17,18</td> <td>Ign</td> <td>子进E停止或l止</td> </tr> <tr> <td>SIGCONT</td> <td>19,18,25</td> <td>Cont</td> <td>如果停止Ql执?/td> </tr> <tr> <td>SIGSTOP</td> <td>17,19,23</td> <td>Stop</td> <td>非来自终端的停止信号</td> </tr> <tr> <td>SIGTSTP</td> <td>18,20,24</td> <td>Stop</td> <td>来自l端的停止信?/td> </tr> <tr> <td>SIGTTIN</td> <td>21,21,26</td> <td>Stop</td> <td>后台q程ȝ?/td> </tr> <tr> <td>SIGTTOU</td> <td>22,22,27</td> <td>Stop</td> <td>后台q程写终?/td> </tr> <tr> <td>SIGBUS</td> <td>10,7,10</td> <td>Core</td> <td>ȝ错误Q内存访问错误)</td> </tr> <tr> <td>SIGPOLL</td> <td>Term</td> <td>Pollable事g发生(Sys V)Q与SIGIO同义</td> </tr> <tr> <td>SIGPROF</td> <td>27,27,29</td> <td>Term</td> <td>l计分布囄计时器到?/td> </tr> <tr> <td>SIGSYS</td> <td>12,-,12</td> <td>Core</td> <td>非法pȝ调用(SVr4)</td> </tr> <tr> <td>SIGTRAP</td> <td>5</td> <td>Core</td> <td>跟踪/断点自陷</td> </tr> <tr> <td>SIGURG</td> <td>16,23,21</td> <td>Ign</td> <td>socket紧急信?4.2BSD)</td> </tr> <tr> <td>SIGVTALRM</td> <td>26,26,28</td> <td>Term</td> <td>虚拟计时器到?4.2BSD)</td> </tr> <tr> <td>SIGXCPU</td> <td>24,24,30</td> <td>Core</td> <td>过CPU旉(4.2BSD)</td> </tr> <tr> <td>SIGXFSZ</td> <td>25,25,31</td> <td>Core</td> <td>过文g长度限制(4.2BSD)</td> </tr> <tr> <td>SIGIOT</td> <td>6</td> <td>Core</td> <td>IOT自陷Q与SIGABRT同义</td> </tr> <tr> <td>SIGEMT</td> <td>7,-,7</td> <td>Term</td> </tr> <tr> <td>SIGSTKFLT</td> <td>-,16,-</td> <td>Term</td> <td>协处理器堆栈错误(不?</td> </tr> <tr> <td>SIGIO</td> <td>23,29,22</td> <td>Term</td> <td>描述W上可以q行I/O操作</td> </tr> <tr> <td>SIGCLD</td> <td>-,-,18</td> <td>Ign</td> <td>与SIGCHLD同义</td> </tr> <tr> <td>SIGPWR</td> <td>29,30,19</td> <td>Term</td> <td>?sh)力故?System V)</td> </tr> <tr> <td>SIGINFO</td> <td>29,-,-</td> <td>与SIGPWR同义</td> </tr> <tr> <td>SIGLOST</td> <td>-,-,-</td> <td>Term</td> <td>文g锁丢?/td> </tr> <tr> <td>SIGWINCH</td> <td>28,28,20</td> <td>Ign</td> <td>H口大小改变(4.3BSD, Sun)</td> </tr> <tr> <td>SIGUNUSED</td> <td>-,31,-</td> <td>Term</td> <td>未用信?will be SIGSYS)</td> </tr> </tbody> </table> <p> </p> <p>说明Q?/p> <p>一些信L(fng)取值是gl构相关的(一般alpha和sparc架构用第一个|i386、ppc和sh架构用中间|mips架构用第三个| - 表示相应架构的取值未知)?/p> <p> </p> <p>蓝色的是POSIX.1-1990标准信号?/p> <p>SIGKILL和SIGSTOP信号不能被挂钩、阻塞或忽略?/p> <p> </p> <p>青色的是SUSv2和POSIX.1-2001定义的信受?/p> <p>在Linux 2.2Q包括)内核之前QSIGSYS、SIGXCPU、SIGXFSZ和SIGBUS QSPARC和MIPS架构除外Q的默认动作是终止进E,但没?core dump。Linux 2.4遵@POSIX.1-2001要求Q这些信L(fng)默认动作改ؓ(f)Q终止进E同时做core dump?/p> <p> </p> <p>色的是其他常见的信受?/p> <p>信号29在Alpha上ؓ(f)SIGINFO / SIGPWR Q在Sparc上ؓ(f)SIGLOST?/p> <p>SIGEMT没有在POSIX.1-2001中说明,但是在大多数的Unices中仍然能见到Q典型的默认动作是终止进Eƈ做core dump?/p> <p>SIGPWR没有在POSIX.1-2001中说明,在用它的一些Unices中典型的默认动作是忽略?/p> <p>SIGIO没有在POSIX.1-2001中说明,在用它的一些Unices中典型的默认动作是忽略?/p> <p> </p> <p>q程可以通过使用sigaction和signalpȝ调用来改变信L(fng)默认处理方式Q用signal的可UL性差Q。进E可以选择下列3U信号处理方式中的一U:</p> <p>1、执行默认操作;</p> <p>2、忽略该信号Q?/p> <p>3、捕莯信号Q但是通过信号句柄来调用自定义的处理函数?/p> <p> </p> <p>信号可能被阻塞。进E中的每个线E拥有独立的信号掩码Q用来表C本U程的信可d。线E通过pthread_sigmask来设|它的信h码。单U程E序可以用sigprocmask来操作信h码。在多线E程序中Q所有线E处理一个指定信L(fng)默认行ؓ(f)都是一L(fng)?/p> <p> </p> <p> </p> <p>补充:</p> <p>SIG_DFL,SIG_IGN 分别表示无返回值的函数指针Q指针值分别是0?Q这两个指针值逻辑上讲是实际程序中不可能出现的函数地址倹{?/p> <p>SIG_DFLQ默认信号处理程?br />SIG_IGNQ忽略信L(fng)处理E序</p></div><img src ="http://www.shnenglu.com/colorful/aggbug/202484.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/colorful/" target="_blank">多彩人生</a> 2013-08-12 09:09 <a href="http://www.shnenglu.com/colorful/archive/2013/08/12/202484.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>让CentOS默认生成core dumphttp://www.shnenglu.com/colorful/archive/2013/07/31/202256.html多彩人生多彩人生Wed, 31 Jul 2013 02:34:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/31/202256.htmlhttp://www.shnenglu.com/colorful/comments/202256.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/31/202256.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202256.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202256.html

CentOS中默认设|了ulimit -c 0也就是默认程序不生成core dump,q样很麻?每次启动E序前都要让用户先执行一ơulimit -c ulimited,有时候用户忘记则不生成core,很不利于错误分析,所以研I了下如何让pȝ默认q成core.

在网上找了部分资?看到?/p>

CentOS 5中ulimitD整ƈ怹生效的方?/p>

http://www.sunchis.com/html/os/linux/2011/0609/338.html

q篇文章,其中说通过~辑/etc/security/limits.conf文g可以实现ulimit的D?试了nofile后的可?但是写入?/p>

* soft core unlimited
* hard core unlimited


重新登陆却没有效?nbsp; // ps by zc, 我到q里有效果?br />

[root@localhost ~]# ulimit -a
core file size          (blocks, -c) 0

通过研究,发现/etc/profile文g中有一?/p>

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

二话不说,把第二行?注释掉后,?/p>

# No core files by default
#ulimit -S -c 0 > /dev/null 2>&1

保存重新登陆用户,再次查看,一切正?

[root@localhost ~]# ulimit -a
core file size          (blocks, -c) ulimited


-----------------------------------------------------------------

1Q设|系l允许生产core文g
?~/.bash_profile 中增?/div>
ulimit -c unlimited
使用ulimit -a可以查看pȝcore文g的大限?
使用ulimit -c [kbytes]可以讄pȝ允许生成的core文g大小;
ulimit -c 0 不生core文g
ulimit -c 100 讄core文g最大ؓ(f)100k
ulimit -c unlimited 不限制core文g大小



多彩人生 2013-07-31 10:34 发表评论
]]>
apache 开启多站点http://www.shnenglu.com/colorful/archive/2013/07/30/202245.html多彩人生多彩人生Tue, 30 Jul 2013 10:41:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/30/202245.htmlhttp://www.shnenglu.com/colorful/comments/202245.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/30/202245.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202245.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202245.html


http://zhangyong333revice.blog.163.com/blog/static/1131518832011101811237149/
http://hi.baidu.com/dspace/item/68b67705a9c53bd21ff046a1
http://zhb1208.iteye.com/blog/1432957
http://zhidao.baidu.com/question/285759208.html
http://michaelkang.blog.51cto.com/1553154/1065251
http://blog.sina.com.cn/s/blog_7e56997901016bw7.html
http://wenku.baidu.com/view/95b2361ca8114431b90dd8c0.html
http://www.cnblogs.com/see7di/archive/2011/06/15/2239756.html
http://zhidao.baidu.com/question/472396507.html
http://blog.csdn.net/yongshiok/article/details/6936960
http://www.xker.com/page/e2010/0925/98279.html
http://www.codesky.net/article/201101/149128.html

如何更改linux下的Apache端口?/h2>

一、修?etc/httpd/conf/httpd.conf文g中的监听端口?/p>

Listen 80

?0修改成需要的P?000Q即

Listen 8000
二、查看SELinux下http相关端口

# semanage port -l|grep http
http_cache_port_t              tcp      3128, 8080, 8118, 10001-10010
http_cache_port_t              udp      3130
http_port_t                    tcp      80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t            tcp      5988
pegasus_https_port_t           tcp      5989

发现8000不在其范围之内,所以需要另外添加,Ҏ(gu)如下Q?/p>

# semanage port -a -t http_port_t -p tcp 8000

再次查看Q?/p>

# semanage port -l|grep http
http_cache_port_t              tcp      3128, 8080, 8118, 10001-10010
http_cache_port_t              udp      3130
http_port_t                    tcp      8000, 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t            tcp      5988
pegasus_https_port_t           tcp      5989

三、在防火墙中开放新d的端?/p>

修改/etc/sysconfig/iptables文gQ在文g中添加如一行:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8008 -j ACCEPT

四、重启防火墙和Apache

# service iptables restart

# service httpd restart

五、正常情况下Q应该可以通过新端口访问WEB服务了?/p>

注:

1、第二、三、四步骤是在pȝ已经开启SELinux和防火墙的情况下讄的,如果已经关闭此两个服务,修改端口后直接重启Apache卛_Q?/p>

2、修改的端口号可以是执行#semanage port -l|grep http后,默认已经有的端口Q如8443Q这样可以省略额外添加SELinux端口操作Q?/p>

3、第三步操作可以囑Ş界面下完成?/p>

参考资?/p>

1、Permission denied: make_sock: could not bind to address

 http://emmune.blogspot.com/2009/07/permission-denied-makesock-could-not.html

不熟(zhn)python、plone、zopeQ想用apache?0端口已经不在Q就征用81端口凑合吧。修改httpd.conf后apachectl startQ结果:
(13)Permission denied: make_sock: could not bind to address [::]:81
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:81

查一下SELinux下http相关端口 semanage port -l|grep httpQ结果:
http_cache_port_t tcp 3128, 8080, 8118, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989

直接用man semanage最后例子中的一?br /># Allow Apache to listen on port 81
semanage port -a -t http_port_t -p tcp 81
然后再apachectl startQOK。用域?81能够讉K啦?br />
注:semanage
semanage is used to configure certain elements of SELinux policy without requiring modification to or recompilation from policy sources. This includes the mapping from Linux usernames to SELinux user identities (which controls the initial security context assigned to Linux users when they login and bounds their authorized role set) as well as security context mappings for various kinds of objects, such as network ports, interfaces, and nodes(hosts) as well as the file context mapping. See the EXAMPLES section below for some examples of common usage. Note that the semanage login command deals with the mapping from Linux usernames (logins) to SELinux user identities, while the semanage user command deals with the mapping from SELinux user identities to authorized role sets. In most cases, only the former mapping needs to be adjusted by the administrator; the latter is principally defined by the base policy and usually does not require modification.

2、linux 下apche无法监听端口解决办法

http://www.zzxj.net/blog/fxs_2008/archive/2010/07/05/187.html

惛_立一个测试用的虚拟主机,遇到了这个问题:
[root@localhost html]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.termwikidev for ServerName
(13)Permission denied: make_sock: could not bind to address [::]:81
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:81
no listening sockets available, shutting down
Unable to open logs

解决办法Q?br />
semanage port -l|grep http
semanage port -a -t http_port_t -p tcp 81

q个两个命o一是查看,一个是dQ添加完再查看一遍,如果?1Q则成功。另可能要以root用户q行?br />
此外Q如果要外网讉KQ还要打开linux的防火墙Q?br />
[root@localhost html]# vim /etc/sysconfig/iptables
[root@localhost html]# service iptables restart

重启apache.

相关资料Q?br />
starting httpd 13 permission denied make_sock could not bind to address2010q?1?9?星期?11:33In Fedora Core 5/6 and RHEL 5. We have made it easier to customize certain common parts of SELinux. In previous releases of SELinux if you wanted to change simple things like which port a daemon could listen to, you would need to write policy. Now we have the semanage utility.

SELinux assigns types to all network ports on a system. By default all ports are less then 1024 are labeled reserved_port_t and all ports > 1024 are labeled port_t. If a port is assigned to a particular type
say the http port 80, it has an assigned type of http_port_t. If you want to look at all the assigned ports in SELinux, you can use the semanage tool, semanage port -l.

So if you executed

semanage port -l | grep http
http_cache_port_t tcp 3128, 8080, 8118
http_cache_port_t udp 3130
http_port_t tcp 80, 443, 488, 8008, 8009, 8443
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989

Here we see http_port_t is assigned to ports 80, 443, 488, 8008, 8009, 8443

The policy is written to allow httpd_t http_port_t:tcp_socket name_bind;

This means the apache command can "bind" to an port that is labeled http_port_t.

So lets say you want to run httpd on port 81.

So you edit /etc/httpd/http.conf

and change this line
Listen 80
to
Listen 81


Now restart the daemon.
service httpd restart
Stopping httpd: [ OK ]
Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:81
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:81
no listening sockets available, shutting down
Unable to open logs
[FAILED]

Now the daemon fails to start because it can not bind to port 81.

This generates an AVC that looks like

----
time->Tue Dec 12 17:37:49 2006
type=SYSCALL msg=audit(1165963069.248:852): arch=40000003 syscall=102 success=no exit=-13 a0=2 a1=bf96a830 a2=b5b1e8 a3=9e58b68 items=0 ppid=21133 pid=21134 auid=3267 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts10 comm="httpd" exe="/usr/sbin/httpd" subj=user_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1165963069.248:852): avc: denied { name_bind } for pid=21134 comm="httpd" src=81 scontext=user_u:system_r:httpd_t:s0 tcontext=system_u:object_r:reserved_port_t:s0 tclass=tcp_socket

To fix this you can use semanage to add the port

semanage port -a -t http_port_t -p tcp 81

service httpd start
Starting httpd: [ OK ]

多彩人生 2013-07-30 18:41 发表评论
]]>php socket connect Permission denied :13http://www.shnenglu.com/colorful/archive/2013/07/29/202222.html多彩人生多彩人生Mon, 29 Jul 2013 09:27:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/29/202222.htmlhttp://www.shnenglu.com/colorful/comments/202222.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/29/202222.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202222.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202222.htmlHi there!

For the TCP connections: socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
In case you're having problems in socket_connect() with socket_strerror() = "Permission denied", you may be having a SELinux config issue.

Check if SELinux is enabled:
# /usr/sbin/sestatus -v
In case it is, you can just type the command:
# setsebool httpd_can_network_connect=1

That's it... I read you had to reboot, but I didn't and it worked fine anyway. More info, you may check:
http://arkiv.netbsd.se/?ml=squirrelmail-users&a=2005-11&t=1523021


多彩人生 2013-07-29 17:27 发表评论
]]>
PHP的ntohl|络字节序函数及相关知识http://www.shnenglu.com/colorful/archive/2013/07/29/202219.html多彩人生多彩人生Mon, 29 Jul 2013 06:49:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/29/202219.htmlhttp://www.shnenglu.com/colorful/comments/202219.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/29/202219.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202219.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202219.htmlhttp://n3yang.com/archives/2011/12/16/php-function-ntohl/
http://www.w3school.com.cn/php/func_misc_unpack.asp    // php unpack 函数


最q项目中使用CPHP与C服务器的socket通信Q在做数据{换的时候,PHP没有提供对应网l字节序和机器字节序怺转换的程序,但是Ҏ(gu)函数的意义,我们可以做相应的转换来实现这一函数Q?/p>

1
2
3
4
function ntohl($str){
    $arr = unpack('I', pack('N', $str));
    return $arr[1];
}

函数的意?/strong>
E序的作用是网l字节序和机器字节序q行怺转换。在C/C++、Python、Delphi中都提供了相应的函数“ntohl”?#8220;htonl”Q如果是shortcd是“ntohs”?#8220;htons”。下面是q些函数的意义:

ntohl()--"Network to Host Long" htonl()--"Host to Network Long" htons()--"Host to Network Short" ntohs()--"Network to Host Short"

什么是L字节?/strong>
不同的机器字节序不相同,q与使用的CPU有关。不同的CPU在处理高位字节时所存储的顺序是不同的?br /> 例如Intel x86l构? short型数0×1234表示?4 12, int型数0×12345678表示?8 56 34 12
如IBM power PCl构? short型数0×1234表示?2 34, int型数0×12345678表示?2 34 56 78

|络字节?/strong>
正是׃每个L的处理顺序有可能不同Q所以在|络协议中规定数据从高到低顺序存储,目的是在不同架构的主Z可以正常通信Q避免兼Ҏ(gu)问题?/p>



多彩人生 2013-07-29 14:49 发表评论
]]>
独立安装php sockets模块http://www.shnenglu.com/colorful/archive/2013/07/28/202201.html多彩人生多彩人生Sun, 28 Jul 2013 14:16:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/28/202201.htmlhttp://www.shnenglu.com/colorful/comments/202201.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/28/202201.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202201.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202201.html
http://blog.chinaunix.net/uid-24426415-id-77267.html

在安装cacti的时候是需要用到sockets模块的,如果在安装php的时候没有?-with-sockets的话Q这时就必须手动重新d此模块。操作步骤如?/strong>Q?/div>
 
1?strong>q入php源文件目录ext下,扑ֈsockets目录。ƈq入此目?/strong>
  #cd php-5.2.9/ext/sockets/

2.在该目录下执行phpize命oQ此命o在php目录的bin?/strong>?/div>
# /usr/local/php/bin/phpize
 
3?strong>配置~译安装
# ./configure --enable-sockets --with-php-config=/usr/local/php/bin/php-config
# make
# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
提示so已经安装到目录下?/div>
 
4?strong>修改配置在php.ini里,讄扩展目录Q?br />extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
q添加扩展模块引用:
extension = sockets.so
 
5.查php.ini配置文g的正?/strong>
/usr/local/php/bin/php -v
执行q个命oӞphp会去查配|文件是否正,如果有配|错误,q里会报错,可以Ҏ(gu)错误信息L?/div>

6.通过/usr/local/php/bin/php -m命o查看是否安装sockets成功

monitor# /usr/local/php/bin/php -m
[PHP Modules]
ctype
date
dom
filter
gd
hash
iconv
json
libxml
mbstring
mysql
pcre
PDO
pdo_sqlite
posix
Reflection
session
SimpleXML
sockets
SPL
SQLite
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

 
7.重启apache生效
/usr/local/apache2/bin/apachectl restart


多彩人生 2013-07-28 22:16 发表评论
]]>php学习(fn)http://www.shnenglu.com/colorful/archive/2013/07/28/202199.html多彩人生多彩人生Sun, 28 Jul 2013 13:28:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/28/202199.htmlhttp://www.shnenglu.com/colorful/comments/202199.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/28/202199.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202199.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202199.htmlhttp://wecoo.iteye.com/blog/1119812  php安装

安装php-5.3.4.tar.bz2首先要安装libxml2而且版本不低?.6.11Q这里我选择的libxml2-2.6.30.tar.bz2

[root@localhost root]# tar xjvf libxml2-2.6.31.tar.bz2

[root@localhost root]# cd libxml2-2.6.31

[root@localhost libxml2-2.6.31]# ./configure --prefix=/usr/local/libxml2

[root@localhost libxml2-2.6.31]# make

[root@localhost libxml2-2.6.31]# make install

到这里libxml2安装完成了Q下面开始安装PHP5.3

[root@localhost libxml2-2.6.31]# cd

[root@localhost root]# tar -xjvf php-5.3.4.tar.gz2

[root@localhost root]# cd php-5.3.4

[root@localhost php-5.3.4]# ./configure --prefix=/usr/local/php5 //安装位置

--enable-mbstring //讄 php 支持多字节字W串

--with-apxs2=/usr/local/apache2/bin/apxs //讄 apache 服务支持 apxs位置

--width-libxml-dir=/usr/local/libxml2 //讄刚才安装的libxml2位置

--with-mysql=/usr/mysql //讄 mysql E序安装位置

--with-config-file-path=/usr/local/php5 //讄 php E序配置文g位置

[root@localhost php-5.3.4]# make

[root@localhost php-5.3.4]# make install

[root@localhost php-5.3.4]# cp php.ini-development /usr/local/php5/php.ini

?APACHE里添?phpQ APACHE 支持 PHP

[root@localhost php-5.3.4]# vi /usr/local/apache2/conf/httpd.conf

53 LoadModule php5_module modules/libphp5.so

54 AddType application/x-httpd-php .php //或者在下面的meta中定?搜烦AddType可以找?

167

168 DirectoryIndex index.php index.html

169

[root@localhost php-5.3.4]# service apache restart

创徏index.php在网站默认根目录下,输入|址讉K试

--------------------------------------------------------------
源码安装时提C找不到 libxml2
yum install libxml2 libxml2-devel

----------------------------------------------------------------
php socket试?提示
Warning: socket_create() Unable to create socket [1]: Operation not permitted
需要root权限Q可用通过在root?Qusr/local/php/bin/php ping.php 来运?br />
The class is using SOCK_RAW to create the socket. It might be you need root privilegues on your machine to execute this code. If this any issue with your enviroment, then fall back to shell_exec

Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-
Unable to load dynamic library '/usr/lib/php/modules/pgsql.so' - libpq.so.5: failed to map segment from shared object:

在用PHP~写web面讉KPostgres数据库时Q遇Capache  没有正确加蝲pdo_pgsql.so的问题, 把它记录下来以备用?/p>


通过web讉Kphp面Ӟ面没有反应Q?查看http log时出C面的错误Q?/p>

PHP Fatal error: Call to undefined function pg_connect()

但是在命令行q行phpE序讉Kpostgres试是成功的Q?没有发现问题?/p>


|上搜烦Q都是说php讉Kpostgres 安装了php-pgsql可以了?但我已经通过yum安装了php-pgsqlQ?查看/etc/php.ini, /etc/php.d/pdo_pgsql.ini都是配置正确的?/p>

[root@localhost php.d]# cat pdo_pgsql.ini 

; Enable pdo_pgsql extension module

extension=pdo_pgsql.so

phpinfoQ)也显C加载了pdo_pgsql.iniQ?pgsql.ini Q?但在PDO节里没有看到Postgres?/p>


后来惛_会不会是SElinux的问题, 把SElinux 关了Q再重启apacheQ?/p>

[root@localhost php.d]# setenforce 0

         service httpd restart

重启q行phpinfo(),  q到postgres 正确加蝲了?/p>

回过来查看以前apache 的error_log, 实是php 在加载pdo_pgsql.so 时出C׃讉K权限引v的问题?/p>

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/pdo_pgsql.so' - libpq.so.5: failed to map segment from shared object: Permission denied in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/pgsql.so' - libpq.so.5: failed to map segment from shared object: Permission denied in Unknown on line 0

把SElinux 关了后, 启动apache时就没有q个错误了,php也成功加载了pgsql?br />

在实际应用中需要关闭SElinuxQ或者重设libpq.so.5的权限?/p>


Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q?/p>

Qusr/bin/apxs: no such file or directory

yum install httpd-devel





多彩人生 2013-07-28 21:28 发表评论
]]>linux查找软g安装位置http://www.shnenglu.com/colorful/archive/2013/07/28/202193.html多彩人生多彩人生Sun, 28 Jul 2013 08:17:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/28/202193.htmlhttp://www.shnenglu.com/colorful/comments/202193.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/28/202193.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202193.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202193.html以apacheZ
如果以rpm包Ş式安?br /> 1.rpm包Ş式(包括yum安装Q可?br /> rpm -aq|grep http                          #查看是否安装了apache的包
rpm -qi   输入上一步获取的包名                #了解一下这个apache包的信息
rpm -ql   输入包名                          #此apache包中所有文件安装的位置

2Q源码安?br /> whereis  httpd                             #http文g的位|?/div>

多彩人生 2013-07-28 16:17 发表评论
]]>
Linux 中如何卸载已安装的Y?转蝲)http://www.shnenglu.com/colorful/archive/2013/07/28/202185.html多彩人生多彩人生Sun, 28 Jul 2013 02:56:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/28/202185.htmlhttp://www.shnenglu.com/colorful/comments/202185.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/28/202185.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202185.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202185.html
Linux 中如何卸载已安装的Y?
  Linux软g的安装和卸蝲一直是困扰许多新用L(fng)N。在 Windows中,我们可以使用软g自带的安装卸载程序或在控刉板中?#8220;d/删除E序”来实现。与其相cMQ在Linux下有一个功能强大的软g安装 卸蝲工具Q名为RPM。它可以用来建立、安装、查询、更新、卸载Y件。该工具是在命o行下使用的。在Shell的提C符后输入rpmQ就可获得该命o的帮 助信息?br />

  软g的安?/strong>

  Linux下Y件的安装主要有两U不同的形式。第一U安装文件名为xxx.tar.gzQ另一U安装文件名为xxx.i386.rpm。以W一U方式发行的软g多ؓ(f)以源码Ş式发送的Q第二种方式则是直接以二q制形式发送的?/p>

  对于W一U,安装Ҏ(gu)如下Q?/p>

  1 .首先Q将安装文g拯至你的目录中。例如,如果你是以rootw䆾d上的Q就Y件拷贝至/root中?/p>

  #cp xxx.tar.gz /root

  2 .׃该文件是被压~ƈ打包?应对其解压羃。命令ؓ(f)Q?/p>

  #tar xvzf filename.tar.gz 如果是filename.tar.bz2格式的,应该是tar jxvf filename.tar.bz2来解?/p>

  3. 执行该命令后Q安装文件按路径Q解压羃在当前目录下。用ls命o可以看到解压~后的文件。通常在解压羃后生的文g中,?#8220;Install”的文件。该文g为纯文本文gQ详l讲qC该Y件包的安装方法?/p>

  4.执行解压~后产生的一个名为configure的可执行脚本E序。它是用于检查系l是否有~译时所需的库Q以及库的版本是否满编译的需要等安装所需要的pȝ信息。ؓ(f)随后的编译工作做准备。命令ؓ(f)Q?#./configure

  如果(zhn)想把Y件安装到指定目录Q应该用#./configure --prefix=/(zhn)自己指定的目录Q比如我x一个mlterm安装?opt/mlterm目录中,应该如下输入

  #./configure --prefix=/opt/mlterm

  5.查通过后,生成用于编译的MakeFile文g。此Ӟ可以开始进行编译了。编译的q程视Y件的规模和计机性能的不同,所耗费的时间也不同。命令ؓ(f)Q?#make?/p>

  6.成功~译后,键入如下的命令开始安装:

  #make install

  7.安装完毕Q应清除~译q程中生的临时文g和配|过E中产生的文件。键入如下命令:

  #make clean

  #make distclean

  xQY件的安装l束?/p>

  对于W二U,其安装方法要单得多?/p>

  同第一U方式一P安装文件拷贝至你的目录中。然后用rpm来安装该文g。命令如下:

  #rpm -i filename.i386.rpm

  rpm自动将安装文g解包QƈY件安装到~省的目录下。ƈY件的安装信息注册到rpm的数据库中。参数i的作用是使rpmq入安装模式?/p>

  软g的卸?/strong>

  1.软g的卸载主要是使用rpm来进行的。卸载Y仉先要知道软g包在pȝ中注册的名称。键入命令:

  #rpm -q -a

  卛_查询到当前系l中安装的所有的软g包?/p>

  2. 定了要卸蝲的Y件的名称Q就可以开始实际卸载该软g了。键入命令:

  #rpm -e [package name]

  卛_卸蝲软g。参数e的作用是使rpmq入卸蝲模式。对名ؓ(f)[package name]的Y件包q行卸蝲。由于系l中各个软g包之间相互有依赖关系。如果因存在依赖关系而不能卸载,rpm给予提Cƈ停止卸蝲。你可以使用如下的命令来忽略依赖关系Q直接开始卸载:

  #rpm -e [package name] -nodeps

  忽略依赖关系的卸载可能会Dpȝ中其它的一些Y件无法?/p>

  如果想知道rpm包安装到哪里了呢Q?/p>

  应该?#rpm -ql [package name]

  3.如何卸蝲用源码包安装的YӞ

  最好是看README和INSTALL Q一般的情况下都有说Q但大多软g没有提供源码包的卸蝲Ҏ(gu)Q我们可以找到Y件的安装点删除。主要看你把它安装在哪了?/p>

  比如Q?/p>

  如果安装软gӞ指定个目录。这个问题也不会难;

  比如用源码包安装gaim ?/p>

  #./configure --prefix=/opt/gaim

  #make

  #make install

  如果安装mlterm

  #./configure --prefix=/opt/mlterm

  #make

  #make install

  把源码包安装的YӞ都指定安装在 /opt目录中,q样不就知道了;

  如果删除Q就删除相应的Y件目录;

  有些软g要在解压安装目录中执?make uninstall Q这样就卸蝲掉了?/p>



多彩人生 2013-07-28 10:56 发表评论
]]> centOS 自动安装php http://www.shnenglu.com/colorful/archive/2013/07/27/202165.html多彩人生多彩人生Sat, 27 Jul 2013 08:16:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/27/202165.htmlhttp://www.shnenglu.com/colorful/comments/202165.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/27/202165.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202165.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202165.html

centos下安装php

#yum install -y php

q个只安装PHP

安装q行库及MySQL的支?/p>

#yum install -y php php-devel php-mysql        // postgresql   ?php-pgsql

如果你的pȝ是CentOS 5.6那么上面q条命o安装的是PHP 5.1,

要安?PHP 5.3则执行下面的命o:

#yum install -y php53 php53-devel php53-mysql     

自动安装启动
#service httpd restart

会安装apache(也就是httpd),但是不会安装MySQL,MySQL需要单独安? 安装MySQL命o: #yum install -y mysql mysql-devel mysql-server q条命o包括MySQL的运行库及服务端


多彩人生 2013-07-27 16:16 发表评论
]]>
CentOS 6.0 pȝ LAMP(Apache+MySQL+PHP)安装步骤http://www.shnenglu.com/colorful/archive/2013/07/26/202145.html多彩人生多彩人生Fri, 26 Jul 2013 12:48:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/26/202145.htmlhttp://www.shnenglu.com/colorful/comments/202145.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/26/202145.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/202145.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/202145.htmlhttp://down.chinaz.com/server/201109/1064_1.htm
http://www.laozhe.net/articles/302.html

CentOS 6.0 pȝ LAMPQApache+MySQL+PHPQ?安装步骤

  安装完毕Q让 MySQL 能够随系l自动启动:

1
2
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

  讄 MySQL 数据 root 账户的密码:

1
mysql_secure_installation

  当出现如下提C时候直接按回RQ?/p>

Enter current password for root

  出现如下再次回RQ?/p>

Set root password? [Y/n]

  出现如下提示输入你需要设|的密码Q回车后在输入一ơ确认:

New password:

  接下来还会有四个认Q分别是Q?/p>

  • Remove anonymous users? [Y/n]
  • Disallow root login remotely? [Y/n]
  • Remove test database and access to it? [Y/n]
  • Reload privilege tables now? [Y/n]

  直接回R卛_?/p>

二、安?Apache lg

  ׃ CentOS 已经装?ApacheQ直接运行安装:

1
yum install httpd

  同样配置pȝ?Apache 随系l启动:

1
chkconfig --levels 235 httpd on

  配置完毕Q启?ApacheQ?/p>

1
/etc/init.d/httpd start

  此时已经可以讉K你的服务器,不出意外的话Q能够看?“Apache 2 Test Page powered by CentOS” 的测试页面。注意,如果其他机器讉Kq台服务无法昄q个面Q而直接在q台服务器上可以讉K的话Q一般情况下?CentOS 自带的防火墙止了。你只需要进入防火墙Q将 “WWW” 对应?“80” 端口打开卛_?/p>

  注意Q在 CentOS ?Apache 的默认根目录?/var/www/htmlQ配|文?/etc/httpd/conf/httpd.conf。其他配|存储在 /etc/httpd/conf.d/ 目录?/p>

三、安?PHP

  输入如下指o安装 PHP:

1
yum install php

  需要重新启?Apache 服务Q?/p>

1
/etc/init.d/httpd restart

四、测?PHP 相关信息

  q步实际上可以省略,但是Z试是否安装成功Q你可以新徏一?PHP 面q行试Q?vim ~辑器新建:

1
vi /var/www/html/info.php

  ?“i” 键进行编辑,输入Q?/p>

1
2
3
<?php
phpinfo();
?>

  ~辑完毕Q按 “ESC” 键退出编辑模式,接着输入Q?/p>

1
:wq

  然后回RQ即保存q出?/p>

  此时你可以访问你的站点地址Q例?“http://192.168.1.2/info.php”Q查看是否能看到相关?PHP 信息?/p>

  看到q样的图Q就说明 PHP 安装成功了?/p>

五、将 PHP 模块?MySQL 模块兌h

  q需要将 PHP ?MySQL 兌hQ才能正常工作。搜索模块:

1
yum search php

  安装相关模块Q?/p>

1
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

  需要重?Apache 模块才能生效Q?/p>

1
/etc/init.d/httpd restart

  再次h刚才建立?“info.php” 面Q往下拉扑ֈ相关 MySQL 模块Q看是否到相关信息?/p>

  如果看到如上囄关信息,则说?MySQL 工作正常了?/p>

六、ȝ

  到这里就l束了,本文阐述了在 CentOS 6.0 pȝ?LAMP lgQApache+MySQL+PHPQ?的详l安装步骤,可以让更多新手熟(zhn)服务器配置环境?/p>

  但是到这里,q只是将环境配置完毕Q很多东西还有欠~,而且q是一些重要的问题Q例如目录的权限配置问题Q或者是理上的问题Q像建立 FTP {。这些内定w后会慢慢谈到?/p>



多彩人生 2013-07-26 20:48 发表评论
]]>
Linux top 命o详解 http://www.shnenglu.com/colorful/archive/2013/07/13/201764.html多彩人生多彩人生Sat, 13 Jul 2013 03:30:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/13/201764.htmlhttp://www.shnenglu.com/colorful/comments/201764.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/13/201764.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/201764.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/201764.html

http://blog.csdn.net/sunboy_2050/article/details/6129177

查看多核CPU命o

 mpstat -P ALL  ?nbsp; sar -P ALL 

 

说明Q?/strong>sar -P ALL > aaa.txt   重定向输出内容到文g aaa.txt

 

top命ol常用来监控linux的系l状况,比如cpu、内存的使用Q程序员基本都知道这个命令,但比较奇怪的是能用好它的人却很少Q例如top监控视图中内存数值的含义有不少的曲解?/p>

本文通过一个运行中的WEB服务器的top监控截图Q讲qtop视图中的各种数据的含义,q包括视图中各进E(dQ的字段的排序?/p>

 

topq入视图

top视图 01

top视图 01

【top视图 01】是刚进入top的基本视图,我们来结合这个视图讲解各个数据的含义?/p>

W一行:
10:01:23 — 当前pȝ旉
126 days, 14:29 — pȝ已经q行?26?4时29分钟Q在q期间没有重启过Q?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />2 users — 当前?个用L(fng)录系l?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />load average: 1.15, 1.42, 1.44 — load average后面的三个数分别?分钟?分钟?5分钟的负载情c?/p>

load average数据是每?U钟查一ơ活跃的q程敎ͼ然后按特定算法计出的数倹{如果这个数除以逻辑CPU的数量,l果高于5的时候就表明pȝ在超负荷q{了?/p>

W二行:
Tasks — dQ进E)Q系l现在共?83个进E,其中处于q行中的?个,182个在休眠QsleepQ,stoped状态的?个,zombie状态(僵尸Q的?个?/p>

W三行:cpu状?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />6.7% us — 用户I间占用CPU的百分比?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />0.4% sy — 内核I间占用CPU的百分比?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />0.0% ni — 改变q优先的进E占用CPU的百分比
92.9% id — I闲CPU癑ֈ?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />0.0% wa — IO{待占用CPU的百分比
0.0% hi — 中断(Hardware IRQQ占用CPU的百分比
0.0% si — 软中断(Software InterruptsQ占用CPU的百分比

在这里CPU的用比率和windows概念不同Q如果你不理解用L(fng)间和内核I间Q需要充充电(sh)了?/p>

W四行:内存状?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />8306544k total — 物理内存总量Q?GBQ?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />7775876k used — 使用中的内存总量Q?.7GBQ?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />530668k free — I闲内存总量Q?30MQ?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />79236k buffers — ~存的内存量 Q?9MQ?/p>

W五行:swap交换分区
2031608k total — 交换区总量Q?GBQ?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />2556k used — 使用的交换区总量Q?.5MQ?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />2029052k free — I闲交换区总量Q?GBQ?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />4231276k cached — ~冲的交换区总量Q?GBQ?/p>

q里要说明的是不能用windows的内存概느解这些数据,如果按windows的方式此台服务器“q”Q?G的内存总量只剩?30M的可用内存。Linux的内存管理有其特D性,复杂炚w要一本书来说明,q里只是单说点和我们传统概念QwindowsQ的不同?/p>

W?四行中用中的内存总量QusedQ指的是现在pȝ内核控制的内存数Q空闲内存总量QfreeQ是内核q未U_其管控范围的数量。纳入内核管理的内存不见 得都在用中Q还包括q去使用q的现在可以被重复利用的内存Q内核ƈ不把q些可被重新使用的内存交q到free中去Q因此在linux上free内存会越 来越,但不用ؓ(f)此担心?/p>

如果Z?fn)惯去计可用内存数Q这里有个近似的计算公式Q第四行的free + W四行的buffers + W五行的cachedQ按q个公式此台服务器的可用内存Q?30668+79236+4231276 = 4.7GB?/p>

对于内存监控Q在top里我们要时刻监控W五行swap交换分区的usedQ如果这个数值在不断的变化,说明内核在不断进行内存和swap的数据交换,q是真正的内存不够用了?/p>

W六行是I

W七行以下:各进E(dQ的状态监?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />PID — q程id
USER — q程所有?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />PR — q程优先U?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />NI — nice倹{负DC高优先U,正DCZ优先U?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />VIRT — q程使用的虚拟内存总量Q单位kb。VIRT=SWAP+RES
RES — q程使用的、未被换出的物理内存大小Q单位kb。RES=CODE+DATA
SHR — ׃n内存大小Q单位kb
S — q程状态。D=不可中断的睡眠状?R=q行 S=睡眠 T=跟踪/停止 Z=僵尸q程
%CPU — 上次更新到现在的CPU旉占用癑ֈ?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />%MEM — q程使用的物理内存百分比
TIME+ — q程使用的CPU旉总计Q单?/100U?br style="margin:0px; font-family:Arial,Helvetica,sans-serif; padding:0px" />COMMAND — q程名称Q命令名/命o行)

多U多核CPU监控

在top基本视图中,按键盘数?#8220;1”Q可监控每个逻辑CPU的状况:

top视图 02

top视图 02

观察上图Q服务器?6个逻辑CPUQ实际上?个物理CPU?/p>

q程字段排序

?认进入topӞ各进E是按照CPU的占用量来排序的Q在【top视图 01】中q程ID?4210的javaq程排在W一Qcpu占用100%Q,q程ID?4183的javaq程排在W二Qcpu占用12%Q。可通过 键盘指o来改变排序字D,比如想监控哪个进E占用MEM最多,我一般的使用Ҏ(gu)如下Q?/p>

1. 敲击键盘“b”Q打开/关闭加亮效果Q,top的视囑֏化如下:

top视图 03

top视图 03

我们发现q程id?0704?#8220;top”q程被加亮了Qtopq程是视图W二行显C的唯一的运行态(runingQ的那个q程Q可以通过敲击“y”键关闭或打开q行态进E的加亮效果?/p>

2. 敲击键盘“x”Q打开/关闭排序列的加亮效果Q,top的视囑֏化如下:

top视图 04

top视图 04

可以看到Qtop默认的排序列?#8220;%CPU”?/p>

3. 通过”shift + >”?#8221;shift + <”可以向右或左改变排序列,下图是按一?#8221;shift + >”的效果图Q?/p>

top视图 05

top视图 05

视图现在已经按照%MEM来排序了?/p>

改变q程昄字段

1. 敲击“f”键,topq入另一个视图,在这里可以编排基本视图中的显C字D:

top视图 06

top视图 06

q里列出了所有可在top基本视图中显C的q程字段Q有”*”q且标注为大写字母的字段是可昄的,没有”*”q且是小写字母的字段是不昄的。如果要在基本视图中昄“CODE”?#8220;DATA”两个字段Q可以通过敲击“r”?#8220;s”键:

top视图 07

top视图 07

2. “回R”q回基本视图Q可以看到多?#8220;CODE”?#8220;DATA”两个字段Q?/p>

top视图 08

top视图 08

top命o的补?/strong>

top 命o是Linux上进行系l监控的首选命令,但有时候却达不到我们的要求Q比如当前这台服务器Qtop监控有很大的局限性。这台服务器q行着 websphere集群Q有两个节点服务Q就是【top视图 01】中的老大、老二两个javaq程Qtop命o的监控最单位是q程Q所以看不到我关心的javaU程数和客户q接敎ͼ而这两个指标是java?web服务非常重要的指标,通常我用ps和netstate两个命o来补充top的不?/p>

监控javaU程敎ͼ
ps -eLf | grep java | wc -l

监控|络客户q接敎ͼ
netstat -n | grep tcp | grep 侦听端口 | wc -l

上面两个命oQ可改动grep的参敎ͼ来达到更l致的监控要求?/p>

?Linuxpȝ“一切都是文?#8221;的思想贯彻指导下,所有进E的q行状态都可以用文件来获取。系l根目录/proc中,每一个数字子目录的名字都是运行中?q程的PIDQ进入Q一个进E目录,可通过其中文g或目录来观察q程的各运行指标,例如task目录是用来描述q程中线E的Q因此也可以通过下面的方 法获取某q程中运行中的线E数量(PID指的是进EIDQ:

ls /proc/PID/task | wc -l

在linux中还有一个命令pmapQ来输出q程内存的状况,可以用来分析U程堆栈Q?/p>

pmap PID



多彩人生 2013-07-13 11:30 发表评论
]]>
centos 6.2 apache安装http://www.shnenglu.com/colorful/archive/2013/07/11/201703.html多彩人生多彩人生Thu, 11 Jul 2013 11:03:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/11/201703.htmlhttp://www.shnenglu.com/colorful/comments/201703.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/11/201703.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/201703.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/201703.htmlApache2的是作ؓ(f)一个CentOS的Y件包Q因此我们可以直接用下面命o安装它:

    yum install httpd

  现在配置pȝ在引导时启动Apache

    chkconfig --levels 235 httpd on

  q启动Apache

    /etc/init.d/httpd start

  现在Q?zhn)的浏览器到httpQ?/192.168.0.100Q你应该看到Apache2的测试页Q?/p>

  Apache的默认文档根目录是在CentOS上的/var/www/html 目录 Q配|文件是/etc/httpd/conf/httpd.conf。配|存储在?etc/httpd/conf.d/目录?/div>

多彩人生 2013-07-11 19:03 发表评论
]]> linux查看目录大小 http://www.shnenglu.com/colorful/archive/2013/07/11/201702.html多彩人生多彩人生Thu, 11 Jul 2013 10:48:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/11/201702.htmlhttp://www.shnenglu.com/colorful/comments/201702.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/11/201702.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/201702.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/201702.html
可以使用Q?br />[tuest@demoserver ~]$ du --max-depth 1 /tmp  -h
4.0K    /tmp/.X11-unix
4.0K    /tmp/.ICE-unix
4.0K    /tmp/.font-unix
5.9M    /tmp


可以看到目录下所有文件夹的内容大?br />
如果只想看一个目录的大小可以使用Q?br />
[tuest@demoserver ~]$ du /tmp -sh
5.9M    /tmp


多彩人生 2013-07-11 18:48 发表评论
]]>
Linux 中如何卸载已安装的Y?http://www.shnenglu.com/colorful/archive/2013/07/11/201701.html多彩人生多彩人生Thu, 11 Jul 2013 10:43:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/11/201701.htmlhttp://www.shnenglu.com/colorful/comments/201701.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/11/201701.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/201701.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/201701.html
Linux 中如何卸载已安装的Y?
  Linux软g的安装和卸蝲一直是困扰许多新用L(fng)N。在 Windows中,我们可以使用软g自带的安装卸载程序或在控刉板中?#8220;d/删除E序”来实现。与其相cMQ在Linux下有一个功能强大的软g安装 卸蝲工具Q名为RPM。它可以用来建立、安装、查询、更新、卸载Y件。该工具是在命o行下使用的。在Shell的提C符后输入rpmQ就可获得该命o的帮 助信息?br />

  软g的安?/strong>

  Linux下Y件的安装主要有两U不同的形式。第一U安装文件名为xxx.tar.gzQ另一U安装文件名为xxx.i386.rpm。以W一U方式发行的软g多ؓ(f)以源码Ş式发送的Q第二种方式则是直接以二q制形式发送的?/p>

  对于W一U,安装Ҏ(gu)如下Q?/p>

  1 .首先Q将安装文g拯至你的目录中。例如,如果你是以rootw䆾d上的Q就Y件拷贝至/root中?/p>

  #cp xxx.tar.gz /root

  2 .׃该文件是被压~ƈ打包?应对其解压羃。命令ؓ(f)Q?/p>

  #tar xvzf filename.tar.gz 如果是filename.tar.bz2格式的,应该是tar jxvf filename.tar.bz2来解?/p>

  3. 执行该命令后Q安装文件按路径Q解压羃在当前目录下。用ls命o可以看到解压~后的文件。通常在解压羃后生的文g中,?#8220;Install”的文件。该文g为纯文本文gQ详l讲qC该Y件包的安装方法?/p>

  4.执行解压~后产生的一个名为configure的可执行脚本E序。它是用于检查系l是否有~译时所需的库Q以及库的版本是否满编译的需要等安装所需要的pȝ信息。ؓ(f)随后的编译工作做准备。命令ؓ(f)Q?#./configure

  如果(zhn)想把Y件安装到指定目录Q应该用#./configure --prefix=/(zhn)自己指定的目录Q比如我x一个mlterm安装?opt/mlterm目录中,应该如下输入

  #./configure --prefix=/opt/mlterm

  5.查通过后,生成用于编译的MakeFile文g。此Ӟ可以开始进行编译了。编译的q程视Y件的规模和计机性能的不同,所耗费的时间也不同。命令ؓ(f)Q?#make?/p>

  6.成功~译后,键入如下的命令开始安装:

  #make install

  7.安装完毕Q应清除~译q程中生的临时文g和配|过E中产生的文件。键入如下命令:

  #make clean

  #make distclean

  xQY件的安装l束?/p>

  对于W二U,其安装方法要单得多?/p>

  同第一U方式一P安装文件拷贝至你的目录中。然后用rpm来安装该文g。命令如下:

  #rpm -i filename.i386.rpm

  rpm自动将安装文g解包QƈY件安装到~省的目录下。ƈY件的安装信息注册到rpm的数据库中。参数i的作用是使rpmq入安装模式?/p>

  软g的卸?/strong>

  1.软g的卸载主要是使用rpm来进行的。卸载Y仉先要知道软g包在pȝ中注册的名称。键入命令:

  #rpm -q -a

  卛_查询到当前系l中安装的所有的软g包?/p>

  2. 定了要卸蝲的Y件的名称Q就可以开始实际卸载该软g了。键入命令:

  #rpm -e [package name]

  卛_卸蝲软g。参数e的作用是使rpmq入卸蝲模式。对名ؓ(f)[package name]的Y件包q行卸蝲。由于系l中各个软g包之间相互有依赖关系。如果因存在依赖关系而不能卸载,rpm给予提Cƈ停止卸蝲。你可以使用如下的命令来忽略依赖关系Q直接开始卸载:

  #rpm -e [package name] -nodeps

  忽略依赖关系的卸载可能会Dpȝ中其它的一些Y件无法?/p>

  如果想知道rpm包安装到哪里了呢Q?/p>

  应该?#rpm -ql [package name]

  3.如何卸蝲用源码包安装的YӞ

  最好是看README和INSTALL Q一般的情况下都有说Q但大多软g没有提供源码包的卸蝲Ҏ(gu)Q我们可以找到Y件的安装点删除。主要看你把它安装在哪了?/p>

  比如Q?/p>

  如果安装软gӞ指定个目录。这个问题也不会难;

  比如用源码包安装gaim ?/p>

  #./configure --prefix=/opt/gaim

  #make

  #make install

  如果安装mlterm

  #./configure --prefix=/opt/mlterm

  #make

  #make install

  把源码包安装的YӞ都指定安装在 /opt目录中,q样不就知道了;

  如果删除Q就删除相应的Y件目录;

  有些软g要在解压安装目录中执?make uninstall Q这样就卸蝲掉了?/p>



多彩人生 2013-07-11 18:43 发表评论
]]>
crontab防止脚本周期内未执行完重复执?/title><link>http://www.shnenglu.com/colorful/archive/2013/07/06/201568.html</link><dc:creator>多彩人生</dc:creator><author>多彩人生</author><pubDate>Sat, 06 Jul 2013 08:59:00 GMT</pubDate><guid>http://www.shnenglu.com/colorful/archive/2013/07/06/201568.html</guid><wfw:comment>http://www.shnenglu.com/colorful/comments/201568.html</wfw:comment><comments>http://www.shnenglu.com/colorful/archive/2013/07/06/201568.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/colorful/comments/commentRss/201568.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/colorful/services/trackbacks/201568.html</trackback:ping><description><![CDATA[个h体会: flock -xn my.lock commond<br />my.lock是一个文Ӟ应该可以是Q意文Ӟ可以新徏一个空文g<br />当flock 获得锁后׃执行后面?commond<br />试q程: $1: flock -xn my.lock sleep 20<br />              $2: flock -xn my.lock ls<br />只有?q回后, 2的ls才会成功<br /><br /><div><h2>crontab防止脚本周期内未执行完重复执?/h2> <p>如果某脚本要q行30分钟Q可以在Crontab里把脚本间隔设ؓ(f)臛_一时来避免冲H。而比较糟的情冉|可能该脚本在执行周期内没有完成,接着W?二个脚本又开始运行了。如何确保只有一个脚本实例运行呢Q一个好用的Ҏ(gu)是利用lockfQFreeBSD 8.1下ؓ(f)lockfQCentOS  5.5下ؓ(f)flockQ,在脚本执行前先检能否获取某个文仉Q以防止脚本q行冲突?/p><p>lockf的参数如下?/p><p>-kQ一直等待获取文仉?/p><p>-sQsilentQ不发出M信息Q即使拿不到文g锁?/p><p>-t secondsQ设定timeout的时间是secondsU,如果过旉Q则自动攑ּ?/p><p>以下Crontab计划d执行前,需获取临时文gcreate.lock的文仉Q此Crontab计划d的内容如下:</p><div><div class="6161611" id="highlighter_560612" bash"=""><table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td><div number1="" index0="" alt2"="">1</div></td><td><div><div number1="" index0="" alt2"=""><code plain"="">*</code><code plain"="">/10</code> <code plain"="">* * * * (lockf -s -t 0 </code><code plain"="">/tmp/create</code><code plain"="">.lock </code><code plain"="">/usr/bin/python</code> <code plain"="">/home/project/cron/create_tab</code><code plain"="">.py  >> </code><code plain"="">/home/project/logs/create</code><code plain"="">.log 2>&1)</code></div></div></td></tr></tbody></table></div></div><p><br /></p><p>若第一个实例在10分钟内没有运行完Q第2个实例不会运行。我以前是通过Shell脚本来解册个问题的Q比如用while...do循环Q然后放在后台执行。但后来发现其实用flock或lockfҎ(gu)更ؓ(f)单?/p><p><br /></p><p>附上linux下的flock的用法:</p><div><div class="6616661" id="highlighter_710880" cpp"=""><table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td><div number1="" index0="" alt2"="">1</div><div number2="" index1="" alt1"="">2</div><div number3="" index2="" alt2"="">3</div><div number4="" index3="" alt1"="">4</div><div number5="" index4="" alt2"="">5</div><div number6="" index5="" alt1"="">6</div><div number7="" index6="" alt2"="">7</div><div number8="" index7="" alt1"="">8</div><div number9="" index8="" alt2"="">9</div><div number10="" index9="" alt1"="">10</div><div number11="" index10="" alt2"="">11</div><div number12="" index11="" alt1"="">12</div><div number13="" index12="" alt2"="">13</div><div number14="" index13="" alt1"="">14</div><div number15="" index14="" alt2"="">15</div><div number16="" index15="" alt1"="">16</div><div number17="" index16="" alt2"="">17</div></td><td><div><div number1="" index0="" alt2"=""><code plain"="">flock (util-linux 2.13-pre7)</code></div><div number2="" index1="" alt1"=""><code plain"="">Usage: flock [-sxun][-w #] fd#</code></div><div number3="" index2="" alt2"=""><code spaces"="">       </code><code plain"="">flock [-sxon][-w #] file [-c] command...</code></div><div number4="" index3="" alt1"=""><code spaces"="">  </code><code plain"="">-s  --shared     Get a shared lock </code></div><div number5="" index4="" alt2"=""><code preprocessor"="">#׃n?在定向ؓ(f)某文件的FD上设|共享锁而未释放锁的旉?其他q程试图在定向ؓ(f)此文件的FD上设|独占锁的请求失?而其他进E试囑֜定向为此文g的FD上设|共享锁的请求会成功</code></div><div number6="" index5="" alt1"=""><code spaces"="">  </code><code plain"="">-x  --exclusive  Get an exclusive lock </code></div><div number7="" index6="" alt2"=""><code preprocessor"="">#独占或排他锁,在定向ؓ(f)某文件的FD上设|独占锁而未释放锁的旉?其他q程试图在定向ؓ(f)此文件的FD上设|共享锁或独占锁都会p|。只要未讄-s参数,此参数默认被讄</code></div><div number8="" index7="" alt1"=""><code spaces"="">  </code><code plain"="">-u  --unlock     Remove a lock </code></div><div number9="" index8="" alt2"=""><code preprocessor"="">#手动解锁,一般情况不必须,当FD关闭?pȝ会自动解?此参数用于脚本命令一部分需要异步执?一部分可以同步执行的情?/code></div><div number10="" index9="" alt1"=""><code spaces"="">  </code><code plain"="">-n  --nonblock   Fail rather than wait </code></div><div number11="" index10="" alt2"=""><code preprocessor"="">#为非d模式,当试图设|锁p|,采用非阻塞模?直接q回1,</code></div><div number12="" index11="" alt1"=""><code spaces"="">  </code><code plain"="">-w  --timeout    Wait </code><code keyword="" bold"="">for</code> <code plain"="">a limited amount of </code><code functions="" bold"="">time</code></div><div number13="" index12="" alt2"=""><code preprocessor"="">#讄d时,当超q设|的U数,p出阻?q回1</code></div><div number14="" index13="" alt1"=""><code spaces"="">  </code><code plain"="">-o  --close      Close file descriptor before running command</code></div><div number15="" index14="" alt2"=""><code spaces"="">  </code><code plain"="">-c  --command    Run a single command string through the shell 执行其后的comand</code></div><div number16="" index15="" alt1"=""><code spaces"="">  </code><code plain"="">-h  --help       Display </code><code keyword="" bold"="">this</code> <code plain"="">text</code></div><div number17="" index16="" alt2"=""><code spaces"="">  </code><code plain"="">-V  --version    Display version</code></div></div></td></tr></tbody></table></div></div><p>举个例子执行如下脚本Q?/p><p>每天23:30的时候执行一个脚本,但是执行前必要获得排他文g锁,否则无法执行命o<br /></p><table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td><div number1="" index0="" alt2"="">1</div></td><td><div><div number1="" index0="" alt2"=""><code plain"="">30 23 * * * flock -xn </code><code plain"="">/tmp/test</code><code plain"="">.lock -c </code><code string"="">'/usr/local/php test.php'</code></div></div></td></tr></tbody></table></div><img src ="http://www.shnenglu.com/colorful/aggbug/201568.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/colorful/" target="_blank">多彩人生</a> 2013-07-06 16:59 <a href="http://www.shnenglu.com/colorful/archive/2013/07/06/201568.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>shell中if做比?/title><link>http://www.shnenglu.com/colorful/archive/2013/07/06/201566.html</link><dc:creator>多彩人生</dc:creator><author>多彩人生</author><pubDate>Sat, 06 Jul 2013 08:28:00 GMT</pubDate><guid>http://www.shnenglu.com/colorful/archive/2013/07/06/201566.html</guid><wfw:comment>http://www.shnenglu.com/colorful/comments/201566.html</wfw:comment><comments>http://www.shnenglu.com/colorful/archive/2013/07/06/201566.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/colorful/comments/commentRss/201566.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/colorful/services/trackbacks/201566.html</trackback:ping><description><![CDATA[<div><h2> <a id="cb_post_title_url" >shell中if做比?/a> </h2> <p>比较两个字符串是否相{的办法是:</p> <p>    if [ "$test"x = "test"x ]; then</p> <p>    q里的关键有几点Q?/p> <p>    1 使用单个{号</p> <p>    2 注意到等号两边各有一个空|q是unix shell的要?/p> <p>    3 注意?$test"x最后的xQ这是特意安排的Q因为当$test为空的时候,上面的表辑ּ变成了x = testxQ显然是不相{的。而如果没有这个xQ表辑ּ׃报错Q[: =: unary operator expected</p> <p>    </p> <p>    二元比较操作W?比较变量或者比较数?注意数字与字W串的区?</p> <p>    整数比较</p> <p>    -eq {于,?if [ "$a" -eq "$b" ]</p> <p>    -ne 不等??if [ "$a" -ne "$b" ]</p> <p>    -gt 大于,?if [ "$a" -gt "$b" ]</p> <p>    -ge 大于{于,?if [ "$a" -ge "$b" ]</p> <p>    -lt 于,?if [ "$a" -lt "$b" ]</p> <p>    -le 于{于,?if [ "$a" -le "$b" ]</p> <p>     大于(需要双括号),?(("$a" > "$b"))</p> <p>    >= 大于{于(需要双括号),?(("$a" >= "$b"))</p> <p>    数据比较可使用AWK</p> <p>    字符串比?/p> <p>    = {于,?if [ "$a" = "$b" ]</p> <p>    == {于,?if [ "$a" == "$b" ],?{h(hun)</p> <p>     注意:==的功能在[[]]和[]中的行ؓ(f)是不同的,如下:</p> <p>     1 [[ $a == z* ]] # 如果$a?z"开?模式匚w)那么ؓ(f)true</p> <p>     2 [[ $a == "z*" ]] # 如果$a{于z*(字符匚w),那么l果为true</p> <p>     3</p> <p>     4 [ $a == z* ] # File globbing 和word splitting会发生</p> <p>     5 [ "$a" == "z*" ] # 如果$a{于z*(字符匚w),那么l果为true</p> <p>     一点解?关于File globbing是一U关于文件的速记?比如"*.c"是,再如~也是.</p> <p>     但是file globbingq不是严格的正则表达?虽然l大多数情况下结构比较像.</p> <p>    != 不等??if [ "$a" != "$b" ]</p> <p>     q个操作W将在[[]]l构中用模式匹?</p> <p>     大于,在ASCII字母序??</p> <p>     if [[ "$a" > "$b" ]]</p> <p>     if [ "$a" \> "$b" ]</p> <p>     注意:在[]l构?>"需要被转义.</p> <p>     具体参考Example 26-11来查看这个操作符应用的例?</p> <p>    -z 字符串ؓ(f)"null".是长度?.</p> <p>    -n 字符串不?null"</p> <p>     <span style="color: #ff0000;">注意: </span></p> <p><span style="color: #ff0000;">     使用-n在[]l构中测试必要?"把变量引h.使用一个未?"的字W串来? -z </span></p> <p><span style="color: #ff0000;">     或者就是未?"引用的字W串本n,攑ֈ[]l构中。虽然一般情况下?</span></p> <p><span style="color: #ff0000;">     以工?但这是不安全??fn)惯于?"来测试字W串是一U好?fn)?</span></p> <p><span style="color: #ff0000;">if判断?br />if [ 条g判断一 ] && (||) [ 条g判断?]; then<br />elif [ 条g判断?] && (||) [ 条g判断?]; then<br />else<br />    执行W三D內容程?br />fi </span></p> <p><span style="color: #ff0000;">例如Q?/span></p> <p> </p> <pre mb10"="">root@Bizbox:~# a=0 root@Bizbox:~# b=0 root@Bizbox:~# c=5 root@Bizbox:~# if [ $a = 0 -a $b = 0 ]&&[ $c != 0 ]; then > echo success > fi success</pre> <p><span style="color: #ff0000;">if 使用的表辑ּ</span></p> <div>Primary 意义<br />[ -a 文g ] 如果文g存在为真?br />[ -b 文g ] 如果 文g 存在 而且 是一??Ҏ(gu) 文g为真?br />[ -c 文g ] 为真 如果 文g 存在 而且 是一??Ҏ(gu) 文g?/div> <p> </p> <div>[ -d 文g ] 为真 如果 文g 存在 而且 是一?目录?br />[ -e 文g ] 为真 如果 文g 存在?br />[ -f 文g ] 为真 如果 文g 存在 而且 是一?普?文g?br />[ -g 文g ] 为真 如果 文g 存在 而且 已经讄了他?SGID 位?br />[ -h 文g ] 为真 如果 文g 存在 而且 是一?W号q接?br />[ -k 文g ] 为真 如果 文g 存在 而且 他的_住位已l设|?br />[ -p 文g ] 为真 如果 文g 存在 而且 是一?已经命名的管?(F 如果O)?br />[ -r 文g ] 为真 如果 文g 存在 而且 是可ȝ?br />[ -s 文g ] 为真 如果 文g 存在 而且 比零字节大?br />[ -t FD ] 为真 如果 文g 文g描述W已l打开 而且 指向一个终端?br />[ -u 文g ] 为真 如果 文g 存在 而且 已经讄了他?SUID (set user ID)位?br />[ -w 文g ] 为真 如果 文g 为真 如果 文g 存在 而且 是可写的?br />[ -x 文g ] 为真 如果 文g 存在 而且 是可执行的?br />[ -O 文g ] 为真 如果 文g 存在 而且 属于有效用户ID?br />[ -G 文g ] 为真 如果 文g 存在 而且 属于有效lID?br />[ -L 文g ] 为真 如果 文g 存在 而且 是一?W号q接?br />[ -N 文g ] 为真 如果 文g 存在 而且 has been mod 如果ied since it was last read?br />[ -S 文g ] 为真 如果 文g 存在 而且 是一?socket?br />[ 文g1 -nt 文g2 ] 为真 如果 文g1 has been changed more recently than 文g2, or 如果<br />文g1 存在 而且<br />文g2 does not?br />[ 文g1 -ot 文g2 ] 为真 如果 文g1 ?文g2 ? 或?文g2 存在而且 文g1 不存在?br />[ 文g1 -ef 文g2 ] 为真 如果 文g1 而且 文g2 refer to the same device 而且 inode<br />numbers?br />[ -o 选项?] 为真 如果 shell 选项 "选项? 开启?br />[ -z STRING ] 为真 如果 "STRING"的长度是零?br />[ -n STRING ] 或?[ STRING ] 为真 "STRING"的长度是非零倹{?br />[ STRING1 == STRING2 ] 如果两个字符串相{ؓ(f)真?"=" may be used instead of "==" for<br />strict POSIX compliance?br />[ STRING1 != STRING2 ] 为真 如果 两两个字W串不相{?br />[ STRING1 < STRING2 ] 为真 如果 "STRING1" sorts before "STRING2" lexicographically in the<br />current locale?br />[ STRING1 > STRING2 ] 为真 如果 "STRING1" sorts after "STRING2" lexicographically in the<br />current locale?br />[ ARG1 OP ARG2 ]<br />"OP" ?-eq, -ne, -lt, -le, -gt or -ge 其中一个?These arithmetic binary operators<br />return 为真 如果 "ARG1" is equal to, not equal to, less than, less than or equal to, greater<br />than, or greater than or equal to "ARG2", respectively?"ARG1" 而且 "ARG2" are<br />integers?br />表达式可以借以下操作符l合h, listed in decreasing order of precedence:<br />操作W效?br />[ ! EXPR ] 如果EXPR 为假则ؓ(f)真?br />[ ( EXPR ) ] q回EXPR 的倹{?q样可以用来忽略正常的操作符优先U?/div></div><img src ="http://www.shnenglu.com/colorful/aggbug/201566.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/colorful/" target="_blank">多彩人生</a> 2013-07-06 16:28 <a href="http://www.shnenglu.com/colorful/archive/2013/07/06/201566.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux 删除所有后~名相同的文ghttp://www.shnenglu.com/colorful/archive/2013/07/06/201565.html多彩人生多彩人生Sat, 06 Jul 2013 08:15:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/06/201565.htmlhttp://www.shnenglu.com/colorful/comments/201565.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/06/201565.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/201565.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/201565.html
Ҏ(gu)一:
find 目录 -name "*.abc" | xargs rm
命o很危? 你先执行前半D试试看 是不是你要删除的文g, 在整条执?br />
Ҏ(gu)?
find . -name '*.exe' -type f -print -exec rm -rf {} \;
(1) "."    表示从当前目录开始递归查找
(2) “ -name '*.exe' "Ҏ(gu)名称来查找,要查找所有以.exel尾的文件夹或者文?br />(3) " -type f "查找的类型ؓ(f)文g
(4) "-print" 输出查找的文件目录名
(5) 最主要的是?exec了,-exec选项后边跟着一个所要执行的命oQ表C将find出来的文件或目录执行该命令?br />     exec选项后面跟随着所要执行的命o或脚本,然后是一对儿{}Q一个空格和一个\Q最后是一个分?br />
-----------------------------------------------------------

find: paths must precede expression Usage: find [-H] [-L] [-P] [path...] [expression]

今天在跑脚本的时候看到如下报错:

find: paths must precede expression
Usage: find [-H] [-L] [-P] [path...] [expression]

然后׃|查了一下,l果搜烦C,大概是这栯的:多文件的查找的时候需要增加单引号

而我之前一直都是用的双引号Q也没有遇到问题Q这ơ却报错了~

ssh $ip "cd $path;find . -name'access.$month*.log' -print -exec zip -r access.$month.zip {} \;"

修改?span style="background-color:#ffff99">单引?/span>后,木有再见报错~

例子说明Q?/span>

  1. # q入tmp目录新徏4个文本文?nbsp; 
  2. # cd /tmp  
  3. # touch {1,2,3,4}.txt  
  4. # find . -name *.txt  
  5. find: paths must precede expression: 2.txt  

出现q个提示是因为星可展开为当前目录下所有的文gQ这L(fng)匚w当然会出错。看q个q道了Q?/span>

  1. # echo *  
  2. 1.txt 2.txt 3.txt 4.txt  
  3. # echo '*'  
  4. *  
  5. # echo \*  
  6. *  

惌星号不被展开需要加?span style="background-color:#ccffff">括号或者反斜杠转义Q知道了q些我们q道该怎么find?/span>

  1. # find . -name '*.txt'  
  2. find . -name '*.txt'  
  3. ./4.txt  
  4. ./2.txt  
  5. ./3.txt  
  6. ./1.txt  
  7. #或者用反斜杠  
  8.  find . -name \*.txt  
  9. ./4.txt  
  10. ./2.txt  
  11. ./3.txt  
  12. ./1.txt 



多彩人生 2013-07-06 16:15 发表评论
]]>
How to rename a file in Linuxhttp://www.shnenglu.com/colorful/archive/2013/07/06/201563.html多彩人生多彩人生Sat, 06 Jul 2013 07:49:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/06/201563.htmlhttp://www.shnenglu.com/colorful/comments/201563.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/06/201563.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/201563.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/201563.html//Z?rename 不行

mv command renames the file named by the source operand to the destination path named by the target operand. mv command syntax:

Code:
mv {old-file-name {new-file-name} mv {old-dir-name} {new-dir-name}
Rename a file tom.txt to jerry.txt, type:
Code:
mv tom.txt jerry.txt
Rename a directory lgitech to logitech, enter:
Code:
mv lgitech logitech


多彩人生 2013-07-06 15:49 发表评论
]]>
q程守护脚本Q?如果已运行则不运?/title><link>http://www.shnenglu.com/colorful/archive/2013/07/06/201561.html</link><dc:creator>多彩人生</dc:creator><author>多彩人生</author><pubDate>Sat, 06 Jul 2013 07:36:00 GMT</pubDate><guid>http://www.shnenglu.com/colorful/archive/2013/07/06/201561.html</guid><wfw:comment>http://www.shnenglu.com/colorful/comments/201561.html</wfw:comment><comments>http://www.shnenglu.com/colorful/archive/2013/07/06/201561.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/colorful/comments/commentRss/201561.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/colorful/services/trackbacks/201561.html</trackback:ping><description><![CDATA[<div>processExist=`ps aux|grep processName|grep -v "grep" `   // 注意q是Esc下面那个`<br /> if [ -z "$processExist" ];then<br />     exec processName<br /> else<br />     echo "process is running"<br /> fi </div><img src ="http://www.shnenglu.com/colorful/aggbug/201561.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/colorful/" target="_blank">多彩人生</a> 2013-07-06 15:36 <a href="http://www.shnenglu.com/colorful/archive/2013/07/06/201561.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>定时自动启动dcrontab命o用法http://www.shnenglu.com/colorful/archive/2013/07/06/201560.html多彩人生多彩人生Sat, 06 Jul 2013 07:31:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/06/201560.htmlhttp://www.shnenglu.com/colorful/comments/201560.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/06/201560.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/201560.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/201560.html

http://www.centos.bz/2011/03/auto-run-task-crontab/

每个操作pȝ都有它的自动定时启动E序的功能,Windows有它的Q务计划,?a title="Linux" >Linux对应的功能是crontab?/p>

crontab?/h3>

crontab命o常见于Unix和类Unix的操作系l之中,用于讄周期性被执行的指令。该命o从标准输入设备读取指令,q将其存放于 “crontab”文g中,以供之后d和执行。该词来源于希腊? chronos(χρόνος)Q原意是旉。  通常Qcrontab储存的指令被守护q程Ȁz, crond常常在后台运行,每一分钟查是否有预定的作业需要执行。这cM业一般称为cron jobs?/p>

crontab用法

crontab的格式如下面Q?/p>

f1 f2 f3 f4 f5 program

其中 f1 是表C分钟,f2 表示时Qf3 表示一个月份中的第几日Qf4 表示月䆾Qf5 表示一个星期中的第几天。program 表示要执行程式的路径?/p>

  • ?f1 ?* 时表C每分钟都要执行 programQf2 ?* 时表C每时都要执行E式Q其余类?/li>
  • ?f1 ?a-b 时表CZW?a 分钟到第 b 分钟q段旉内要执行Qf2 ?a-b 时表CZW?a 到第 b 时都要执行Q其余类?/li>
  • ?f1 ?*/n 时表C每 n 分钟个时间间隔执行一ơ,f2 ?*/n 表示?n 时个时间间隔执行一ơ,其余cL
  • ?f1 ?a, b, c,... 时表C第 a, b, c,... 分钟要执行,f2 ?a, b, c,... 时表C第 a, b, c...个小时要执行Q其余类?/li>

理员登录SSH,输入命ocrontab -e~辑crontab文gQ根据上面的格式输入q保存?/p>

crontab例子

每月每天每小时的W?0 分钟执行一?/bin/ls :

  1. 0 * * * * /bin/ls

?12 月内, 每天的早?6 点到 12 点中Q每?20 分钟执行一?/usr/bin/backup :

  1. */20 6-12 * 12 * /usr/bin/backup

周一到周五每天下?5:00 寄一信l?alex@domain.name :

  1. 0 17 * * 1-5 mail -s "hi" alex@domain.name &lt; /tmp/maildata

每月每天的午?0 ?20 ? 2 ?20 ? 4 ?20 ?...执行 echo "haha"

  1. 20 0-23/2 * * * echo "haha"

晚上11点到早上8点之间每两个时Q早??/p>

  1. 0 23-7/2Q? * * * date

在hp unix,中,?0分钟执行一ơ,表示为:0,20,40 * * * * 而不能采?/n方式Q否则出现语法错?/p>

crontab用法其实很容易掌握,懂得使用crontabQ对|站和服务器l护起到很大的帮助,比如定时备䆾Q定时优化服务器{?/p>

多彩人生 2013-07-06 15:31 发表评论
]]>
Linux静态库和动态库http://www.shnenglu.com/colorful/archive/2013/07/01/201427.html多彩人生多彩人生Mon, 01 Jul 2013 09:59:00 GMThttp://www.shnenglu.com/colorful/archive/2013/07/01/201427.htmlhttp://www.shnenglu.com/colorful/comments/201427.htmlhttp://www.shnenglu.com/colorful/archive/2013/07/01/201427.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/201427.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/201427.html

库从本质上来说是一U可执行代码的二q制格式Q可以被载入内存中执行。库分静态库和动态库两种?nbsp;

静态库和动态库的区?/h1>

1. 静态函数库

    q类库的名字一般是libxxx.aQ利用静态函数库~译成的文g比较大,因ؓ(f)整个 函数库的所有数据都会被整合q目标代码中Q他的优点就显而易见了Q即~译后的执行E序不需要外部的函数库支持,因ؓ(f)所有用的函数都已l被~译q去了。当 然这也会成ؓ(f)他的~点Q因为如果静态函数库改变了,那么你的E序必须重新~译?

2. 动态函数库

    q类库的名字一般是libxxx.so;相对于静态函数库Q动态函数库在编译的时? q没有被~译q目标代码中Q你的程序执行到相关函数时才调用该函数库里的相应函数Q因此动态函数库所产生的可执行文g比较?yu)。由于函数库没有被整合进你的 E序Q而是E序q行时动态的甌q调用,所以程序的q行环境中必L供相应的库。动态函数库的改变ƈ不媄响你的程序,所以动态函数库的升U比较方ѝ?
linuxpȝ有几个重要的目录存放相应的函数库Q如/lib /usr/lib?

静态库的?/h1>

静态库的操作工Pgcc和ar 命o?nbsp;

~写及用静态库 

(1)设计库源?pr1.c ?pr2.c 

[root@billstone make_lib]# cat pr1.c 

void print1() 

                printf("This is the first lib src!\n"); 

[root@billstone make_lib]# cat pr2.c 

void print2() 

                printf("This is the second src lib!\n"); 

       (2)  ~译.c 文g 

[bill@billstone make_lib]$ cc -O -c pr1.c pr2.c 

[bill@billstone make_lib]$ ls -l pr*.o 

-rw-rw-r--        1 bill          bill                    804    4 ?nbsp; 15 11:11 pr1.o 

-rw-rw-r--        1 bill          bill                    804    4 ?nbsp; 15 11:11 pr2.o 

(3)  链接静态库 

    Z在编译程序中正确扑ֈ库文?静态库必须按照 lib[name].a 的规则命?如下例中[name]=pr. 

[bill@billstone make_lib]$ ar -rsv libpr.a pr1.o pr2.o 

a - pr1.o 

a - pr2.o 

[bill@billstone make_lib]$ ls -l *.a 

-rw-rw-r--        1 bill          bill                  1822    4 ?nbsp; 15 11:12 libpr.a 

[bill@billstone make_lib]$ ar -t libpr.a 

pr1.o 

pr2.o 

(4)  调用库函C?main.c 

[bill@billstone make_lib]$ cat main.c 

int main() 

                print1(); 

                print2(); 

                return 0; 

(5)  ~译链接选项 

    -L ?l 参数攑֜后面.其中,-L 加蝲库文件\?-l 指明库文件名? 

[bill@billstone make_lib]$ gcc -o main main.c -L./ -lpr 

[bill@billstone make_lib]$ ls -l main* 

-rwxrwxr-x        1 bill          bill                11805    4 ?nbsp; 15 11:17 main 

-rw-rw-r--        1 bill          bill                      50    4 ?nbsp; 15 11:15 main.c 

(6)执行目标E序 

[bill@billstone make_lib]$ ./main 

This is the first lib src! 

This is the second src lib! 

[bill@billstone make_lib]$ 

动态库的?/h1>

~写动态库 

(1)设计库代?/strong> 

[bill@billstone make_lib]$ cat pr1.c 

int p = 2; 

void print(){ 

                printf("This is the first dll src!\n"); 

[bill@billstone make_lib]$   

(2)生成动态库 

[bill@billstone make_lib]$ gcc -O -fpic -shared -o dl.so pr1.c 

[bill@billstone make_lib]$ ls -l *.so 

-rwxrwxr-x        1 bill          bill                  6592    4 ?nbsp; 15 15:19 dl.so 

[bill@billstone make_lib]$ 

动态库的隐式调?/strong> 

  在编译调用库函数代码时指明动态库的位|及名字,  看下面实?nbsp;

[bill@billstone make_lib]$ cat main.c 

int main() 

                print(); 

                return 0; 

[bill@billstone make_lib]$ gcc -o tdl main.c ./dl.so 

[bill@billstone make_lib]$ ./tdl 

This is the first dll src! 

[bill@billstone make_lib]$ 

当动态库的位|活名字发生改变?  E序无法正常运?  而动态库取代静态库的好处之一则是通过更新动态库而随时升U库的内? 

动态库的显式调?/strong> 

  昑ּ调用动态库需要四个函数的支持,  函数 dlopen 打开动态库,  函数 dlsym 获取动态库中对象基址,  ?/strong>?dlerror 获取昑ּ动态库操作中的错误信息,  函数 doclose 关闭动态库.

[bill@billstone make_lib]$ cat main.c 

#include <dlfcn.h> 

int main() 

                void *pHandle; 

                void (*pFunc)();                                                    //  指向函数的指?nbsp;

                int *p; 

                pHandle = dlopen("./d1.so", RTLD_NOW);                  //  打开动态库 

                if(!pHandle){ 

                                printf("Can't find d1.so \n"); 

                                exit(1); 

                } 

                pFunc = (void (*)())dlsym(pHandle, "print");                //  获取库函?print 的地址 

                if(pFunc) 

                                pFunc(); 

                else 

                                printf("Can't find function print\n"); 

                p = (int *)dlsym(pHandle, "p");                                      //  获取库变?p 的地址 

                if(p) 

                                printf("p = %d\n", *p); 

                else 

                                printf("Can't find int p\n"); 

                dlclose(pHandle);                                                                //  关闭动态库 

                return 0; 

[bill@billstone make_lib]$ gcc -o tds main.c –ld1 –L.

?时还不能立即./tdsQ因为在动态函数库使用Ӟ会查?usr/lib?lib目录下的动态函数库Q而此时我们生成的库不在里辏V? q个时候有好几U方法可以让他成功运行: 最直接最单的Ҏ(gu)是把libstr_out.so拉到/usr/lib?lib中去?q有一U方? export LD_LIBRARY_PATH=$(pwd) 另外q可以在/etc/ld.so.conf文g里加入我们生成的库的目录Q然?sbin/ldconfig? /etc/ld.so.conf是非帔R要的一个目录,里面存放的是链接器和加蝲器搜索共享库时要查的目录Q默认是?usr/lib /lib中读取的Q所以想要顺利运行,我们也可以把我们库的目录加入到这个文件中q执?sbin/ldconfig 。另外还有个文g需要了?etc/ld.so.cache,里面保存了常用的动态函数库Q且会先把他们加载到内存中,因ؓ(f)内存的访问速度q远大于盘?讉K速度Q这样可以提高Y件加载动态函数库的速度了?

库依赖的查看

使用ldd命o来查看执行文件依赖于哪些库?/p>

该命令用于判断某个可执行?binary 档案含有什么动态函式库?br />[root@test root]# ldd [-vdr] [filename]
参数说明Q?br />--version  打印l(f)dd的版本号
-v --verbose  打印所有信息,例如包括W号的版本信?br />-d --data-relocs  执行W号重部|Ԍq报告缺的目标对象Q只对ELF格式适用Q?br />-r --function-relocs  对目标对象和函数执行重新部vQƈ报告~少的目标对象和函数Q只对ELF格式适用Q?br />--help 用法信息?

如果命o行中l定的库名字包含'/'Q这个程序的libc5版本用它作ؓ(f)库名字;否则它将在标准位|搜索库。运行一个当前目录下的共享库Q加前缀"./"?/p>



多彩人生 2013-07-01 17:59 发表评论
]]>
shell脚本中局部变?/title><link>http://www.shnenglu.com/colorful/archive/2012/07/26/185148.html</link><dc:creator>多彩人生</dc:creator><author>多彩人生</author><pubDate>Thu, 26 Jul 2012 02:53:00 GMT</pubDate><guid>http://www.shnenglu.com/colorful/archive/2012/07/26/185148.html</guid><wfw:comment>http://www.shnenglu.com/colorful/comments/185148.html</wfw:comment><comments>http://www.shnenglu.com/colorful/archive/2012/07/26/185148.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/colorful/comments/commentRss/185148.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/colorful/services/trackbacks/185148.html</trackback:ping><description><![CDATA[<div><div class="1666161" id="sina_keyword_ad_area2" "=""> <p>在shell中定义函数可以代码模块化,便于复用代码。不q脚本本w的变量和函数的变量的作用域问题可能令你费解Q在q里梳理一下这个问题?br /> <br /> (1)Shell脚本中定义的变量是global的,其作用域从被定义的地方开始,到shelll束或被昄删除的地方ؓ(f)止?br /> <br /> ?Q脚本变量的作用?br /> #!/bin/bash<br /> #define the function ltx_func<br /> ltx_func()<br /> {<br />  <wbr> <wbr> echo $v1<br />  <wbr> <wbr> #modify the variable v1<br />  <wbr> <wbr> v1=200<br /> }<br /> #define the variable v1<br /> v1=100<br /> #call the function ltx_func<br /> ltx_func<br /> echo $v1<br /> <br /> l果Q?br /> 100<br /> 200<br /> 解析Q脚本变量v1的作用域从被定义的地方开始,到shelll束。调用函数l(f)tx_func的地方在变量v1的作用域内,所以能够访问ƈ修改变量v1?br /> <br /> (2)Shell函数定义的变量默认是global的,其作用域?#8220;函数被调用时执行变量定义的地?#8221;开始,到shelll束或被昄删除处ؓ(f)止。函数定义的变量可以被显C定义成local的,其作用域局限于函数内。但h意,函数的参数是local的?br /> <br /> ?Q函数定义的global变量<br /> #!/bin/bash<br /> #define the function ltx_func<br /> ltx_func()<br /> {<br />  <wbr> <wbr> #define the variable v2<br />  <wbr> <wbr> v2=200<br /> }<br /> #call the function ltx_func<br /> ltx_func<br /> echo $v2<br /> <br /> l果Q?br /> 200<br /> 解析Q函数变量v2默认是global的,其作用域?#8220;函数被调用时执行变量定义的地?#8221;开始,到shelll束为止。注意,不是从定义函数的地方开始,而是从调用函数的地方开始。打印命令在变量v2的作用域内,所以能够访问变量v2?br /> <br /> ?Q函数定义的local变量<br /> #!/bin/bash<br /> #define the function ltx_func<br /> ltx_func()<br /> {<br />  <wbr> <wbr> #define the local variable v2<br />  <wbr> <wbr> local v2=200<br /> }<br /> #call the function ltx_func<br /> ltx_func<br /> echo $v2<br /> <br /> l果Q?br /> Q空Q?br /> 解析Q函数变量v2昄定义为local的,其作用域局限于函数内。打印命令在函数外,不在变量v2的作用域内,所以能够不能访问变量v2?br /> <br /> ?Q函数参数是local变量<br /> #!/bin/bash<br /> #define the function ltx_func<br /> ltx_func()<br /> {<br />  <wbr> <wbr> echo "param 1: $1"<br /> }<br /> #call the function ltx_func<br /> ltx_func 100<br /> <br /> l果Q?br /> 100<br /> 解析Q函数参数是local的,通过位置变量来访问。打印命令输出函数的W一个参数?br /> <br /> (3)如果同名QShell函数定义的local变量会屏蔽脚本定义的global变量?br /> <br /> ?Q同名local变量屏蔽global变量<br /> #!/bin/bash<br /> #define the function ltx_func<br /> ltx_func()<br /> {<br />  <wbr> <wbr> echo $v1<br />  <wbr> <wbr> #define the local variable v1<br />  <wbr> <wbr> local v1=200<br />  <wbr> <wbr> echo $v1<br /> }<br /> #define the global variable v1<br /> v1=100</p> <p>#call the function ltx_func<br /> ltx_func<br /> echo $v1<br /> <br /> l果Q?br /> 100<br /> 200<br /> 100<br /> 解析Qglobal变量v1的作用域从被定义的地方开始,到shelll束。调用函数l(f)tx_func的地方在变量v1的作用域内,所以能够变量v1。函 数又定义了同名的local变量v1Q同名local变量屏蔽global变量Q所以函数第二次打印讉K的是local变量。退出函数后再次打印v1Q此 时函数定义的local变量已经消失Q访问的是global变量?/p> </div></div><img src ="http://www.shnenglu.com/colorful/aggbug/185148.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/colorful/" target="_blank">多彩人生</a> 2012-07-26 10:53 <a href="http://www.shnenglu.com/colorful/archive/2012/07/26/185148.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>nohuphttp://www.shnenglu.com/colorful/archive/2012/07/24/184858.html多彩人生多彩人生Tue, 24 Jul 2012 06:55:00 GMThttp://www.shnenglu.com/colorful/archive/2012/07/24/184858.htmlhttp://www.shnenglu.com/colorful/comments/184858.htmlhttp://www.shnenglu.com/colorful/archive/2012/07/24/184858.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/184858.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/184858.html
http://baike.baidu.com/view/1839401.htm


多彩人生 2012-07-24 14:55 发表评论
]]>
~译c文g出现undefined reference to `__gxx_personality_v0'http://www.shnenglu.com/colorful/archive/2012/07/23/184712.html多彩人生多彩人生Mon, 23 Jul 2012 03:47:00 GMThttp://www.shnenglu.com/colorful/archive/2012/07/23/184712.htmlhttp://www.shnenglu.com/colorful/comments/184712.htmlhttp://www.shnenglu.com/colorful/archive/2012/07/23/184712.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/184712.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/184712.html在linux~写E序如下
QUOTE:
#include
#include
#include
int count=0;
void ctrl_c_count(int);
main()
{
int c;
void (*old_handler)(int);
old_handler=signal(SIGINT,ctrl_c_count);
while((c=getchar()!='\n'))
;
printf("Ctrl_C count=%d\n",count);
signal(SIGINT,old_handler);

}
void ctrl_c_count(int i)
{
printf("Ctrl_C\n");
count++;
}

q个E序的功能是研究signal函数的应?
signal 函数是用于设|信号量的处理函Cؓ(f)自定义的?br /> SIGINT是用户在l端上按下ctrl+c的而生信号量
它的pȝ默认的处理函Cؓ(f)l止正运行的q程
现在把它Ҏ(gu)按ctrl+c后,是全局变量count?的操?br /> 当用户在l端输入回R后该q程l束?br /> 且又把SIGINT的处理函Cؓ(f)默认的?br />
当我把上q程序保存ؓ(f)t.cpp?br /> 利用gcc -o t t.cpp
产生如下错误
/tmp/ccGsoxH2.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
解决Ҏ(gu)?gcc -o t t.cpp -lstdc++
Z么会出现q个错误Q是因ؓ(f)你用gcc~译.cpp文g.按系l默?cpp文g是c++的文件格?br /> 另一个方法是用g++ -o t t.cpp 也是可以?br /> q有一U方法是把文件保存ؓ(f).c格式Q反正里面全是c的代?br /> 然后用gcc -o t t.c或者是g++ -o t t.c 都是OK?/div>

多彩人生 2012-07-23 11:47 发表评论
]]>
一个linux 博客http://www.shnenglu.com/colorful/archive/2012/05/07/173878.html多彩人生多彩人生Mon, 07 May 2012 01:56:00 GMThttp://www.shnenglu.com/colorful/archive/2012/05/07/173878.htmlhttp://www.shnenglu.com/colorful/comments/173878.htmlhttp://www.shnenglu.com/colorful/archive/2012/05/07/173878.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/173878.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/173878.htmlhttp://blog.chinaunix.net/uid/20754793/frmd/14822/page/1.html

多彩人生 2012-05-07 09:56 发表评论
]]>
Linux中时间度?http://www.shnenglu.com/colorful/archive/2012/05/07/173877.html多彩人生多彩人生Mon, 07 May 2012 01:51:00 GMThttp://www.shnenglu.com/colorful/archive/2012/05/07/173877.htmlhttp://www.shnenglu.com/colorful/comments/173877.htmlhttp://www.shnenglu.com/colorful/archive/2012/05/07/173877.html#Feedback0http://www.shnenglu.com/colorful/comments/commentRss/173877.htmlhttp://www.shnenglu.com/colorful/services/trackbacks/173877.htmlLinux中时间度?/a>

一)ANSI clock函数


1)概述:
clock 函数的返回值类型是clock_t,它除以CLOCKS_PER_SEC来得出时?一般用两次clock函数来计进E自w运行的旉.

ANSI clock有三个问?
1)如果过一个小?要D溢出.
2)函数clock没有考虑CPU被子q程使用的情?
3)也不能区分用L(fng)间和内核I间.

所以clock函数在linuxpȝ上变得没有意?

2)试
~写test1.cE序,试采用clock函数的输ZtimeE序的区?

vi test1.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main( void )
{
   long i=1000L;
   clock_t start, finish;
   double  duration;
   printf( "Time to do %ld empty loops is ", i );
   start = clock();
   while (--i){
    system("cd");
   }
   finish = clock();
   duration = (double)(finish - start) / CLOCKS_PER_SEC;
   printf( "%f seconds\n", duration );
   return 0;
}

gcc test1.c -o test1

time ./test1
Time to do 1000 empty loops is 0.180000 seconds

real    0m3.492s
user    0m0.512s
sys     0m2.972s

3)ȝ:
(1)E序调用 system("cd");Q这里主要是pȝ模式子进E的消?test1E序不能体现q一?
(2)0.180000 secondsU的消耗是两次clock()函数调用除以CLOCKS_PER_SEC.
(3)clock()函数q回值是一个相Ҏ(gu)_而不是绝Ҏ(gu)?
(4)CLOCKS_PER_SEC是系l定义的宏,由GNU标准库定义ؓ(f)1000000.

 


?times()旉函数

1)概述:

原型如下Q?br /> clock_t times(struct tms *buf);

tmsl构体如?
strace tms{
 clock_t tms_utime;
 clock_t tms_stime;
 clock_t tms_cutime;
 clock_t tms_cstime;
}

注释:
tms_utime记录的是q程执行用户代码的时?
tms_stime记录的是q程执行内核代码的时?
tms_cutime记录的是子进E执行用户代码的旉.
tms_cstime记录的是子进E执行内总码的旉.


2)试:

vi test2.c
#include <sys/times.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

static void do_cmd(char *);
static void pr_times(clock_t, struct tms *, struct tms *);

int main(int argc, char *argv[]){
        int i;
        for(i=1; argv[i]!=NULL; i++){
                do_cmd(argv[i]);
        }
        exit(1);
}
static void do_cmd(char *cmd){
        struct tms tmsstart, tmsend;
        clock_t start, end;
        int status;
        if((start=times(&tmsstart))== -1)
                puts("times error");
        if((status=system(cmd))<0)
                puts("system error");
        if((end=times(&tmsend))== -1)
                puts("times error");
        pr_times(end-start, &tmsstart, &tmsend);
        exit(0);
}
static void pr_times(clock_t real, struct tms *tmsstart, struct tms *tmsend){
        static long clktck=0;
        if(0 == clktck)
                if((clktck=sysconf(_SC_CLK_TCK))<0)
                           puts("sysconf err");
        printf("real:%7.2f\n", real/(double)clktck);
        printf("user-cpu:%7.2f\n", (tmsend->tms_utime - tmsstart->tms_utime)/(double)clktck);
        printf("system-cpu:%7.2f\n", (tmsend->tms_stime - tmsstart->tms_stime)/(double)clktck);
        printf("child-user-cpu:%7.2f\n", (tmsend->tms_cutime - tmsstart->tms_cutime)/(double)clktck);
        printf("child-system-cpu:%7.2f\n", (tmsend->tms_cstime - tmsstart->tms_cstime)/(double)clktck);
}

~译:
gcc test2.c -o test2

试q个E序:
time ./test2 "dd if=/dev/zero f=/dev/null bs=1M count=10000"
10000+0 records in
10000+0 records out
10485760000 bytes (10 GB) copied, 4.93028 s, 2.1 GB/s
real:   4.94
user-cpu:   0.00
system-cpu:   0.00
child-user-cpu:   0.01
child-system-cpu:   4.82

real    0m4.943s
user    0m0.016s
sys     0m4.828s


3)ȝ:
(1)通过q个试,pȝ的timeE序与test2E序输出基本一致了.
(2)(double)clktck是通过clktck=sysconf(_SC_CLK_TCK)来取?也就是要得到user-cpu所占用的时? p?br /> (tmsend->tms_utime - tmsstart->tms_utime)/(double)clktck);
(3)clock_t times(struct tms *buf);q回值是q去一D|间内旉嘀嗒的ơ数.
(4)times()函数q回g是一个相Ҏ(gu)?

 

?实时函数clock_gettime

在POSIX1003.1中增Mq个函数,它的原型如下Q?br /> int clock_gettime(clockid_t clk_id, struct timespec *tp);

它有以下的特?
1)它也有一个时间结构体:timespec ,timespec计算旉ơ数的单位是十亿分之一U?
strace timespec{
 time_t tv_sec;
 long tv_nsec;
}

2)clockid_t是确定哪个时钟类?

CLOCK_REALTIME: 标准POSIX实时旉
CLOCK_MONOTONIC: POSIX旉,以恒定速率q行;不会复位和调?它的取值和CLOCK_REALTIME是一L(fng).
CLOCK_PROCESS_CPUTIME_ID和CLOCK_THREAD_CPUTIME_ID是CPU中的g计时器中实现?


3)试:
#include<time.h>
#include<stdio.h>
#include<stdlib.h>

#define MILLION 1000000


int main(void)
{
        long int loop = 1000;
        struct timespec tpstart;
        struct timespec tpend;
        long timedif;

        clock_gettime(CLOCK_MONOTONIC, &tpstart);

        while (--loop){
                system("cd");
        }

        clock_gettime(CLOCK_MONOTONIC, &tpend);
        timedif = MILLION*(tpend.tv_sec-tpstart.tv_sec)+(tpend.tv_nsec-tpstart.tv_nsec)/1000;
        fprintf(stdout, "it took %ld microseconds\n", timedif);

        return 0;
}

~译:
gcc test3.c -lrt -o test3

计算旉:
time ./test3
it took 3463843 microseconds

real    0m3.467s
user    0m0.512s
sys     0m2.936s

 


?旉函数gettimeofday()

1)概述:
gettimeofday()可以获得当前pȝ的时?是一个绝对?/p>

原型如下Q?br /> int gettimeofday ( struct timeval * tv , struct timezone * tz )

timevall型体的原型如下:
struct timeval {
               time_t      tv_sec;    
               suseconds_t tv_usec;   
           };

所以它可以_到微U?/p>


试:
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
int
main(){
        int i=10000000;
        struct timeval tvs,tve;
        gettimeofday(&tvs,NULL);
        while (--i);
        gettimeofday(&tve,NULL);
        double span = tve.tv_sec-tvs.tv_sec + (tve.tv_usec-tvs.tv_usec)/1000000.0;
        printf("time: %.12f\n",span);
        return 0;
}

gcc test5.c
./a.out
time: 0.041239000000

 

?四种旉函数的比?/strong>

1)_度比?

以下是各U精度的类型{?
1U?1000毫秒(ms), 1毫秒=1/1000U?s)Q?br /> 1U?1000000 微秒(μs), 1微秒=1/1000000U?s)Q?br /> 1U?1000000000 U秒(ns),1U秒=1/1000000000U?s)Q?/p>


2)
clock()函数的精度?0毫秒(ms)
times()函数的精度?0毫秒(ms)
gettimofday()函数的精度是微U?μs)
clock_gettime()函数的计量单位ؓ(f)十亿分之一Q也是U秒(ns)


3)试4U函数的_?

vi test4.c


#include    <stdio.h>
#include    <stdlib.h>
#include    <unistd.h>
#include    <time.h>
#include    <sys/times.h>
#include    <sys/time.h>
#define WAIT for(i=0;i<298765432;i++);
#define MILLION    1000000
    int
main ( int argc, char *argv[] )
{
    int i;
    long ttt;
    clock_t s,e;
    struct tms aaa;



    s=clock();
    WAIT;
    e=clock();
    printf("clock time : %.12f\n",(e-s)/(double)CLOCKS_PER_SEC);


    long tps = sysconf(_SC_CLK_TCK);
    s=times(&aaa);
    WAIT;
    e=times(&aaa);
    printf("times time : %.12f\n",(e-s)/(double)tps);


    struct timeval tvs,tve;
    gettimeofday(&tvs,NULL);
    WAIT;
    gettimeofday(&tve,NULL);
    double span = tve.tv_sec-tvs.tv_sec + (tve.tv_usec-tvs.tv_usec)/1000000.0;
    printf("gettimeofday time: %.12f\n",span);


    struct timespec tpstart;
    struct timespec tpend;

    clock_gettime(CLOCK_REALTIME, &tpstart);
    WAIT;
    clock_gettime(CLOCK_REALTIME, &tpend);
    double timedif = (tpend.tv_sec-tpstart.tv_sec)+(tpend.tv_nsec-tpstart.tv_nsec)/1000000000.0;
    printf("clock_gettime time: %.12f\n", timedif);

    return EXIT_SUCCESS;
}

gcc -lrt test4.c -o test4
debian:/tmp# ./test4
clock time : 1.190000000000
times time : 1.180000000000
gettimeofday time: 1.186477000000
clock_gettime time: 1.179271718000

 

?内核旉

默认的Linux旉周期?00HZ,而现在最新的内核旉周期默认?50HZ.
如何得到内核的时钟周期呢?
grep ^CONFIG_HZ /boot/config-2.6.26-1-xen-amd64

CONFIG_HZ_250=y
CONFIG_HZ=250

l果是250HZ.

而用sysconf(_SC_CLK_TCK);得到的却?00HZ
例如:

#include    <stdio.h>
#include    <stdlib.h>
#include    <unistd.h>
#include    <time.h>
#include    <sys/times.h>
#include    <sys/time.h>

int
main ( int argc, char *argv[] )
{

    long tps = sysconf(_SC_CLK_TCK);
    printf("%ld\n", tps);
   
    return EXIT_SUCCESS;
}

Z么得到的是不同的值呢Q?br /> 因ؓ(f)sysconf(_SC_CLK_TCK)和CONFIG_HZ所代表的意义是不同?
sysconf(_SC_CLK_TCK)是GNU标准库的clock_t频率.
它的定义位置?/usr/include/asm/param.h

例如:
#ifndef HZ
#define HZ 100
#endif

最后ȝ一下内核时?
内核的标准时间是jiffy,一个jiffy是一个内部时钟周?而内部时钟周期是?50HZ的频率所产生中的,也就是一个时钟滴{?间隔旉??U?ms).

也就是说:
1个jiffy=1个内部时钟周?250HZ=1个时钟滴{?4毫秒

每经q一个时钟滴{就会调用一ơ时钟中断处理程序,处理E序用jiffy来篏计时钟滴{数,每发生一ơ时钟中断就?.
而每个中断之?pȝ通过调度E序跟据旉片选择是否要进El运?或让q程q入qA状?

最后需要说明的是每个操作系l的旉滴答频率都是不一L(fng),LINUX可以选择(100,250,1000)HZ,而DOS的频率是55HZ.

 

?为应用程序计?/strong>

用timeE序可以监视M命o或脚本占用CPU的情?

1)bash内置命otime
例如:
time sleep 1

real    0m1.016s
user    0m0.000s
sys     0m0.004s


2)/usr/bin/time的一般命令行
例如:
\time sleep 1
0.00user 0.00system 0:01.01elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (1major+176minor)pagefaults 0swaps

注:
在命令前加上斜杠可以l过内部命o.
/usr/bin/timeq可以加?v看到更具体的输出:
\time -v sleep 1
        Command being timed: "sleep 1"
        User time (seconds): 0.00
        System time (seconds): 0.00
        Percent of CPU this job got: 0%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.00
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 0
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 178
        Voluntary context switches: 2
        Involuntary context switches: 0
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0
       
q里的输出更多来源于l构体rusage.

最后,我们看到real time大于user time和sys time的dQ这说明q程不是在系l调用中d,是得不到运行的Z.
而sleep()的运用,也说明了q一?/div>

多彩人生 2012-05-07 09:51 发表评论
]]> þֻоƷ18| һɫۺϾþ| ĻۺϾþ| ˬˬƬaþ| ŷ޾Ʒ˾þ| ƷƵþ| Ļ˾Ʒþò| ҹƷþþþþ| þݺҹҹվ| ޹Ʒһþhs| þ99Ʒþþþ| þۺۺϾþ97ɫ| 69þҹɫƷ69| ҹƷþþþ| 99Ʒþþþþþ| þþþëƬ| ŮþþƷ㽶69| ҹƷþþþ| þþþþ޾Ʒ| þþþþ˸߳ӰԺ| 99ƷþþƷ| Vþþ| Ʒþۺ123 | ޾ƷþþþĻ| þþþþþþþþþƷ| ձþþþĻ| ޾þþһ| ޷AVþò| www.þ99| þþWWW| þSEƷһ| ľþþþר| Ʒþþþþø| ŷպƷþþþ| 99þ99þþƷƬ| þˬˬƬav鷳| ձƬҹþ| ƷƵþþþ| 777ҹƷþav| þݺҹҹ2020 | þùҹaӰԺ |