<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>五四陈科学院-坚信科学，分享技术 &#187; linux</title>
	<atom:link href="http://www.54chen.com/tag/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.54chen.com</link>
	<description>PHP、JAVA、缓存、架构、经验、分享</description>
	<lastBuildDate>Fri, 10 Feb 2012 12:21:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>跨系统共享键盘鼠标利器分享：synergy</title>
		<link>http://www.54chen.com/_linux_/tool-for-cross-system-shared-keyboard-and-mouse-share-synergy.html</link>
		<comments>http://www.54chen.com/_linux_/tool-for-cross-system-shared-keyboard-and-mouse-share-synergy.html#comments</comments>
		<pubDate>Thu, 17 Jun 2010 10:03:00 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[synergy]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/tool-for-cross-system-shared-keyboard-and-mouse-share-synergy.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>是这样的张总, ?在家里的电脑上按了CTRL+C，然后在公司的电脑上再按CTRL+V是。。。肯定不行的。即使同一篇文章也不行。不不，多贵的电脑都不行。 --题记 端午归来，特此总结，实现上述难题，靠一利器：synergy 此利器可打通mac\linux\windows任意两者的联系，使两个系统共享鼠标和键盘。下面以ubuntu 10.04与盗版windows XP为例。 首先，在ubuntu下面，建立服务端。 #sudo apt-get install synergy quicksynergy #quicksynergy 启动后如图所示： 只需要填写上下左右中的某一个位置修改成另一台机器的机器名，点击执行，常驻运行即可。 然后，在windows下面，安装客户端。 Synergy 1.3 Client 安装运行后如图： 输入Ubuntu机器的ip地址，点Start即可连上两机。 连上之后，可以撤掉在你办公桌面上的一个键盘，鼠标移动到哪个桌面上，键盘针对哪个系统输入，非常好用，还支持复制粘贴，对上班时候用两台电脑的同学非常适用。<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img02.taobaocdn.com/imgextra/i2/T1MNNDXetkXXbMtWc5_054611.jpg" alt="世界杯马蜂窝" /><br />
是这样的张总, ?在家里的电脑上按了CTRL+C，然后在公司的电脑上再按CTRL+V是。。。肯定不行的。即使同一篇文章也不行。不不，多贵的电脑都不行。</p>
<p>--题记</p>
<p>端午归来，特此总结，实现上述难题，靠一利器：synergy</p>
<p>此利器可打通mac\linux\windows任意两者的联系，使两个系统共享鼠标和键盘。下面以ubuntu 10.04与盗版windows XP为例。</p>
<p>首先，在ubuntu下面，建立服务端。<br />
#sudo apt-get install synergy quicksynergy<br />
#quicksynergy<br />
启动后如图所示：<br />
<img src="http://img05.taobaocdn.com/imgextra/i5/T12x8DXkpcXXaH5Js5_055323.jpg" alt="synergy" /><br />
只需要填写上下左右中的某一个位置修改成另一台机器的机器名，点击执行，常驻运行即可。</p>
<p>然后，在windows下面，安装客户端。<br />
Synergy 1.3 Client<br />
安装运行后如图：<br />
<img src="http://img08.taobaocdn.com/imgextra/i8/T1N3RDXlpBXXc8W3U5_055747.jpg" alt="Synergy 1.3 " /><br />
输入Ubuntu机器的ip地址，点Start即可连上两机。</p>
<p>连上之后，可以撤掉在你办公桌面上的一个键盘，鼠标移动到哪个桌面上，键盘针对哪个系统输入，非常好用，还支持复制粘贴，对上班时候用两台电脑的同学非常适用。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/tool-for-cross-system-shared-keyboard-and-mouse-share-synergy.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ubuntu 10.04 LTS版本下的Empathy MSN群聊显示昵称方法</title>
		<link>http://www.54chen.com/_linux_/ubuntu-1004-lts-version-of-the-empathy-msn-group-chat-under-the-nickname-display-method.html</link>
		<comments>http://www.54chen.com/_linux_/ubuntu-1004-lts-version-of-the-empathy-msn-group-chat-under-the-nickname-display-method.html#comments</comments>
		<pubDate>Fri, 04 Jun 2010 11:23:44 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/ubuntu-1004-lts-version-of-the-empathy-msn-group-chat-under-the-nickname-display-method.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>1.关系普及 Empathy是个托，python-papyon是个python实现的msn库，telepathy-butterfly是个完成msn功能的python客户端。 2.修改办法 sudo vim /usr/share/pyshared/papyon/conversation.py 查找 if message_type == 这个字符串 找到内容为： if message_type == 'text/plain': msg = ConversationMessage(unicode(message.body, message_encoding), TextFormat.parse(message_formatting), self.__last_received_msn_objects) try: display_name = message.get_header('P4-Context') 将if判断后try之前中间定义msg这一堆内容修改为如下： try: msg = ConversationMessage(unicode("["+message.get_header('P4-Context')+"]"+message.body, message_encoding), TextFormat.parse(message_formatting), self.__last_received_msn_objects) except KeyError: msg = ConversationMessage(unicode(message.body, message_encoding), &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img06.taobaocdn.com/bao/uploaded/i6/T1BulCXhXkXXXYjVM9_072304.jpg" alt="54chen ubuntu empathy msn" /></p>
<h2><strong>1.关系普及</strong></h2>
<p>Empathy是个托，python-papyon是个python实现的msn库，telepathy-butterfly是个完成msn功能的python客户端。</p>
<h2><strong>2.修改办法</strong></h2>
<p>sudo vim /usr/share/pyshared/papyon/conversation.py<br />
查找 if message_type == 这个字符串<br />
找到内容为：</p>
<blockquote><p>if message_type == 'text/plain':<br />
            msg = ConversationMessage(unicode(message.body, message_encoding),<br />
                    TextFormat.parse(message_formatting),<br />
                    self.__last_received_msn_objects)<br />
            try:<br />
                display_name = message.get_header('P4-Context')</p></blockquote>
<p>将if判断后try之前中间定义msg这一堆内容修改为如下：</p>
<blockquote><p> try:<br />
                msg = ConversationMessage(unicode("["+message.get_header('P4-Context')+"]"+message.body, message_encoding),<br />
                    TextFormat.parse(message_formatting),<br />
                    self.__last_received_msn_objects)<br />
            except KeyError:<br />
                  msg = ConversationMessage(unicode(message.body, message_encoding),<br />
                    TextFormat.parse(message_formatting),<br />
                    self.__last_received_msn_objects)</p></blockquote>
<p>保存后重新启动empathy，msn群里就能显示昵称鸟。</p>
<p><img src="http://img02.taobaocdn.com/bao/uploaded/i2/T1_udCXfXjXXbldwg4_053033.jpg" alt="empathy" /></p>
<p><a href="http://www.54chen.com/conversation.py.gz"><font color=red>点击此处下载我的conversation.py文件</font></a></p>
<p>下载下来后执行：</p>
<blockquote><p>chen@54chen:~$ gunzip conversation.py.gz<br />
chen@54chen:~$ sudo cp conversation.py /usr/share/pyshared/papyon/</p></blockquote>
<p><strong>我的版本是：Empathy 2.30.1</strong></p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/ubuntu-1004-lts-version-of-the-empathy-msn-group-chat-under-the-nickname-display-method.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>linux系统更换sshd的方法手记[from科学院]</title>
		<link>http://www.54chen.com/_linux_/linux-system-replacement-method-sshd-notes-from-from-academy-of-sciences.html</link>
		<comments>http://www.54chen.com/_linux_/linux-system-replacement-method-sshd-notes-from-from-academy-of-sciences.html#comments</comments>
		<pubDate>Wed, 04 Nov 2009 07:42:12 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[sshd]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/linux-system-replacement-method-sshd-notes-from-from-academy-of-sciences.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>朋友的服务器让人给黑了，把sshd都给更换了，拿到root用户名密码直接用curl往外传。绝对是老毛子的手法，非常娴熟，入侵涉及的方案有perl服务、c、shell、curl、php exec等等。 在最简单的分析下，采取更换sshd服务的办法来去除老毛子的垃圾sshd. 第一步、下载、安装 wget -c "ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-5.0p1.tar.gz" tar zxvf openssh-5.0p1.tar.gz cd openssh-5.0p1 请确认Zlib和OpenSSL的版本: openssh-5.0p1要求Zlib的版本在1.2.1.2以上,OpenSSL版本在0.9.6以上.下面是Zlib和 OpenSSL的官方地址: http://www.gzip.org/zlib/ http://www.openssl.org/ 在安装过程中我遇到了zlib的版本过低。从上边的网址去下一个 zlib-1.2.3.tar.gz tar zxvf zlib-1.2.3.tar.gz cd zlib-1.2.3 ./configure make &#38;&#38; make install 然后重新进入 openssh-5.0p1: ./configure --sysconfdir=/etc/ssh make 这一步后面很牛B，要去到那个修改过的openssh的目录里 make uninstall (就是要把老毛子的病毒sshd给全部rm掉),然后再执行下面的步骤： make install &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>朋友的服务器让人给黑了，把sshd都给更换了，拿到root用户名密码直接用curl往外传。绝对是老毛子的手法，非常娴熟，入侵涉及的方案有<a href="http://www.54chen.com/79-perl-workshop-2008-%e5%bd%92%e6%9d%a5/">perl</a>服务、c、shell、curl、php exec等等。</p>
<p>在最简单的分析下，采取更换sshd服务的办法来去除老毛子的垃圾sshd.</p>
<p>第一步、下载、安装</p>
<blockquote><p>wget -c "ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-5.0p1.tar.gz"</p>
<p>tar zxvf openssh-5.0p1.tar.gz<br />
cd openssh-5.0p1</p></blockquote>
<p>请确认Zlib和OpenSSL的版本:<br />
openssh-5.0p1要求Zlib的版本在1.2.1.2以上,<a href="http://www.54chen.com/809-tsinghua-huambo-fist-of-fury-review-environmental-elements-lamp/">OpenSSL</a>版本在0.9.6以上.下面是Zlib和 OpenSSL的官方地址:</p>
<p>http://www.gzip.org/zlib/</p>
<p>http://www.openssl.org/</p>
<p>在安装过程中我遇到了zlib的版本过低。从上边的网址去下一个 zlib-1.2.3.tar.gz</p>
<blockquote><p>tar zxvf zlib-1.2.3.tar.gz</p>
<p>cd zlib-1.2.3</p>
<p>./configure</p>
<p>make &amp;&amp; make install</p></blockquote>
<p>然后重新进入 openssh-5.0p1:</p>
<blockquote><p>./configure --sysconfdir=/etc/ssh</p>
<p>make</p>
<p>这一步后面很牛B，要去到那个修改过的openssh的目录里 make uninstall (就是要把老毛子的病毒sshd给全部rm掉),然后再执行下面的步骤：</p>
<p>make install</p></blockquote>
<p>第二步、配置启动革新</p>
<p>新安装的sshd都在/usr/local/sbin/sshd，老的在/usr/sbin/sshd，ps能看到老的还在跑（当然还在跑，不跑你还能连着ssh操作吗~~·）</p>
<p>修改配置文件，让新的sshd在新的端口启动：</p>
<blockquote><p>vi /etc/ssh/sshd_config</p>
<p>Port 220</p>
<p>然后启动新的sshd:</p>
<p>/usr/local/ssh/sbin/sshd -f /etc/ssh/sshd_config</p>
<p>注意打开下iptable:</p>
<p>iptables -I <a href="http://www.54chen.com/230-%e6%b7%ab%e8%8d%a1%e4%b8%80%e4%b8%8b%ef%bc%8c%e4%bd%a0%e5%b0%b1%e7%9f%a5%e9%81%93/">INPUT</a> -p udp --dport 220 -j ACCEPT</p></blockquote>
<p>K掉原来的~~搞定！打完收工。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/linux-system-replacement-method-sshd-notes-from-from-academy-of-sciences.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>轻点魔棒，瞬间安装上百台服务器</title>
		<link>http://www.54chen.com/_linux_/%e8%bd%bb%e7%82%b9%e9%ad%94%e6%a3%92%ef%bc%8c%e7%9e%ac%e9%97%b4%e5%ae%89%e8%a3%85%e4%b8%8a%e7%99%be%e5%8f%b0%e6%9c%8d%e5%8a%a1%e5%99%a8.html</link>
		<comments>http://www.54chen.com/_linux_/%e8%bd%bb%e7%82%b9%e9%ad%94%e6%a3%92%ef%bc%8c%e7%9e%ac%e9%97%b4%e5%ae%89%e8%a3%85%e4%b8%8a%e7%99%be%e5%8f%b0%e6%9c%8d%e5%8a%a1%e5%99%a8.html#comments</comments>
		<pubDate>Tue, 06 Jan 2009 01:08:18 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[服务器安装]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/%e8%bd%bb%e7%82%b9%e9%ad%94%e6%a3%92%ef%bc%8c%e7%9e%ac%e9%97%b4%e5%ae%89%e8%a3%85%e4%b8%8a%e7%99%be%e5%8f%b0%e6%9c%8d%e5%8a%a1%e5%99%a8.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>转自: 知道分子查看完整个人资料  http://hutuworm.blogspot.com   从前，我们一直在做装机民工这份很有前途的职业。自打若干年前 Red Hat 推出了Kickstart，此后我们顿觉身价倍增。不再需要刻了光盘一台一台地安装 Linux，只要搞定PXE、DHCP、TFTP，还有那满屏眼花缭乱不知所云的 Kickstart脚本，我们就可以像哈里波特一样，轻点魔棒，瞬间安装上百台服务器。这一堆花里胡哨的东西可不是一般人都能整明白的，没有大专以上学 历，通不过英语四级，根本别想玩转。总而言之，这是一份多么有前途，多么有技术含量的工作啊。 很不幸，Red Hat 最新发布了网络安装服务器套件Cobbler（补鞋匠），它已将 Linux网络安装的技术门槛，从大专以上文化水平，成功降低到初中以下，连补鞋匠都能学会。对于我们这些在装机领域浸淫多年，经验丰富，老骥伏枥，志在 千里的民工兄弟们来说，不啻为一个晴天霹雳（}雷{）。 Cobbler（https://fedorahosted.org/cobbler）声称可以快速建立网络安装环境（rapid setup ofnetwork installation environments），那么到底有多快呢？我在一台装有 Fedora 9的服务器上进行了测试，步骤如下： 1. 安装相关软件：      yum -y install cobbler tftp-server dhcp httpd xinetd     # 注意 /var/www/cobbler 目录必须具有足够容纳 Linux 安装文件的空间（移动，建软链接） 2. 检查 cobbler &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>转自: 知道分子<a href="http://www.blogger.com/profile/00767221594564607162" target="_blank">查看完整个人资料</a>  <a href="http://hutuworm.blogspot.com/" target="_blank">http://hutuworm.blogspot.com</a></p>
<p> </p>
<p>从前，我们一直在做装机民工这份很有前途的职业。自打若干年前 Red Hat 推出了Kickstart，此后我们顿觉身价倍增。不再需要刻了光盘一台一台地安装 <a href="http://www.54chen.com/c/356">Linux</a>，只要搞定PXE、DHCP、TFTP，还有那满屏眼花缭乱不知所云的 Kickstart脚本，我们就可以像哈里波特一样，轻点魔棒，瞬间安装上百台服务器。这一堆花里胡哨的东西可不是一般人都能整明白的，没有大专以上学 历，通不过英语四级，根本别想玩转。总而言之，这是一份多么有前途，多么有技术含量的工作啊。</p>
<p>很不幸，Red Hat 最新发布了网络安装服务器套件Cobbler（补鞋匠），它已将 <a href="http://www.54chen.com/c/356">Linux</a>网络安装的技术门槛，从大专以上文化水平，成功降低到初中以下，连补鞋匠都能学会。对于我们这些在装机领域浸淫多年，经验丰富，老骥伏枥，志在 千里的民工兄弟们来说，不啻为一个晴天霹雳（}雷{）。</p>
<p>Cobbler（<a href="https://fedorahosted.org/cobbler" target="_blank">https://fedorahosted.org/cobbler</a>）声称可以快速建立网络安装<a href="http://www.54chen.com/c/372">环境</a>（rapid setup ofnetwork installation environments），那么到底有多快呢？我在一台装有 Fedora 9的服务器上进行了测试，步骤如下：</p>
<p>1. 安装相关软件：<br />
     yum -y install cobbler tftp-server dhcp httpd xinetd     # 注意 /var/www/cobbler 目录必须具有足够容纳 Linux 安装文件的空间（移动，建软链接）</p>
<p>2. 检查 cobbler <span class="t_tag" onclick="tagshow(event)">配置</span>：<br />
     cobbler check   # 按提示解决相关问题，把 /etc/cobbler/settings 中的 server 和  next_server 设为本服务器的 IP 地址，manage_dhcp 设为 1，以便管理 DHCP</p>
<p>3. 导入 Fedora 9 安装 DVD ISO 中的文件：<br />
     mount -o loop Fedora9/x86_64/Fedora-9-x86_64-DVD.iso /mnt/dvd/    # 将ISO文件挂载到 /mnt/dvd 目录<br />
     cobbler import --mirror=/mnt/dvd --name=FC9-x86-64      # 从 /mnt/dvd 目录导入所有安装文件，命名为 FC9-x86-64<br />
     cobbler distro list          # 查看导入结果，应显示 FC9-64-i386 和 FC9-64-xen-i386</p>
<p>4. 修改 DHCP 和 Kickstart 配置模板：<br />
     vi /etc/cobbler/dhcp.template        # DHCP 配置模板，如果已经有一个 dhcpd.conf，可参照修改此模板<br />
     vi /etc/cobbler/sample.ks            # Kickstart 配置模板</p>
<p>5. 生成并同步所有配置：<br />
     cobbler sync</p>
<p>6. 启动相关服务：<br />
     service xinetd start               # /etc/xinetd.d/tftp 中 disable = no<br />
     service dhcpd start<br />
     service cobblerd start</p>
<p>曹植七步成诗，而 Cobbler 居然只需要六步。启动另一台新服务器，通过 PXE 启动进入蓝色的 Cobbler 安装界面，选择 Fedora 9 安装项，几分钟之内就能一气呵成，自动完成<span class="t_tag" onclick="tagshow(event)">系统</span>安装。[OVER]</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/%e8%bd%bb%e7%82%b9%e9%ad%94%e6%a3%92%ef%bc%8c%e7%9e%ac%e9%97%b4%e5%ae%89%e8%a3%85%e4%b8%8a%e7%99%be%e5%8f%b0%e6%9c%8d%e5%8a%a1%e5%99%a8.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ubuntu 8.10 desktop版本 硬盘安装手记</title>
		<link>http://www.54chen.com/_linux_/ubuntu-810-desktop%e7%89%88%e6%9c%ac-%e7%a1%ac%e7%9b%98%e5%ae%89%e8%a3%85%e6%89%8b%e8%ae%b0.html</link>
		<comments>http://www.54chen.com/_linux_/ubuntu-810-desktop%e7%89%88%e6%9c%ac-%e7%a1%ac%e7%9b%98%e5%ae%89%e8%a3%85%e6%89%8b%e8%ae%b0.html#comments</comments>
		<pubDate>Mon, 05 Jan 2009 08:01:37 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/ubuntu-810-desktop%e7%89%88%e6%9c%ac-%e7%a1%ac%e7%9b%98%e5%ae%89%e8%a3%85%e6%89%8b%e8%ae%b0.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>[文章作者：陈臻 本文版本：v1.0 最后修改：2009.1.5 转载请注明原文链接：http://www.54chen.com/c/372] 折腾到半夜，特做记录。 1.ubuntu8.10 liveCD系统镜像文件下载： ubuntu-8.10-desktop-i386.iso http://ubuntu.interhost.co.il/intrepid/ubuntu-8.10-desktop-i386.iso（某一个镜像的地址） 2.winGrub文件下载： WINGRB0206.EXE http://fedora.linuxsir.org/main/files/WINGRB0206.EXE 3.安装WINGRB0206.EXE： 双击，没啥说的。 4.运行winGrub： 第一次打开会有个BaseSetup，把勾都选上，选OK就行。 主界面中： Profiles选default。 Tools-&#62;Install Grub-&#62;Boot From 选Boot.ini，System Drive选C，Title随便写，TimeOut写30，-&#62;install 完毕！ 5.修改menu.lst： 从ubuntu-8.10-desktop-i386.iso的casper里解压出来vmlinuz和initrd.gz到C盘根目录，ubuntu-8.10-desktop-i386.iso文件放在任何一个盘的根目录，它会自己去找到的。 在C:\GRUB\menu.lst里增加如下： title Install Ubuntu root (hd0,0) kernel (hd0,0)/vmlinuz boot=casper iso-scan/filename=/ubuntu-8.10-desktop-i386.iso ro quiet splash locale=zh_CN.UTF-8 &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>[文章作者：陈臻 本文版本：v1.0 最后修改：2009.1.5 转载请注明原文链接：<a href="http://www.54chen.com/c/372">http://www.54chen.com/c/372</a>]</p>
<p>折腾到半夜，特做记录。</p>
<p>1.ubuntu8.10 liveCD系统镜像文件下载：</p>
<p>ubuntu-8.10-desktop-i386.iso</p>
<p>http://ubuntu.interhost.co.il/intrepid/ubuntu-8.10-desktop-i386.iso（某一个镜像的地址）</p>
<p>2.winGrub文件下载：</p>
<p>WINGRB0206.EXE</p>
<p>http://fedora.linuxsir.org/main/files/WINGRB0206.EXE</p>
<p>3.安装WINGRB0206.EXE：</p>
<p>双击，没啥说的。</p>
<p>4.运行winGrub：</p>
<p>第一次打开会有个BaseSetup，把勾都选上，选OK就行。</p>
<p>主界面中：</p>
<p>Profiles选default。</p>
<p>Tools-&gt;Install Grub-&gt;Boot From 选Boot.ini，System Drive选C，Title随便写，TimeOut写30，-&gt;install</p>
<p>完毕！</p>
<p>5.修改menu.lst：</p>
<p>从ubuntu-8.10-desktop-i386.iso的casper里解压出来vmlinuz和initrd.gz到C盘根目录，ubuntu-8.10-desktop-i386.iso文件放在任何一个盘的根目录，它会自己去找到的。</p>
<p>在C:\GRUB\menu.lst里增加如下：</p>
<p>title Install Ubuntu<br />
root (hd0,0)<br />
kernel (hd0,0)/vmlinuz boot=casper iso-scan/filename=/ubuntu-8.10-desktop-i386.iso ro quiet splash locale=zh_CN.UTF-8<br />
initrd (hd0,0)/initrd.gz</p>
<p>保存，重启。</p>
<p>6.选择从install Ubuntu进去：</p>
<p>一直进啊进，到了liveCD的桌面。双击安装。</p>
<p>问题来了，整个硬盘没有显示！使用ubuntu下的系统管理器可以看到系统加载了一个/isodevice的设备，这个就是加载的在F盘下的ubuntu镜像。我们要使用ubuntu下的终端输入sudo umount -l /isodevice来卸载掉它。-l这个参数必须加，否则不能卸载。然后在安装进程中点击后退，鼠标变成一个转动的圆圈，等两三分钟（视系统配置）就可以加载硬盘了。</p>
<p>7.安装完成重新启动</p>
<p>8.进入系统：</p>
<p>这时会发现一半中文一半英文，听说是LiveCD版本的原因，中文支持不完整。</p>
<p>这时先搜索最快的软件源服务器，然后在终端里输入</p>
<p>sudo apt-get update 更新了列表后执行下列命令</p>
<p>sudo apt-get install language-support-zh</p>
<p>ThinkPad 系列，调整屏幕亮度，请使用“首选项”-“电源管理”.亮度选择那个条是反的。试了就知道了。</p>
<p>完毕。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/ubuntu-810-desktop%e7%89%88%e6%9c%ac-%e7%a1%ac%e7%9b%98%e5%ae%89%e8%a3%85%e6%89%8b%e8%ae%b0.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MySQL的性能调优工具：比mysqlreport更方便的tuning-primer.sh</title>
		<link>http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html</link>
		<comments>http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html#comments</comments>
		<pubDate>Mon, 22 Dec 2008 01:43:08 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>Sundry MySQL提供的脚本相比mysqlreport更进一步：除了报表还进一步提供了修改建议。安装和使用非常简单： wget http://www.day32.com/MySQL/tuning-primer.sh chmod +x tuning-primer.sh ./tuning-primer.sh 和mysqlreport一样，tuning-primer.sh也支持.my.cnf [client] user = USERNAME password = PASSWORD socket = /tmp/mysql.sock   样例输出：在终端上按照问题重要程度分别用黄色/红色字符标记问题 -- MYSQL PERFORMANCE TUNING PRIMER -- - By: Matthew Montgomery -   MySQL Version 5.0.45 i686 Uptime = 19 days &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><div class="entry-body" style="clear: both;">
<p style="margin-top: 10px; margin-bottom: 10px;">Sundry MySQL提供的脚本相比mysqlreport更进一步：除了报表还进一步提供了修改建议。安装和使用非常简单：</p>
<blockquote style="margin-top: 10px; margin-bottom: 10px;"><p>wget<span class="Apple-converted-space"> </span><a style="color: #3165ce; text-decoration: underline;" href="http://www.day32.com/MySQL/tuning-primer.sh">http://www.day32.com/MySQL/tuning-primer.sh</a><br />
chmod +x tuning-primer.sh<br />
./tuning-primer.sh</p></blockquote>
<p>和mysqlreport一样，tuning-primer.sh也支持.my.cnf</p>
<blockquote style="margin-top: 10px; margin-bottom: 10px;"><p>[client]<br />
user = USERNAME<br />
password = PASSWORD<br />
socket = /tmp/mysql.sock</p></blockquote>
<p style="margin-top: 10px; margin-bottom: 10px;"> </p>
<p style="margin-top: 10px; margin-bottom: 10px;">样例输出：在终端上按照问题重要程度分别用黄色/红色字符标记问题</p>
<blockquote style="margin-top: 10px; margin-bottom: 10px;"><p>-- MYSQL PERFORMANCE TUNING PRIMER --<br />
- By: Matthew Montgomery -</p>
<p style="margin-top: 10px; margin-bottom: 10px;"> </p>
<p style="margin-top: 10px; margin-bottom: 10px;">MySQL Version 5.0.45 i686</p>
<p style="margin-top: 10px; margin-bottom: 10px;">Uptime = 19 days 8 hrs 32 min 54 sec<br />
Avg. qps = 0<br />
Total Questions = 264260<br />
Threads Connected = 1</p>
<p style="margin-top: 10px; margin-bottom: 10px;">Server has been running for over 48hrs.<br />
It should be safe to follow these recommendations</p>
<p style="margin-top: 10px; margin-bottom: 10px;">To find out more information on how each of these<br />
runtime variables effects performance visit:</p>
<p>http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html</p>
<p>Visit http://www.mysql.com/products/enterprise/advisors.html<br />
for info about MySQL's Enterprise Monitoring and Advisory Service</p>
<p style="margin-top: 10px; margin-bottom: 10px;">SLOW QUERIES<br />
The slow query log is NOT enabled.<br />
Current long_query_time = 10 sec.<br />
You have 0 out of 264274 that take longer than 10 sec. to complete<br />
Your long_query_time may be too high, I typically set this under 5 sec.</p>
<p style="margin-top: 10px; margin-bottom: 10px;">BINARY UPDATE LOG<br />
The binary update log is NOT enabled.<br />
You will not be able to do point in time recovery<br />
See http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html</p>
<p style="margin-top: 10px; margin-bottom: 10px;">WORKER THREADS<br />
Current thread_cache_size = 0<br />
Current threads_cached = 0<br />
Current threads_per_sec = 1<br />
Historic threads_per_sec = 0<br />
Your thread_cache_size is fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">MAX CONNECTIONS<br />
Current max_connections = 100<br />
Current threads_connected = 1<br />
Historic max_used_connections = 33<br />
The number of used connections is 33% of the configured maximum.<br />
Your max_connections variable seems to be fine.</p>
<p style="margin-top: 10px; margin-bottom: 10px;">MEMORY USAGE<br />
Max Memory Ever Allocated : 96 M<br />
Configured Max Per-thread Buffers : 268 M<br />
Configured Max Global Buffers : 7 M<br />
Configured Max Memory Limit : 276 M<br />
Physical Memory : 1.97 G<br />
Max memory limit seem to be within acceptable norms</p>
<p style="margin-top: 10px; margin-bottom: 10px;">KEY BUFFER<br />
Current MyISAM index space = 8 M<br />
Current key_buffer_size = 7 M<br />
Key cache miss rate is 1 : 1817<br />
Key buffer fill ratio = 6.00 %<br />
Your key_buffer_size seems to be too high.<br />
Perhaps you can use these resources elsewhere</p>
<p style="margin-top: 10px; margin-bottom: 10px;">QUERY CACHE<br />
Query cache is supported but not enabled<br />
Perhaps you should set the query_cache_size</p>
<p style="margin-top: 10px; margin-bottom: 10px;">SORT OPERATIONS<br />
Current sort_buffer_size = 2 M<br />
Current read_rnd_buffer_size = 256 K<br />
Sort buffer seems to be fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">JOINS<br />
Current join_buffer_size = 132.00 K<br />
You have had 0 queries where a join could not use an index properly<br />
Your joins seem to be using indexes properly</p>
<p style="margin-top: 10px; margin-bottom: 10px;">OPEN FILES LIMIT<br />
Current open_files_limit = 1024 files<br />
The open_files_limit should typically be set to at least 2x-3x<br />
that of table_cache if you have heavy MyISAM usage.<br />
Your open_files_limit value seems to be fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">TABLE CACHE<br />
Current table_cache value = 64 tables<br />
You have a total of 125 tables<br />
You have 64 open tables.<br />
Current table_cache hit rate is 9%, while 100% of your table cache is in use<br />
<strong>You should probably increase your table_cache<br />
</strong><br />
TEMP TABLES<br />
Current max_heap_table_size = 16 M<br />
Current tmp_table_size = 32 M<br />
Of 564 temp tables, 6% were created on disk<br />
Effective in-memory tmp_table_size is limited to max_heap_table_size.<br />
Created disk tmp tables ratio seems fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">TABLE SCANS<br />
Current read_buffer_size = 128 K<br />
Current table scan ratio = 1 : 1<br />
read_buffer_size seems to be fine</p>
<p style="margin-top: 10px; margin-bottom: 10px;">TABLE LOCKING<br />
Current Lock Wait ratio = 0 : 264392<br />
Your table locking seems to be fine</p></blockquote>
<p style="margin-top: 10px; margin-bottom: 10px;"> </p>
<p style="margin-top: 10px; margin-bottom: 10px;">更有用是作者总结的处理MySQL性能问题处理的优先级：尤其是头3条，基本上可以解决大部分瓶颈问题的原因。<br />
# Slow Query Log 慢查询 尤其是like操作，性能杀手，轻易不要使用，让全文索引交给<a style="color: #3165ce; text-decoration: underline;" href="http://www.chedong.com/tech/lucene.html">Lucene</a>或者利用Tag机制减少like操作；<br />
# Max Connections 并发连接数：一个MySQL deamon缺省最大连接数是100，调到更高只是为了出现问题是给我们更多的缓冲时间而不是任其一直处于那么高的状态，并发连接数类似于等候大厅：当等候人数过多的时候，一味扩大等候厅不是根本解决问题的办法，提高业务的处理速度，多开几个窗口才是更好的解决方法；我的经验就是<a style="color: #3165ce; text-decoration: underline;" href="http://www.chedong.com/blog/archives/000945.html">超过100： 数据就要想办法（镜像或者分片）分布到更多Deamon上</a>；<br />
# Worker Threads：<span class="Apple-converted-space"> </span><a style="color: #3165ce; text-decoration: underline;" href="http://jeremy.zawodny.com/blog/archives/000173.html">Jeremy Zawondy 曾在部落格上說到：Thread caching</a><span class="Apple-converted-space"> </span>並不是我們最需要關心的問題，但當你解決了所有其他更嚴重的問題之後，它就會是最嚴重的問題。(thread caching really wasn't the worst of our problems. But it became the worst after we had fixed all the bigger ones.)<br />
# Key Buffer<span class="Apple-converted-space"> </span><br />
# Query Cache<span class="Apple-converted-space"> </span><br />
# Sort Buffer<span class="Apple-converted-space"> </span><br />
# Joins<span class="Apple-converted-space"> </span><br />
# Temp Tables 临时表<br />
# Table (Open &amp; Definition) Cache 表缓存；<br />
# Table Locking 表锁定<br />
# Table Scans (read_buffer)<span class="Apple-converted-space"> </span><br />
# Innodb Status</p>
</div>
<div id="more" class="entry-more" style="clear: both;">
<p style="margin-top: 10px; margin-bottom: 10px;">其他一些工具：<span class="Apple-converted-space"> </span><br />
1<span class="Apple-converted-space"> </span><a style="color: #3165ce; text-decoration: underline;" href="http://jeremy.zawodny.com/mysql/mytop/">mytop</a>： 一个top like的show processlist;<br />
2 使用cacti做MySQL的监控：推荐<a style="color: #3165ce; text-decoration: underline;" href="http://code.google.com/p/mysql-cacti-templates/">配置模板</a>；<br />
3 把binlog导出成文本和slowquery的格式几乎是一样的，调用mysqlslowquery脚本分析，有时候也会有意外收获；</p>
<p style="margin-top: 10px; margin-bottom: 10px;">谢谢 oldplantegg 补充：<br />
<a style="color: #3165ce; text-decoration: underline;" href="http://hackmysql.com/mysqlsla">mysqlsla</a>(<a style="color: #3165ce; text-decoration: underline;" href="http://hackmysql.com/">hackmysql.com</a>推出的一款日志分析工具该网站还维护了，mysqlreport,<span class="Apple-converted-space"> </span><a style="color: #3165ce; text-decoration: underline;" href="http://hackmysql.com/mysqlidxchk">mysqlidxchk</a><span class="Apple-converted-space"> </span>等比较实用的mysql工具)能够分析slow query 和binlog等，这样就不用将binlog导出来了.</p>
<p style="margin-top: 10px; margin-bottom: 10px;">from:http://www.chedong.com/blog/archives/001451.html</p>
</div>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/php-tech/mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>普及帖：Linux 下编译C程序</title>
		<link>http://www.54chen.com/_linux_/%e6%99%ae%e5%8f%8a%e5%b8%96%ef%bc%9alinux-%e4%b8%8b%e7%bc%96%e8%af%91c%e7%a8%8b%e5%ba%8f.html</link>
		<comments>http://www.54chen.com/_linux_/%e6%99%ae%e5%8f%8a%e5%b8%96%ef%bc%9alinux-%e4%b8%8b%e7%bc%96%e8%af%91c%e7%a8%8b%e5%ba%8f.html#comments</comments>
		<pubDate>Fri, 19 Dec 2008 02:28:02 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[c]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/%e6%99%ae%e5%8f%8a%e5%b8%96%ef%bc%9alinux-%e4%b8%8b%e7%bc%96%e8%af%91c%e7%a8%8b%e5%ba%8f.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>GNU 编译器集（其前身为GNU C 编译器）诞生于1987年。当时Richard Stallman（GNU 项目的创办人）想要创建一个编译器，它可以满足他定义的“自由软件”概念，并可用来编译 GNU 项目发布的其他软件。GNU C 编译器迅速在自由软件社区中流行开来，而且以其健壮性和可移植性而闻名。它已成为许多集成开发工具的基础，被世界各地的发行商应用在 Linux 和其他操作系统之上。   GCC 已不再是主要针对GNU项目自身的软件的小型 C 语言编译器了。如今，它已支持了许多不同的语言，包括 C、C++、Ada、Fortran、Objective C，甚至还有Java。事实上，现代 Linux 系统除了可以自豪地炫耀那些由 GNU 工具直接支持的语言以外，它还支持大量其他语言。日益流行的脚本语言 Perl、Python 和 Ruby，以及正在不断发展的mono 可移植C#实现的确有助于冲淡人们对 Linux 编程的传统看法，但这完全是另外一个问题了。 Linux 内核和许多其他自由软件以及开放源码应用程序都是用 C 语言编写并使用 GCC 编译的。 1. 编译单个源文件 为了进行测试，你可以创建“Hello World”程序： #include &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>GNU 编译器集（其前身为GNU C 编译器）诞生于1987年。当时Richard Stallman（GNU 项目的创办人）想要创建一个编译器，它可以满足他定义的“自由软件”概念，并可用来编译 GNU 项目发布的其他软件。GNU C 编译器迅速在自由软件社区中流行开来，而且以其健壮性和可移植性而闻名。它已成为许多集成开发工具的基础，被世界各地的发行商应用在 Linux 和其他操作系统之上。</p>
<p> </p>
<p>GCC 已不再是主要针对GNU项目自身的软件的小型 C 语言编译器了。如今，它已支持了许多不同的语言，包括 C、C++、Ada、Fortran、Objective C，甚至还有Java。事实上，现代 Linux 系统除了可以自豪地炫耀那些由 GNU 工具直接支持的语言以外，它还支持大量其他语言。日益流行的脚本语言 Perl、Python 和 Ruby，以及正在不断发展的mono 可移植C#实现的确有助于冲淡人们对 Linux 编程的传统看法，但这完全是另外一个问题了。</p>
<p>Linux 内核和许多其他自由软件以及开放源码应用程序都是用 C 语言编写并使用 GCC 编译的。</p>
<p>1. 编译单个源文件</p>
<p>为了进行测试，你可以创建“Hello World”程序：</p>
<blockquote><p>#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;</p>
<p>int main(int argc, char **argv)<br />
{<br />
printf(”Hello world!\n”);<br />
exit(0);<br />
}</p></blockquote>
<p>使用如下命令编译并测试这个代码：<br />
<code># gcc -o hello hello.c<br />
# ./hello<br />
Hello wordl!</code></p>
<p>在默认情况下产生的可执行程序名为a.out，但你通常可以通过 gcc 的“-o”选项来指定自己的可执行程序名称。</p>
<p>2. 编译多个源文件</p>
<p>源文件message.c包含一个简单的消息打印函数：</p>
<blockquote><p>#include &lt;stdio.h&gt;</p>
<p>void goodbye_world(void)<br />
{<br />
printf(”Goodbye, world!\n”);<br />
}</p></blockquote>
<p>使用gcc的“-c”标记来编译支持库代码：<br />
<code># gcc -c message.c</code></p>
<p>这一过程的输出结果是一个名为message.o的文件，它包含适合连接到一个较大程序的已编译目标代码。</p>
<p>创建一个简单的示例程序，它包含一个调用goodbye_world的main函数</p>
<blockquote><p>#include &lt;stdlib.h&gt;</p>
<p>void goodbye_world(void):</p>
<p>int main(int argc, char **argv)<br />
{<br />
goodbye_world();<br />
exit(0);<br />
}</p></blockquote>
<p>使用GCC编译这个程序：<br />
<code># gcc -c main.c</code></p>
<p>现在有了两个目标文件： message.o 和 main.o 。它们包含能够被 Linux 执行的目标代码。要从这个目标代码创建Linux可执行程序，需要再一次调用 GCC 来执行连接阶段的工作：<br />
# gcc -o goodbye message.o main.o</p>
<p>运行编译结果：<br />
<code># ./goodbye<br />
Goodbye, world!</code></p>
<p>前面这些单独的步骤也可以简化为一个命令，这是因为 GCC 对如何将多个源文件编译为一个可执行程序有内置的规则。<br />
<code># gcc -o goodbye message.c main.c<br />
# ./goodbye<br />
Goodbye, world!</code></p>
<p>3. 使用外部函数库</p>
<p>GCC 常常与包含标准例程的外部软件库结合使用，几乎每一个 Linux 应用程序都依赖于由 GNU C 函数库 GLIBC。<br />
应用外部函数库的例子：</p>
<blockquote><p>#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#include &lt;math.h&gt;</p>
<p>#define MAX_INPUT 25</p>
<p>int main(int agrc, char **argv)<br />
{<br />
char input[MAX_INPUT];<br />
double angle;</p>
<p>printf(”Give me an angle (in radians) ==&gt;”);<br />
if(!fgets(input, MAX_INPUT, stdin)){<br />
perror(”an error occurred.\n”);<br />
}<br />
angle = strtod(input, NULL);</p>
<p>printf(”sin(%e) = %e\n”, angle, sin(angle));</p>
<p>return 0;<br />
}</p></blockquote>
<p>编译命令：<br />
<code># gcc -o trig -lm trig.c</code></p>
<p>GCC 的”-lm”选项，它告诉 GCC 查看系统提供的数学库（libm）。因为Linux和UNIX的系统函数库通常以”lib”为前缀，所以我们假设它存在。真正的函数库位置随系统的不同而不同，但它一般会位于目录/lib或/usr/lib中，在这些目录中还有数以百计的其他必需的系统函数库。</p>
<p>4. 共享函数库与静态函数库</p>
<p>Linux系统上的函数库分为两种不同的类型：共享的和静态的</p>
<p>静态函数库：每次当应用程序和静态连接的函数库一起编译时，任何引用的库函数中的代码都会被直接包含进最终的二进制程序。</p>
<p>共享函数库：包含每个库函数的单一全局版本，它在所有应用程序之间共享。这一过程背后所涉及的机制相当复杂，但主要依靠的是现代计算机的虚拟内存能力，它允许包含库函数的物理内存安全地在多个独立用户程序之间共享。</p>
<p>使用共享函数库不仅减少了文件的容量和 Linux 应用程序在内存中覆盖的区域，而且它还提高了系统的安全性。一个被许多不同程序同时调用的共享函数库很可能会驻留在内存中，以在需要使用它时被立即使用，而不是位于磁盘的交换分区中。这有助于进一步减少一些大型 Linux 应用程序的装载时间。</p>
<p>将上面的 message.c 作为共享库函数使用的例子：</p>
<p><code># gcc -fPIC -c message.c</code><br />
“PIC”命令行标记告诉 GCC 产生的代码不要包含对函数和变量具体内存位置的引用，这是因为现在还无法知道使用该消息代码的应用程序会将它连接到哪一段内存地址空间。这样编译输出的文件 message.o 可以被用于建立共享函数库，我们只需使用gcc的“-shared”标记即可：<br />
<code># gcc -shared -o libmessage.so message.o</code></p>
<p>将上面的mian.c使用共享库函数ligmessage.so编译：<br />
<code># gcc -o goodbye -lmessage -L. message.o</code><br />
“-lmessage”标记来告诉 GCC 在连接阶段引用共享函数库 libmessage.so 。“-L.”标记告诉 GCC 函数库可能位于当前目录中，否则 GNU 的连接器会查找标准系统函数库目录，在本例的情况下，就找不到可用的函数库了。</p>
<p>此时运行编译好的goodbye会提示找不到共享函数库：<br />
<code>#./goodbye<br />
./goodbye: error while loading shared libraries: libmessage.so: cannot open shared object file: No such file or directory</code></p>
<p>可以使用命令 ldd 来发现一个特定应用程序需要使用的函数库。ldd搜索标准系统函数库路径并显示一个特定程序使用的函数库版本。</p>
<blockquote><p>#ldd goodbye<br />
linux-gate.so.1 =&gt;  (0×00493000)<br />
libmessage.so =&gt; not found<br />
libc.so.6 =&gt; /lib/libc.so.6 (0×0097c000)<br />
/lib/ld-linux.so.2 (0×0095a000)</p></blockquote>
<p>库文件 libmessage.so 不能在任何一个标准搜索路径中找到，而且系统提供的配置文件 /etc/ld.so.conf 也没有包含一个额外的条目来指定包含该库文件的目录。</p>
<p>需要设置一个环境变量LD_LIBRARY_PATH来制定额外的共享函数库搜索路径，<br />
<code># export LD_LIBRARY_PATH=`pwd`<br />
# ldd goodbye<br />
linux-gate.so.1 =&gt;  (0x002ce000)<br />
libmessage.so =&gt; /tmp/cpro/libmessage.so (0x00b0f000)<br />
libc.so.6 =&gt; /lib/libc.so.6 (0x0097c000)<br />
/lib/ld-linux.so.2 (0x0095a000)</code><br />
运行程序<br />
<code># ./goodbye<br />
Goodbye, world!</code></p>
<p>gcc在命令行上经常使用的几个选项是：<br />
-c   只预处理、编译和汇编源程序，不进行连接。编译器对每一个源程序产生一个目标文件。<br />
-o file  确定输出文件为file。如果没有用-o选项，缺省的可执行文件的输出是 a.out，目标文件和汇编文件的输出对source.suffix分别是source.o和source.s，预处理的C源程序的输出是标准输出stdout。<br />
-Dmacro或-Dmacro=defn   其作用类似于源程序里的#define。例如：% gcc -c -DHAVE_GDBM -DHELP_FILE=\”help\” cdict.c其中第一个- D选项定义宏HAVE_GDBM，在程序里可以用#ifdef去检查它是否被设置。第二个-D选项将宏HELP_FILE定义为字符串“help”（由于反斜线的作用，引号实际上已成为该宏定义的一部分），这对于控制程序打开哪个文件是很有用的。<br />
-Umacro   某些宏是被编译程序自动定义的。这些宏通常可以指定在其中进行编译的计算机系统类型的符号，用户可以在编译某程序时加上 -v选项以查看gcc缺省定义了哪些宏。如果用户想取消其中某个宏定义，用-Umacro选项，这相当于把#undef macro放在要编译的源文件的开头。<br />
-Idir   将dir目录加到搜寻头文件的目录列表中去，并优先于在gcc缺省的搜索目录。在有多个-I选项的情况下，按命令行上-I选项的前后顺序搜索。dir可使用相对路径，如-I../inc等。<br />
-O   对程序编译进行优化，编译程序试图减少被编译程序的长度和执行时间，但其编译速度比不做优化慢，而且要求较多的内存。<br />
-O2   允许比-O更好的优化，编译速度较慢，但结果程序的执行速度较快。<br />
-g   产生一张用于调试和排错的扩展符号表。-g选项使程序可以用GNU的调试程序GDB进行调试。优化和调试通常不兼容，同时使用-g和-O（-O2）选项经常会使程序产生奇怪的运行结果。所以不要同时使用-g和-O（-O2）选项。<br />
-fpic或-fPIC   产生位置无关的目标代码，可用于构造共享函数库。<br />
以上是gcc的编译选项。gcc的命令行上还可以使用连接选项。事实上，gcc将所有不能识别的选项传递给连接程序ld。连接程序ld将几个目标文件和库程序组合成一个可执行文件，它要解决对外部变量、外部过程、库程序等的引用。但我们永远不必要显式地调用ld。利用gcc命令去连接各个文件是很简单的，即使在命令行里没有列出库程序，gcc也能保证某些库程序以正确的次序出现。<br />
gcc的常用连接选项有下列几个：<br />
-Ldir   将dir目录加到搜寻-l选项指定的函数库文件的目录列表中去，并优先于gcc缺省的搜索目录。在有多个-L选项的情况下，按命令行上-L选项的前后顺序搜索。dir可使用相对路径。如-L../lib等。<br />
-lname   在连接时使用函数库libname.a，连接程序在-Ldir选项指定的目录下和/lib，/usr/lib目录下寻找该库文件。在没有使用-static选项时，如果发现共享函数库libname.so，则使用libname.so进行动态连接。<br />
-static   禁止与共享函数库连接。<br />
-shared   尽量与共享函数库连接。<br />
这是Linux上连接程序的缺省选项。下面是一个使用gcc进行连接的例子：<br />
<code>% gcc -o prog main.o subr.o -L../lib -lany -lm</code></p>
<p>From:<a href="http://www.ownlinux.cn/2008/11/14/linux-gcc-c/">http://www.ownlinux.cn/2008/11/14/linux-gcc-c/</a></p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/%e6%99%ae%e5%8f%8a%e5%b8%96%ef%bc%9alinux-%e4%b8%8b%e7%bc%96%e8%af%91c%e7%a8%8b%e5%ba%8f.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>坐阵杭州淘宝</title>
		<link>http://www.54chen.com/life/%e5%9d%90%e9%98%b5%e6%9d%ad%e5%b7%9e%e6%b7%98%e5%ae%9d.html</link>
		<comments>http://www.54chen.com/life/%e5%9d%90%e9%98%b5%e6%9d%ad%e5%b7%9e%e6%b7%98%e5%ae%9d.html#comments</comments>
		<pubDate>Wed, 17 Dec 2008 07:05:22 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[生活备份]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[备忘]]></category>

		<guid isPermaLink="false">http://www.54chen.com/life/%e5%9d%90%e9%98%b5%e6%9d%ad%e5%b7%9e%e6%b7%98%e5%ae%9d.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>照片欠奉。 涉及到技术转型，看到一句话，共勉。 如果程序语言是宗教，那么： C语言是犹太教，Java是基督教，c++是回教. C#是摩門教，LISP是禪宗佛教，PHP是Cafeteria基督教，Haskell是道教，Erlang是印度教，Perl是伏都教，Lua是巫术，Ruby是新异教主义，Python是世俗人文主义，COBOL是古异教主义，APL是山达基教，Visual Basic是撒旦教。<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>照片欠奉。</p>
<p>涉及到技术转型，看到一句话，共勉。</p>
<p>如果程序语言是宗教，那么： C语言是犹太教，Java是基督教，c++是回教. C#是摩門教，LISP是禪宗佛教，PHP是Cafeteria基督教，Haskell是道教，Erlang是印度教，Perl是伏都教，Lua是巫术，Ruby是新异教主义，Python是世俗人文主义，COBOL是古异教主义，APL是山达基教，Visual Basic是撒旦教。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/life/%e5%9d%90%e9%98%b5%e6%9d%ad%e5%b7%9e%e6%b7%98%e5%ae%9d.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>究竟什么是TSRMLS_CC？</title>
		<link>http://www.54chen.com/php-tech/what-is-tsrmls_cc.html</link>
		<comments>http://www.54chen.com/php-tech/what-is-tsrmls_cc.html#comments</comments>
		<pubDate>Wed, 03 Dec 2008 11:21:30 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[资料文档]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php扩展]]></category>

		<guid isPermaLink="false">http://www.54chen.com/php-tech/what-is-tsrmls_cc.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>翻译：54chen.com 原文地址：http://blog.libssh2.org/index.php?/archives/22-What-the-heck-is-TSRMLS_CC-anyway.html 如果你曾经做过php内核或者是php扩展方面的工作，你一定见到过这个到处都是的结构，但是却从来没有人提起过它。知道这是什么的人典型回答不知道的人都会这样说：“不用管它是什么，只需要在这里、这里还有这里用，如果编译器说少一个tsrm_ls，就加一个...”。这样回答并非都是因为这个人懒惰（的确是有一点点懒），其实那只是在说引擎甚至可以不管这个神奇的值在简化什么，这是因为一个新入门的扩展开发者知道它的结构没有什么益处。这信息就像奶牛的意见一样，没关系，就是牛叫而已。 既然我喜欢听自己喋喋不休的无意义主题（这个月我已经少写很多博客了），我想我得弥补这一主题，看看会不会有人通过他能领会什么。你可以责怪Lukas(Lukas Smith 是 PEAR DB 的主要作者应该是这个Lukas，译者注)，他让我一直在planet-php.net上。 术语 TSRM Thread Safe Resource Manager - 这是一个经常被忽视的层面，就会有也是很少被讨论到，在你的PHP源代码包中，它被隐藏在/TSRM目录中。默认情况下，TSRM 层只在编译需要它的SAPI的时候才会打开（例如apache2-worker）。所有的在win32下编译的SAPI都会有TSRM层而不会管它们是否需要。 ZTS Zend Thread Ssafety -通常情况下，与TSRM有相同的用处。具体来说不同在于，ZTS的使用需要在编译的时候加上参数如./configure ( --enable-experimental-zts for PHP4, --enable-maintainer-zts for PHP5），而TSRM是否被使用是由#define的预处理机制来确定的。 tsrm_ls TSRM local storage - 当ZTS可用时，这是它在TSRMLS_*宏里传来传去的实际的变量名。它作为一个指向那个线程的独立数据存储块开始位置的指针，我会在一会儿后将它覆盖掉。 TSRMLS_?? 有四个宏设计来为了使ZTS模式和非ZTS模式之间的差异变得平滑，当ZTS不能用时，这四个宏同时都没有任何用处。而在ZTS启用的时候，它们扩大了以下的定义： TSRMLS_C   tsrm_ls TSRMLS_D   void &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><blockquote><p>翻译：<a href="http://www.54chen.com">54chen.com</a></p></blockquote>
<p>原文地址：<a href="http://blog.libssh2.org/index.php?/archives/22-What-the-heck-is-TSRMLS_CC-anyway.html">http://blog.libssh2.org/index.php?/archives/22-What-the-heck-is-TSRMLS_CC-anyway.html</a></p>
<p>如果你曾经做过php内核或者是<a href="http://www.54chen.com/c/91">php扩展</a>方面的工作，你一定见到过这个到处都是的结构，但是却从来没有人提起过它。知道这是什么的人典型回答不知道的人都会这样说：“不用管它是什么，只需要在这里、这里还有这里用，如果编译器说少一个tsrm_ls，就加一个...”。这样回答并非都是因为这个人懒惰（的确是有一点点懒），其实那只是在说引擎甚至可以不管这个神奇的值在简化什么，这是因为一个新入门的扩展开发者知道它的结构没有什么益处。这信息就像奶牛的意见一样，没关系，就是牛叫而已。</p>
<p>既然我喜欢听自己喋喋不休的无意义主题（这个月我已经少写很多博客了），我想我得弥补这一主题，看看会不会有人通过他能领会什么。你可以责怪Lukas(Lukas Smith 是 PEAR DB 的主要作者应该是这个Lukas，译者注)，他让我一直在<a href="http://www.planet-php.net/">planet-php.net</a>上。</p>
<p><strong>术语</strong></p>
<p>TSRM</p>
<p><strong>T</strong>hread <strong>S</strong>afe <strong>R</strong>esource <strong>M</strong>anager - 这是一个经常被忽视的层面，就会有也是很少被讨论到，在你的<a href="http://www.54chen.com/c/61">PHP源代码</a>包中，它被隐藏在/TSRM目录中。默认情况下，TSRM 层只在编译需要它的SAPI的时候才会打开（例如apache2-worker）。所有的在win32下编译的SAPI都会有TSRM层而不会管它们是否需要。</p>
<p>ZTS</p>
<p><strong>Z</strong>end <strong>T</strong>hread <strong>S</strong>safety -通常情况下，与TSRM有相同的用处。具体来说不同在于，ZTS的使用需要在编译的时候加上参数如<span style="font-family: courier;">./configure</span> ( <span style="font-family: courier;">--enable-experimental-zts</span> for PHP4, <span style="font-family: courier;">--enable-maintainer-zts</span> for PHP5），而TSRM是否被使用是由#define的预处理机制来确定的。</p>
<p>tsrm_ls</p>
<p>TSRM <strong>l</strong>ocal <strong>s</strong>torage - 当ZTS可用时，这是它在TSRMLS_*宏里传来传去的实际的变量名。它作为一个指向那个线程的独立数据存储块开始位置的指针，我会在一会儿后将它覆盖掉。</p>
<p>TSRMLS_??</p>
<p>有四个宏设计来为了使ZTS模式和非ZTS模式之间的差异变得平滑，当ZTS不能用时，这四个宏同时都没有任何用处。而在ZTS启用的时候，它们扩大了以下的定义：</p>
<li><span style="font-family: courier;">TSRMLS_C   tsrm_ls</span></li>
<li><span style="font-family: courier;">TSRMLS_D   void ***tsrm_ls</span></li>
<li><span style="font-family: courier;">TSRMLS_CC  , tsrm_ls</span></li>
<li><span style="font-family: courier;">TSRMLS_DC  , void ***tsrm_ls</span></li>
<p><span style="font-family: Courier;"><strong>综述</strong></span></p>
<p><span style="font-family: Courier;">在任何普通的C程序（PHP也一样）中，要在两个不同的函数间传递相同的数据块，你两种办法。</span></p>
<p><span style="font-family: Courier;">第一种方法是通过函数的参数传递值：</span></p>
<blockquote>
<pre>#include &lt;stdio.h&gt;

void output_func(char *message)
{
    printf("%s\n", message);
}

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

    return 0;
}</pre>
</blockquote>
<pre>另一种方法，你可以把这个值保存在一个上层的全局变量中，让函数通过它来取得：</pre>
<blockquote>
<pre>#include &lt;stdio.h&gt;

char *message;

void output_func(void)
{
    printf("%s\n", message);
}

int main(int argv, char *argv[])
{
    message = argv[0];
    output_func();

    return 0;
}</pre>
</blockquote>
<p>这两种方法各有优点和缺点，而且在在实际应用中你常常会看到两者结合使用。事实上，PHP里到处都是全局变量，从类型标识符，到函数回调指针，再到请求特殊的信息例如用于存储用户空间变量的符号表。试图通过函数参数的方法来传递那些变量是不方便的，例如PHP这样的应用常常会需要去注册回调方法来给不支持上下文数据的外部的库使用，此时使用参数传递是不可能的。</p>
<p>因此，共同的信息，像执行栈、函数表、类表以及扩展登记表都是在全局范围里进行声明的，以便它们能在整个应用的任何一个位置都能使用。对于单线程的SAPIs，例如CLI、APACHE1，或者甚至Apache2-prefork，这样做都是完美的。在RINIT/Activation 阶段，请求具体结构被初始化，并在RSHUTDOWN/Deactivation 阶段重新设置回初始的值等待下一次的请求。一个像APACHE1这样特定的WEB服务器，可以一次处理多个页面，是因为它会产生多个进程，每个进程会在自己的进程空间内使用自己的全局变量副本。</p>
<p>现在，让我们来介绍像Apache2-worker或者IIS这样的线程服务器。在这种情况下，在指定时间里只有一个进程空间是可用的，由它抛出多线程处理。每一个线程都会类似一个单独的进程的方式工作。在处理请求的时候服务会一次一个地来。当两个或者多个<a href="http://www.54chen.com/c/71">线程</a>去处理同一时间的一个请求的时候，麻烦就出现了。每个<a href="http://www.54chen.com/c/73">线程</a>都试图去使用全局变量来保存它的特定请求信息，并尝试写向同样的存储空间。这样子最少会导致一个脚本里声明的用户空间变量在另一个脚本中出现。而在实践中，这样会导致快速灾难性的错误和不可预测的情况，因为内存可以释放两次或者独立的线程写了相互矛盾的信息。</p>
<p><strong>不全的全局</strong></p>
<p>解决方案需要一个引擎、一个核心，还有任何一个使用全局存储的<a href="http://www.54chen.com/c/91">扩展</a>都要决定会使用多少内存给具体的请求数据。然后，在运行的每一个新的线程中，给它们每个分配一块内存，用来存储它们的数据，从而使每个线程都有自己的本地存储。为了把所有的被指定线程用到的内存块聚成一组，最后一个指针向量被开辟来保存子结构的指针。这个指针指向tsrm_ls变量，被TSRMLS_*家族的宏所使用。为了看清它是怎么工作的，我们先来看一个扩展的例子：</p>
<blockquote>
<pre>typedef struct _zend_myextension_globals {
    int foo;
    char *bar;
} zend_myextension_globals;

#ifdef ZTS
int myextension_globals_id;
#else
zend_myextension_globals myextension_globals;
#endif

/* Triggered at the beginning of a thread */
static void php_myextension_globals_ctor(zend_myextension_globals *myext_globals TSRMLS_DC)
{
    myext_globals-&gt;foo = 0;
    myext_globals-&gt;bar = NULL;
}

/* Triggered at the end of a thread */
static void php_myextension_globals_dtor(zend_myextension_globals *myext_globals TSRMLS_DC)
{
    if (myext_globals-&gt;bar) {
        efree(myext_globals-&gt;bar);
    }
}

PHP_MINIT_FUNCTION(myextension)
{
#ifdef ZTS
    ts_allocate_id(&amp;myextension_globals_id, sizeof(zend_myextension_globals),
                   php_myextension_globals_ctor, php_myextension_globals_dtor);
#else
    php_myextension_globals_ctor(&amp;myextension_globals TSRMLS_CC);
#endif

    return SUCCESS;
}

PHP_MSHUTDOWN_FUNCTION(myextension)
{
#ifndef ZTS
    php_myextension_globals_dtor(&amp;myextension_globals TSRMLS_CC);
#endif

    return SUCCESS;
}</pre>
</blockquote>
<p>这里可以看到，扩展在启动的时候声明了它全局需求的变量给TSRM层，它需要sizeof(zend_myextension_globals)字节的存储，并且在初始化或者销毁指定的线程的本地存储的时候提供了回调函数。myextension_globals_id里的值可得出偏移量（对所有线程是公共的），存储于tsrm_ls向量，指向那个线程本地存储的指针中也是这个向量。如果ZTS不能用，数据存储只不过是放在真实的全局环境中，并且在线程初始和销毁的过程中需要手动执行初始化和销毁的程序。如果你现在想知道为什么<span style="font-family: courier;">TSRMLS_CC</span> 被包含在非ZTS块中，那我可以很确定我没有使你看睡着了。这些都是不是必须的，因为我们知道非ZTS里他们有和没有一个样，但这有助于鼓励函数原型调用时引用它们的好习惯。</p>
<p><strong>把它们聚在一起</strong></p>
<p>最后一块线程安全的疑惑来自于一个问题：“我如何获得这些数据结构？”这个问题的答案来自于另一个有着相似样子的宏。在每个扩展或者是核心组件定义的头文件中，有一个宏的定义如下所示：</p>
<blockquote>
<pre>#ifdef ZTS
# define   MYEXTENSION_G(v)     \
             (((zend_myextension_globals*)(*((void ***)tsrm_ls))[(myextension_globals_id)-1])-&gt;v)
#else
# define   MYEXTENSION_G(v)     (myextension_globals.v)
#endif</pre>
</blockquote>
<p>因此，当ZTS不可用时，这个宏简单地收集来自全局环境中的即时值作用正确的值，否则，它将根据ID将结构开辟在本线程的本地存储拷贝中，并且从那里引用到值。</p>
<p>【结束：54chen.com】</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/php-tech/what-is-tsrmls_cc.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>sscanf函数的各种用法</title>
		<link>http://www.54chen.com/php-tech/sscanf%e5%87%bd%e6%95%b0%e7%9a%84%e5%90%84%e7%a7%8d%e7%94%a8%e6%b3%95.html</link>
		<comments>http://www.54chen.com/php-tech/sscanf%e5%87%bd%e6%95%b0%e7%9a%84%e5%90%84%e7%a7%8d%e7%94%a8%e6%b3%95.html#comments</comments>
		<pubDate>Tue, 02 Dec 2008 08:05:10 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[php扩展]]></category>
		<category><![CDATA[sscanf]]></category>

		<guid isPermaLink="false">http://www.54chen.com/php-tech/sscanf%e5%87%bd%e6%95%b0%e7%9a%84%e5%90%84%e7%a7%8d%e7%94%a8%e6%b3%95.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>sscanf是一个运行时函数，原形很简单：  int sscanf(  const char *buffer,  const char *format [,  argument ] ...  );  它强大的功能体现在对format的支持上。  sscanf与scanf类似，都是用于输入的，只是后者以屏幕(stdin)为输入源，前者以固定字符串为输入源。  　   char str[512] = ;  　　sscanf("123456 ", "%s", str);  　　printf("str=%s", str); 输出 str=123456 　   sscanf("123456 ", "%4s", str);  　　printf("str=%s", str); 输出 str = 1234 　　sscanf("123456 abcdedf", "%[^ ]", str);  　　printf("str=%s", str); 输出 str=123456 (遇到空格为止) 　　sscanf("123456abcdedfBCDEF", "%[^A-Z]", str);  　　printf("str=%s", str); 输出 str=123456abcdef (遇到指定字符为止) &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><div>
<p>sscanf是一个运行时函数，原形很简单： <br />
int sscanf( <br />
const char *buffer, <br />
const char *format [, <br />
argument ] ... <br />
); <br />
它强大的功能体现在对format的<a href="http://www.54chen.com/c/132">支持</a>上。 </p>
<p>sscanf与scanf类似，都是用于<a href="http://www.54chen.com/c/75">输入</a>的，只是后者以屏幕(stdin)为输入源，前者以固定字符串为输入源。 </p>
<blockquote><p>　   char str[512] = ; <br />
　　sscanf("123456 ", "%s", str); <br />
　　printf("str=%s", str);</p></blockquote>
<p><a href="http://www.54chen.com/c/61">输出</a> str=123456</p>
<blockquote><p>　   sscanf("123456 ", "%4s", str); <br />
　　printf("str=%s", str);</p></blockquote>
<p>输出 str = 1234</p>
<blockquote><p>　　sscanf("123456 abcdedf", "%[^ ]", str); <br />
　　printf("str=%s", str);</p></blockquote>
<p>输出 str=123456 (遇到<a href="http://www.54chen.com/c/22">空格</a>为止)</p>
<blockquote><p>　　sscanf("123456abcdedfBCDEF", "%[^A-Z]", str); <br />
　　printf("str=%s", str);</p></blockquote>
<p>输出 str=123456abcdef (遇到指定<a href="http://www.54chen.com/c/22">字符</a>为止)</p>
<blockquote><p>sscanf(mod, "%s", mod);//去除空格</p></blockquote>
</div>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/php-tech/sscanf%e5%87%bd%e6%95%b0%e7%9a%84%e5%90%84%e7%a7%8d%e7%94%a8%e6%b3%95.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

