<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>https://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>https://jackxiang.com/post//</link>
<title><![CDATA[[常常遇到]通过Strace定位故障原因之connect() failed (110: Connection timed out) while connecting to upstream]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Thu, 22 Jun 2017 15:48:16 +0000</pubDate> 
<guid>https://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	分析文章：https://huoding.com/2013/10/06/288<br/>内存不够用时通过它来申请新内存（data segment）<br/><br/><br/>「man brk」来查询一下它的含义：<br/><br/>brk() sets the end of the data segment to the value specified by end_data_segment, when that value is reasonable, the system does have enough memory and the process does not exceed its max data size (see setrlimit(2)).<br/><br/>在Strace中和操作花费时间相关的选项有两个，分别是「-r」和「-T」，它们的差别是「-r」表示相对时间，而「-T」表示绝对时间。简单统计可以用「-r」，但是需要注意的是在多任务背景下，CPU随时可能会被切换出去做别的事情，所以相对时间不一定准确，此时最好使用「-T」，在行尾可以看到操作时间，可以发现确实很慢。 更多：https://blog.huoding.com/2013/10/06/288 <br/><textarea name="code" class="php" rows="15" cols="100">
pgrep -n php-fpm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#多个PHP-FPM进程只跟踪一个
47655


strace -T -e brk -p $(pgrep -n php-fpm)
Process 47655 attached

</textarea><br/><br/>shell&gt; strace -T -p $(pgrep -n php-cgi) 2&gt;&amp;1 &#124; grep -B 10 brk<br/>stat(&quot;/path/to/script.php&quot;, &#123;...&#125;) = 0 &lt;0.000064&gt;<br/>brk(0x1d9a000) = 0x1d9a000 &lt;0.000067&gt;<br/>brk(0x1dda000) = 0x1dda000 &lt;0.001134&gt;<br/>brk(0x1e1a000) = 0x1e1a000 &lt;0.000065&gt;<br/>brk(0x1e5a000) = 0x1e5a000 &lt;0.012396&gt;<br/>brk(0x1e9a000) = 0x1e9a000 &lt;0.000092&gt;<br/><br/>cat bak0.c <br/>#include&lt;stdio.h&gt;<br/>#include &lt;unistd.h&gt;<br/><br/>int main()<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;int*p1 = sbrk(4);<br/>&nbsp;&nbsp;&nbsp;&nbsp;int*p2 = sbrk(4);<br/>&nbsp;&nbsp;&nbsp;&nbsp;int*p3 = sbrk(4);<br/>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;pid%d&#92;n&quot;,getpid());<br/>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;p1:%p&#92;n&quot;,p1);<br/>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;p2:%p&#92;n&quot;,p2);<br/>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;p3:%p&#92;n&quot;,p3);<br/>&nbsp;&nbsp;&nbsp;&nbsp; while(1);<br/>&#125;<br/><br/>gcc bak0.c&nbsp;&nbsp;-o main<br/>#./main <br/>pid2816<br/>p1:0x602000<br/>p2:0x602004<br/>p3:0x602008<br/>ps -ef&#124;grep main<br/>root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2994&nbsp;&nbsp;2461 94 10:26 pts/3&nbsp;&nbsp;&nbsp;&nbsp;00:00:07 ./main<br/>此时我们可以看下他的maps文件<br/>cat /proc/2994/maps<br/>00602000-00603000 rw-p 00000000 00:00 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[heap]<br/><br/><br/>2)&nbsp;&nbsp;内核维护一个指针，假设是p，那么sbrk(0)或得到一个没有被占用的虚拟内存地址，但是此时不分配空间，但是此时只是初始化p，所以你如果对此时得到的内存地址赋值，那么就会出现段错误<br/>cat bak.c<br/>#include&lt;stdio.h&gt;<br/>#include&lt;unistd.h&gt;<br/> <br/>int main()<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int *p = sbrk(0);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;%p&#92;n&quot;,p);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *p = 111;<br/><br/>&#125;<br/>gcc bak.c -o main<br/><br/>#./main <br/>0x602000<br/>段错误(吐核)<br/><br/><br/>来自：https://blog.csdn.net/xiaoxiaopengbo/article/details/78206953<br/>https://www.cnblogs.com/chengxuyuancc/p/3566710.html
]]>
</description>
</item><item>
<link>https://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [常常遇到]通过Strace定位故障原因之connect() failed (110: Connection timed out) while connecting to upstream]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>