﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Prayer</title><link>http://www.cppblog.com/prayer/</link><description>在一般中寻求卓越</description><language>zh-cn</language><lastBuildDate>Sun, 19 Apr 2026 17:33:38 GMT</lastBuildDate><pubDate>Sun, 19 Apr 2026 17:33:38 GMT</pubDate><ttl>60</ttl><item><title>DB2 缓冲池调优Bufferpools</title><link>http://www.cppblog.com/prayer/archive/2019/06/24/216446.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Mon, 24 Jun 2019 02:09:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/06/24/216446.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216446.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/06/24/216446.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216446.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216446.html</trackback:ping><description><![CDATA[<div>https://blog.csdn.net/liujinwei2005/article/details/8547190<br /><h1>DB2 缓冲池调优Bufferpools</h1><br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word; color: #333333; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun; background-color: #ffffff;" /><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"></p><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 24px; word-wrap: break-word; overflow-x: auto; color: #333333; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun; background-color: #ffffff;"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="box-sizing: border-box; outline: 0px; margin: 0px auto; padding: 0px; border-collapse: collapse; border-spacing: 0px; width: 712px; word-wrap: break-word;"><tbody style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; border: 0px; word-wrap: break-word;"><tr style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; border-width: 1px 0px 0px; border-top-style: solid; border-top-color: #dddddd; word-wrap: break-word;"><td style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 8px; word-wrap: break-word; border-style: solid; border-color: #dddddd; font-size: 14px; color: #4f4f4f; line-height: 22px;"><div id="art" style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">背景知识</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">缓冲池是内存中的一块存储区域，用于临时读入和更改<a target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #4ea1db; cursor: pointer; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;"><u style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-weight: 700; word-wrap: break-word;">数据库</span></u></a>页（包含表行或索引项）。缓冲池的用途是为了提高数据库系统的性能。从内存访问数据要比从磁盘访问数据快得多。因此，数据库<a target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #4ea1db; cursor: pointer; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;"><u style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-weight: 700; word-wrap: break-word;">管理</span></u></a>器需要从磁盘读取或写入磁盘的次数越少，性能就越好。对一个或多个缓冲池进行配置之所以是调优的最重要方面，是因为连接至数据库的应用程序的大多数数据（不包括大对象和长字段数据）操作都在缓冲池中进行。</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">缺省情况下，应用程序使用缓冲池 IBMDEFAULTBP，它是在创建数据库时创建的。当 SYSCAT.BUFFERPOOLS 目录表中该缓冲池的 NPAGES 值为 -1 时，<a target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #4ea1db; cursor: pointer; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;"><u style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-weight: 700; word-wrap: break-word;">DB2</span></u></a>&nbsp;数据库配置参数 BUFFPAGE 控制着缓冲池的大小。否则会忽略 BUFFPAGE 参数，并且用 NPAGES 参数所指定的页数创建缓冲池。</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">建议</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">对于仅使用一个缓冲池的应用程序，将 NPAGES 更改成 -1，这样 BUFFPAGE 就可以控制该缓冲池的大小。这使得更新和报告缓冲池大小以及其它 DB2 数据库配置参数变得更加方便。</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">确保可以使用数据库配置中的 BUFFPAGE 参数来控制缓冲池大小之后，将该参数设置成合适的值。根据数据库的大小和应用程序的性质将该参数设置成一个合理的大值，这种做法很安全。通常，该参数的缺省值非常小，可能满足不了要求。请考虑下列情况：</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">一开始，如果您的机器上有足够大的内存，请将 BUFFPAGE 设置成 40000 个页（160 MB），或者等于机器总内存的 10%。&nbsp;</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">对于大型 OLTP 数据库，在保持系统稳定的同时为缓冲池留出尽可能多的内存。一开始，先尝试使用 1.6 GB 的内存，然后尝试用更多内存。&nbsp;</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">如何更改该参数</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">运行下面这个脚本，以便：&nbsp;</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">验证目录值&nbsp;</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">启用数据库配置参数 BUFFPAGE&nbsp;</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">更新所有数据库的 BUFFPAGE 值。&nbsp;</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v connect to DB_NAME</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v select * from syscat.bufferpools</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v alter bufferpool IBMDEFAULTBP size -1</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v connect reset</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v update db cfg for dbname using BUFFPAGE bigger_value</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v terminate</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">研究步骤</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">要确定数据库的缓冲池大小是否由 BUFFPAGE 参数所决定，请运行：</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v connect to DB_NAME</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v SELECT * from SYSCAT.BUFFERPOOLS</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v connect reset</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v terminate</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">检查结果。如果每个缓冲池都有一个为&#8220;-1&#8221;的 NPAGES 值，那么缓冲池大小是由数据库配置中的 BUFFPAGE 参数控制的。</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">要确定缓冲池大小是否足够大，请在运行应用程序时收集数据库和／或缓冲池的快照。类似于下面的脚本为您提供这些所需的信息：</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v update monitor switches using bufferpool on</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v get monitor switches</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v reset monitor all</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">-- run your application --</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v get snapshot for all databases &gt; snap.out</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v get snapshot for dbm &gt;&gt; snap.out</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v get snapshot for all bufferpools &gt;&gt; snap.out</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v reset monitor all</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">db2 -v terminate</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">请确保您在断开数据库连接之前发出&#8220;db2 -v get snapshot&#8221;。当最后一个应用程序与数据库断开连接时，该数据库停止运行，同时所有快照统计信息将会丢失。要确保一直存在使数据库处于正常运行状态的连接，请使用下列方法之一：</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">在收集快照的窗口中保持一个单独的连接。&nbsp;</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">使用 DB2 ACTIVATE DATABASE 命令。</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">在数据库快照或缓冲池快照的快照输出中，查找下列&#8220;logical reads&#8221;和&#8220;physical reads&#8221;，这样就可以计算出缓冲池命中率，它可以帮助您调优缓冲池：</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">-- Related lines from a sample of bufferpool snapshots --</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">Buffer pool&nbsp;<a target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #4ea1db; cursor: pointer; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;"><u style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-weight: 700; word-wrap: break-word;">data</span></u></a>&nbsp;logical reads = 702033</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">Buffer pool data physical reads = 0</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">Buffer pool data writes = 414</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">Buffer pool index logical reads = 168255</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">Buffer pool index physical reads = 0</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">缓冲池命中率表明数据库管理器不需要从磁盘装入页（即该页已经在缓冲池中）就能处理页请求的时间百分比。缓冲池的命中率越高，使用磁盘 I/O 的频率就越低。按如下计算缓冲池命中率：</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">(1 - ((buffer pool data physical reads + buffer pool index physical reads) /</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">(buffer pool data logical reads + pool index logical reads))</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">) * 100%</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">这个计算考虑了缓冲池高速缓存的所有页（索引和数据）。理想情况下，该比率应当超过 95%，并尽可能接近 100%。要提高缓冲池命中率，请尝试下面这些方法：</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">增加缓冲池大小。&nbsp;</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">考虑分配多个缓冲池，如果可能的话，为每个经常被访问的大表所属的表空间分配一个缓冲池，为一组小表分配一个缓冲池，然后尝试一下使用不同大小的缓冲池以查看哪种组合会提供最佳性能。&nbsp;</div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;"></div><div style="box-sizing: border-box; outline: 0px; margin: 0px; word-wrap: break-word;">如果已分配的内存不能帮助提高性能，那么请避免给缓冲池分配过多的内存。应当根据取自测试环境的快照信息来决定缓冲池的大小。</div></div></td></tr></tbody></table></div><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">缓冲池命中率</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">这个比率说明了为页面请求提供服务时，数据库管理器不需从磁盘装入页（即该页已经在缓冲池中）就能处理页请求的时间百分比。</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">计算：</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">BPHR = (1 - ((缓冲池数据物理读 + 缓冲池索引物理读) /</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">(缓冲池数据逻辑读 + 缓冲池索引逻辑读) ) ) * 100%</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">索引命中率</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">这个比率表明了可以在缓冲池中找到的页面能够满足的对索引页的所有读请求所占的百分比。</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">计算：</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">IHR = (1 - (缓冲池索引物理读 / 缓冲池索引逻辑读) ) ) * 100%</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">数据命中率</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">这个比率说明了可以在缓冲池中找到的页面能够满足的对数据页的所有读请求所占的百分比。</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">计算：</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">DHR = (1 - (缓冲池数据物理读 / 缓冲池数据逻辑读) ) ) * 100%</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">结论</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">缓冲池命中率大于 80% 被认为是理想的。对于 OLTP 系统来说，该值的理想情况是尽可能接近于 100% （索引命中率更是如此）。</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4d4d4d; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">要提高缓冲池的命中率，可以增加缓冲池的大小，也可以考虑分配多个缓冲池，可以为每个经常访问的具有自己的表空间的大型表使用一个缓冲池，也可以为一组小型表使用一个缓冲池。</p></div><img src ="http://www.cppblog.com/prayer/aggbug/216446.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-06-24 10:09 <a href="http://www.cppblog.com/prayer/archive/2019/06/24/216446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UltraEdit设置主题</title><link>http://www.cppblog.com/prayer/archive/2019/06/03/216394.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Mon, 03 Jun 2019 10:20:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/06/03/216394.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216394.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/06/03/216394.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216394.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216394.html</trackback:ping><description><![CDATA[<div>https://blog.csdn.net/haifeilang/article/details/54959450<br /><div>每次下载最新的UltraEdit，默认主题是黑色，很不适应，想更改主题又常常找不到在哪里，</div><div></div><div>最新Ultraedit设置主题和老版本不太一样，所以网上经验没太大帮助。</div><div></div><div></div><div></div><div>记录到博客，以备不时之需：</div><div></div><div></div><div></div><div>Ultraedit --&gt;布局（Layout）--&gt;主题（Themes）</div><div></div><div></div><div></div><div>&nbsp; &nbsp; &nbsp;&nbsp;</div><div></div><div></div><div></div><div>选择自己喜欢的主题吧！</div><div>---------------------&nbsp;</div><div>作者：haifeilang&nbsp;</div><div>来源：CSDN&nbsp;</div><div>原文：https://blog.csdn.net/haifeilang/article/details/54959450&nbsp;</div><div>版权声明：本文为博主原创文章，转载请附上博文链接！</div></div><img src ="http://www.cppblog.com/prayer/aggbug/216394.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-06-03 18:20 <a href="http://www.cppblog.com/prayer/archive/2019/06/03/216394.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>nm命令中符号类型详解</title><link>http://www.cppblog.com/prayer/archive/2019/04/10/216346.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Wed, 10 Apr 2019 06:28:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/04/10/216346.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216346.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/04/10/216346.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216346.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216346.html</trackback:ping><description><![CDATA[<p style="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: #2f2f2f; font-size: 16px; line-height: 24px; background-color: #ffffff;">nm命令介绍的很多，但大多不介绍其函数符号标志的含义。<br />最近在调试动态库时常用到，其中用的最多的用法:<br />nm -A * |grep &#8220;aaa&#8221; | c++filt&nbsp; // -A 为了显示文件， c++filt转换为可读风格，好像有个参数也能实现类似功能</p><p style="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: #2f2f2f; font-size: 16px; line-height: 24px; background-color: #ffffff;"><br />其他内容整理如下（原作者未知):</p><p style="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: #2f2f2f; font-size: 16px; line-height: 24px; background-color: #ffffff;"><span style="font-family: 'Times New Roman'; font-size: 12pt;"><span style="font-family: inherit; background-color: #fffe65;">nm</span></span><span style="font-family: 宋体; font-size: 12pt;">用于列出目标文件的符号清单，如果没有指定目标文件，则默认为&#8220;</span><span style="font-family: 'Times New Roman'; font-size: 12pt;">a.out</span><span style="font-family: 宋体; font-size: 12pt;">&#8221;。</span><span style="font-family: 'Times New Roman'; font-size: 12pt;"><span style="font-family: inherit; background-color: #fffe65;">nm</span></span><span style="font-family: 宋体; font-size: 12pt;">的格式如下：</span></p><p style="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: #2f2f2f; font-size: 16px; line-height: 24px; background-color: #ffffff;"><span style="font-family: 宋体; font-size: 12pt;"><span style="font-family: inherit; font-size: 9pt;"><span style="font-family: Arial; font-size: small;"><span style="font-family: inherit; background-color: #fffe65;">nm</span>&nbsp;[&#8216;-a&#8217;|&#8216;--debug-syms&#8217;] [&#8216;-g&#8217;|&#8216;--extern-only&#8217;]</span></span><br /><span style="font-family: Arial;"><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&#8216;-B&#8217;] [&#8216;-C&#8217;|&#8216;--demangle&#8217;[=style]] [&#8216;-D&#8217;|&#8216;--dynamic&#8217;]</span></span></span><br /><span style="font-family: Arial;"><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&#8216;-S&#8217;|&#8216;--print-size&#8217;] [&#8216;-s&#8217;|&#8216;--print-armap&#8217;]</span></span></span><br /><span style="font-family: Arial;"><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&#8216;-A&#8217;|&#8216;-o&#8217;|&#8216;--print-file-name&#8217;][&#8216;--special-syms&#8217;]</span></span></span><br /><span style="font-family: Arial;"><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&#8216;-n&#8217;|&#8216;-v&#8217;|&#8216;--numeric-sort&#8217;] [&#8216;-p&#8217;|&#8216;--no-sort&#8217;]</span></span></span><br /><span style="font-family: Arial;"><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&#8216;-r&#8217;|&#8216;--reverse-sort&#8217;] [&#8216;--size-sort&#8217;] [&#8216;-u&#8217;|&#8216;--undefined-only&#8217;]</span></span></span><br /><span style="font-family: Arial;"><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&#8216;-t&#8217; radix|&#8216;--radix=&#8217;radix] [&#8216;-P&#8217;|&#8216;--portability&#8217;]</span></span></span><br /><span style="font-family: Arial;"><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&#8216;--target=&#8217;bfdname] [&#8216;-f&#8217;format|&#8216;--format=&#8217;format]</span></span></span><br /><span style="font-family: Arial;"><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&#8216;--defined-only&#8217;] [&#8216;-l&#8217;|&#8216;--line-numbers&#8217;] [&#8216;--no-demangle&#8217;]</span></span></span><br /><span style="font-family: inherit; font-size: small;"><span style="font-family: Arial;"><span style="font-family: inherit; font-size: 9pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="font-family: Arial;">&nbsp;<span style="font-family: inherit; font-size: 9pt;">[&#8216;-V&#8217;|&#8216;--version&#8217;] [&#8216;-X 32_64&#8217;] [&#8216;--help&#8217;] [objfile...]</span></span></span><br /><span style="font-family: Arial;"><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit; font-size: 9pt;">&nbsp;&nbsp;</span></span></span><br /><span style="font-family: inherit; font-size: small;">对于每一个符号，<span style="font-family: inherit; background-color: #fffe65;">nm</span>列出其值(the symbol value)，类型（the symbol type）和其名字(the symbol name)。</span><br /><span style="font-family: inherit; font-size: 12pt;">如下例：</span><br /><span style="font-family: inherit; font-size: 12pt;">&nbsp;&nbsp;</span><br />&nbsp;&nbsp;&nbsp;&nbsp; 00000024 T cleanup_before_linux<br />&nbsp;&nbsp;&nbsp;&nbsp; 00000018 T cpu_init<br /><span style="font-family: inherit; font-size: 9pt;"><span style="font-family: inherit; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00000060 T dcache_disable</span></span><br /><span style="font-family: inherit; font-size: 9pt;"><span style="font-family: inherit; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00000054 T dcache_enable</span></span><br /><span style="font-family: inherit; font-size: 9pt;"><span style="font-family: inherit; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp; 0000006c T dcache_status</span></span><br /><span style="font-family: inherit; font-size: 9pt;"><span style="font-family: inherit; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp; 00000000 T do_reset</span></span><br /><span style="font-family: inherit; font-size: 9pt;"><span style="font-family: inherit; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp; 0000003c T icache_disable</span></span><br /><span style="font-family: inherit; font-size: 9pt;"><span style="font-family: inherit; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp; 00000030 T icache_enable</span></span><br /><span style="font-family: inherit; font-size: 9pt;"><span style="font-family: inherit; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp; 00000048 T icache_status</span></span><br /><span style="font-family: inherit; font-size: 9pt;"><span style="font-family: inherit; font-size: small;">&nbsp;<br />上面的显示是使用<span style="font-family: inherit; background-color: #fffe65;">nm</span>&nbsp;cpu.o的输出，对于cleanup_before_linux这个符号来说，00000024是以16进制显示的其值，T为其类型，而cleanup_before_linux是其名字。可以看出，上面显示的<span style="font-family: inherit; color: blue;">cleanup_before_linux</span><span style="font-family: inherit; color: blue;">这个</span><span style="font-family: inherit; color: blue;">symbol</span><span style="font-family: inherit; color: blue;">的值实际上是该函数在</span><span style="font-family: inherit; color: blue;">text section</span><span style="font-family: inherit; color: blue;">中的偏移。但是，每个符号的值的具体含义依其类型而异</span>。当然，对于每个符号的值，其类型、其值以及它们所属的section是密切相关的。<br />下面说明符号类型：<span style="font-family: inherit; font-size: 12pt;">对于每一个符号来说，其类型如果是小写的，则表明该符号是</span><span style="font-family: inherit; font-size: 12pt;">local</span><span style="font-family: inherit; font-size: 12pt;">的；大写则表明该符号是</span><span style="font-family: inherit; font-size: 12pt;">global(external)</span><span style="font-family: inherit; font-size: 12pt;">的。</span></span></span></span></p><table border="1" cellpadding="0" cellspacing="0" style="color: #2f2f2f; font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff; border-collapse: collapse; margin-left: 14.4pt;"><tbody><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; width: 36pt; border: 1.5pt double silver;"><strong><span style="font-family: inherit; font-size: 9pt;">符号</span></strong><br /><strong><span style="font-family: inherit; font-size: 9pt;">类型</span></strong></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: 1.5pt 1.5pt 1.5pt medium; border-style: double double double none; width: 378pt; border-top-color: silver; border-right-color: silver;"><strong><span style="font-family: inherit; font-size: 9pt;">说明</span></strong></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">A</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号的值是绝对的，在以后的链接过程中，不允许进行改变。这样的<span style="font-family: inherit; color: blue;">符号值，常常出现在中断向量表中，例如用符号来表示各个中断向量函数在中断向量表中的位置。</span></span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">B</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号的值出现在非初始化数据段</span><span style="font-family: inherit; font-size: 9pt;">(bss)</span><span style="font-family: inherit; font-size: 9pt;">中。例如，<span style="font-family: inherit; color: blue;">在一个文件中定义全局</span></span><span style="font-family: inherit; color: blue; font-size: 9pt;">static int test</span><span style="font-family: inherit; color: blue; font-size: 9pt;">。则该符号</span><span style="font-family: inherit; color: blue; font-size: 9pt;">test</span><span style="font-family: inherit; color: blue; font-size: 9pt;">的类型为</span><span style="font-family: inherit; color: blue; font-size: 9pt;">b</span><span style="font-family: inherit; color: blue; font-size: 9pt;">，位于</span><span style="font-family: inherit; color: blue; font-size: 9pt;">bss section</span><span style="font-family: inherit; color: blue; font-size: 9pt;">中。其值表示该符号在</span><span style="font-family: inherit; color: blue; font-size: 9pt;">bss</span><span style="font-family: inherit; color: blue; font-size: 9pt;">段中的偏移。一般而言，</span><span style="font-family: inherit; color: blue; font-size: 9pt;">bss</span><span style="font-family: inherit; color: blue; font-size: 9pt;">段分配于</span><span style="font-family: inherit; color: blue; font-size: 9pt;">RAM</span><span style="font-family: inherit; color: blue; font-size: 9pt;">中</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">C</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号为</span><span style="font-family: inherit; font-size: 9pt;">common</span><span style="font-family: inherit; font-size: 9pt;">。</span><span style="font-family: inherit; font-size: 9pt;">common symbol</span><span style="font-family: inherit; font-size: 9pt;">是未初始话数据段。<span style="font-family: inherit; color: blue;">该符号没有包含于一个普通</span></span><span style="font-family: inherit; color: blue; font-size: 9pt;">section</span><span style="font-family: inherit; color: blue; font-size: 9pt;">中。只有在链接过程中才进行分配。符号的值表示该符号需要的字节数。例如在一个</span><span style="font-family: inherit; color: blue; font-size: 9pt;">c</span><span style="font-family: inherit; color: blue; font-size: 9pt;">文件中，定义</span><span style="font-family: inherit; color: blue; font-size: 9pt;">int test</span><span style="font-family: inherit; color: blue; font-size: 9pt;">，并且该符号在别的地方会被引用，则该符号类型即为</span><span style="font-family: inherit; color: blue; font-size: 9pt;">C</span><span style="font-family: inherit; color: blue; font-size: 9pt;">。否则其类型为</span><span style="font-family: inherit; color: blue; font-size: 9pt;">B</span><span style="font-family: inherit; color: blue; font-size: 9pt;">。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">D</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号位于初始话数据段中。<span style="font-family: inherit; color: blue;">一般来说，分配到</span></span><span style="font-family: inherit; color: blue; font-size: 9pt;">data section</span><span style="font-family: inherit; color: blue; font-size: 9pt;">中。例如定义全局</span><span style="font-family: inherit; color: blue; font-size: 9pt;">int baud_table[5] = {9600, 19200, 38400, 57600, 115200}</span><span style="font-family: inherit; color: blue; font-size: 9pt;">，则会分配于初始化数据段中</span><span style="font-family: inherit; font-size: 9pt;">。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">G</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号也位于初始化数据段中。主要用于</span><span style="font-family: inherit; font-size: 9pt;">small object</span><span style="font-family: inherit; font-size: 9pt;">提高访问</span><span style="font-family: inherit; font-size: 9pt;">small data object</span><span style="font-family: inherit; font-size: 9pt;">的一种方式。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">I</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号是对另一个符号的间接引用。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">N</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号是一个</span><span style="font-family: inherit; font-size: 9pt;">debugging</span><span style="font-family: inherit; font-size: 9pt;">符号。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">R</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号位于只读数据区。<span style="font-family: inherit; color: blue;">例如定义全局</span></span><span style="font-family: inherit; color: blue; font-size: 9pt;">const int test[] = {123, 123};</span><span style="font-family: inherit; color: blue; font-size: 9pt;">则</span><span style="font-family: inherit; color: blue; font-size: 9pt;">test</span><span style="font-family: inherit; color: blue; font-size: 9pt;">就是一个只读数据区的符号。注意在</span><span style="font-family: inherit; color: blue; font-size: 9pt;">cygwin</span><span style="font-family: inherit; color: blue; font-size: 9pt;">下如果使用</span><span style="font-family: inherit; color: blue; font-size: 9pt;">gcc</span><span style="font-family: inherit; color: blue; font-size: 9pt;">直接编译成</span><span style="font-family: inherit; color: blue; font-size: 9pt;">MZ</span><span style="font-family: inherit; color: blue; font-size: 9pt;">格式时，源文件中的</span><span style="font-family: inherit; color: blue; font-size: 9pt;">test</span><span style="font-family: inherit; color: blue; font-size: 9pt;">对应</span><span style="font-family: inherit; color: blue; font-size: 9pt;">_test</span><span style="font-family: inherit; color: blue; font-size: 9pt;">，并且其符号类型为</span><span style="font-family: inherit; color: blue; font-size: 9pt;">D</span><span style="font-family: inherit; color: blue; font-size: 9pt;">，即初始化数据段中。但是如果使用</span><span style="font-family: inherit; color: blue; font-size: 9pt;">m6812-elf-gcc</span><span style="font-family: inherit; color: blue; font-size: 9pt;">这样的交叉编译工具，源文件中的</span><span style="font-family: inherit; color: blue; font-size: 9pt;">test</span><span style="font-family: inherit; color: blue; font-size: 9pt;">对应目标文件的</span><span style="font-family: inherit; color: blue; font-size: 9pt;">test,</span><span style="font-family: inherit; color: blue; font-size: 9pt;">即没有添加下划线，并且其符号类型为</span><span style="font-family: inherit; color: blue; font-size: 9pt;">R</span><span style="font-family: inherit; color: blue; font-size: 9pt;">。一般而言，位于</span><span style="font-family: inherit; color: blue; font-size: 9pt;">rodata section</span><span style="font-family: inherit; color: blue; font-size: 9pt;">。值得注意的是，如果在一个函数中定义</span><span style="font-family: inherit; color: blue; font-size: 9pt;">const char *test = &#8220;abc&#8221;, const char test_int = 3</span><span style="font-family: inherit; color: blue; font-size: 9pt;">。使用</span><span style="font-family: inherit; color: blue; font-size: 9pt;"><span style="font-family: inherit; background-color: #fffe65;">nm</span></span><span style="font-family: inherit; color: blue; font-size: 9pt;">都不会得到符号信息，但是字符串&#8220;</span><span style="font-family: inherit; color: blue; font-size: 9pt;">abc</span><span style="font-family: inherit; color: blue; font-size: 9pt;">&#8221;分配于只读存储器中，</span><span style="font-family: inherit; color: blue; font-size: 9pt;">test</span><span style="font-family: inherit; color: blue; font-size: 9pt;">在</span><span style="font-family: inherit; color: blue; font-size: 9pt;">rodata section</span><span style="font-family: inherit; color: blue; font-size: 9pt;">中，大小为</span><span style="font-family: inherit; color: blue; font-size: 9pt;">4</span><span style="font-family: inherit; color: blue; font-size: 9pt;">。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">S</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">符号位于非初始化数据区，用于</span><span style="font-family: inherit; font-size: 9pt;">small object</span><span style="font-family: inherit; font-size: 9pt;">。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">T</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号位于代码区</span><span style="font-family: inherit; font-size: 9pt;">text section</span><span style="font-family: inherit; font-size: 9pt;">。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">U</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号在当前文件中是未定义的，即该符号的定义在别的文件中。<span style="font-family: inherit; color: blue;">例如，当前文件调用另一个文件中定义的函数，在这个被调用的函数在当前就是未定义的；但是在定义它的文件中类型是</span></span><span style="font-family: inherit; color: blue; font-size: 9pt;">T</span><span style="font-family: inherit; color: blue; font-size: 9pt;">。但是对于全局变量来说，在定义它的文件中，其符号类型为</span><span style="font-family: inherit; color: blue; font-size: 9pt;">C</span><span style="font-family: inherit; color: blue; font-size: 9pt;">，在使用它的文件中，其类型为</span><span style="font-family: inherit; color: blue; font-size: 9pt;">U</span><span style="font-family: inherit; color: blue; font-size: 9pt;">。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">V</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号是一个</span><span style="font-family: inherit; font-size: 9pt;">weak object</span><span style="font-family: inherit; font-size: 9pt;">。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">W</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">The symbol is a weak symbol that has not been specifically tagged as a weak object symbol.</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">-</span></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号是</span><span style="font-family: inherit; font-size: 9pt;">a.out</span><span style="font-family: inherit; font-size: 9pt;">格式文件中的</span><span style="font-family: inherit; font-size: 9pt;">stabs symbol</span><span style="font-family: inherit; font-size: 9pt;">。</span></td></tr><tr><td valign="top" width="48" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt; border-style: none double double; border-left-color: silver; width: 36pt; border-right-color: silver;"></td><td valign="top" width="504" style="margin: 0px; padding: 0cm 5.4pt; border-bottom-color: silver; border-width: medium 1.5pt 1.5pt medium; border-style: none double double none; width: 378pt; border-right-color: silver;"><span style="font-family: inherit; font-size: 9pt;">该符号类型没有定义</span></td></tr></tbody></table><img src ="http://www.cppblog.com/prayer/aggbug/216346.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-04-10 14:28 <a href="http://www.cppblog.com/prayer/archive/2019/04/10/216346.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sed -i命令详解</title><link>http://www.cppblog.com/prayer/archive/2019/04/04/216337.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Thu, 04 Apr 2019 09:49:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/04/04/216337.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216337.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/04/04/216337.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216337.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216337.html</trackback:ping><description><![CDATA[<div>https://www.cnblogs.com/ev-zhk/p/4277023.html<br /><div data-find="_2" style="margin: 5px 0px; font-size: 12px; line-height: 18px;"><pre data-find="_1" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;">[root@www ~]# <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> [-<span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">nefr] [动作] 选项与参数： </span>-n ：使用安静(silent)模式。在一般 <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> 的用法中，所有来自 STDIN 的数据一般都会被列出到终端上。但如果加上 -<span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">n 参数后，则只有经过sed 特殊处理的那一行(或者动作)才会被列出来。 </span>-e ：直接在命令列模式上进行 <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> 的动作编辑； </span>-f ：直接将 <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> 的动作写在一个文件内， -f filename 则可以运行 filename 内的 <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> 动作； </span>-r ：<span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> 的动作支持的是延伸型正规表示法的语法。(默认是基础正规表示法语法) </span>-<span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">i ：直接修改读取的文件内容，而不是输出到终端。  动作说明： [n1[,n2]]</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">function</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> n1, n2 ：不见得会存在，一般代表『选择进行动作的行数』，举例来说，如果我的动作是需要在 </span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">10</span> 到 <span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">20</span> 行之间进行的，则『 <span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">10</span>,<span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">20</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">[动作行为] 』  </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">function</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">： a ：新增， a 的后面可以接字串，而这些字串会在新的一行出现(目前的下一行)～ c ：取代， c 的后面可以接字串，这些字串可以取代 n1,n2 之间的行！ d ：删除，因为是删除啊，所以 d 后面通常不接任何咚咚； i ：插入， i 的后面可以接字串，而这些字串会在新的一行出现(目前的上一行)； p ：列印，亦即将某个选择的数据印出。通常 p 会与参数 </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> -<span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">n 一起运行～ s ：取代，可以直接进行取代的工作哩！通常这个 s 的动作可以搭配正规表示法！例如 </span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">1</span>,20s/old/new/g 就是啦！</pre><div style="margin: 5px 0px 0px; line-height: 1.5 !important;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5 !important;"><a title="复制代码" style="margin: 0px; padding: 0px; color: #444444; text-decoration: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; max-width: 660px; height: auto; border: none !important;" /></a></span></div></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;"><br style="margin: 0px; padding: 0px;" /><strong style="margin: 0px; padding: 0px;">sed -i</strong>&nbsp;就是直接对文本文件进行操作的</p><div style="margin: 5px 0px; font-size: 12px; line-height: 18px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> -i <span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">s/原字符串/新字符串/</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span> /home/<span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">1</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">.txt </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> -i <span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">s/原字符串/新字符串/g</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span> /home/<span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">1</span>.txt</pre></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;"><br style="margin: 0px; padding: 0px;" />这两条命令的区别就是，看示例吧</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;">这是1.txt的内容</p><div style="margin: 5px 0px; font-size: 12px; line-height: 18px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">#<span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">cat</span> 1</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">.txt d ddd #ff</span></pre></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;">再看执行这两条命令的区别吧</p><div style="margin: 5px 0px; font-size: 12px; line-height: 18px;"><div style="margin: 5px 0px 0px; line-height: 1.5 !important;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5 !important;"><a title="复制代码" style="margin: 0px; padding: 0px; color: #444444; text-decoration: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; max-width: 660px; height: auto; border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> -i <span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">s/d/7523/</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span> /home/<span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">1</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">.txt 执行结果 </span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">7523</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> 7523</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">dd</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> #ff  </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> -i <span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">s/d/7523/g</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span> /home/<span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">1</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">.txt 执行结果 </span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">7523</span> <span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">752375237523</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> #ff</span></pre><div style="margin: 5px 0px 0px; line-height: 1.5 !important;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5 !important;"><a title="复制代码" style="margin: 0px; padding: 0px; color: #444444; text-decoration: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; max-width: 660px; height: auto; border: none !important;" /></a></span></div></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px;">去掉&nbsp;&#8220;行首&#8221;&nbsp;带&#8220;@&#8221;的首字母@</strong></p><div style="margin: 5px 0px; font-size: 12px; line-height: 18px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> -i <span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">s/^@//</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">file</span></pre></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px;">特定字符串的行前插入新行</strong></p><div style="margin: 5px 0px; font-size: 12px; line-height: 18px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> -i <span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">/特定字符串/i 新行字符串</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">' <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">file</span></span></pre></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px;">特定字符串的行后插入新行</strong></p><div style="margin: 5px 0px; font-size: 12px; line-height: 18px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> -i <span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">/特定字符串/a 新行字符串</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">file</span></pre></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px;">特定字符串的删除</strong></p><div style="margin: 5px 0px; font-size: 12px; line-height: 18px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">sed</span> -i <span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">'</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">/字符串/d</span><span style="margin: 0px; padding: 0px; color: #800000; line-height: 1.5 !important;">' </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">file</span></pre></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; line-height: 18px; color: #444444; font-family: tahoma, arial, sans-serif; font-size: 12px; background-color: #ffffff;">&nbsp;</p></div><img src ="http://www.cppblog.com/prayer/aggbug/216337.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-04-04 17:49 <a href="http://www.cppblog.com/prayer/archive/2019/04/04/216337.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sed中使用变量替换以及执行外部命令</title><link>http://www.cppblog.com/prayer/archive/2019/04/04/216336.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Thu, 04 Apr 2019 09:46:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/04/04/216336.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216336.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/04/04/216336.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216336.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216336.html</trackback:ping><description><![CDATA[<div>https://blog.csdn.net/halazi100/article/details/41722021<br /><br /><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">在使用sed对日志或者其它文本进行parse的过程当中，有时候我们需要引用外部变量的值，<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />或者获取一个shell命令执行的结果，以便达到更加可观的输出结果。这里介绍如何做到。<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />sed中使用变量替换<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />1.sed命令使用双引号的情况下，使用$var直接引用<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />$ echo|sed "s/^/$RANDOM.rmvb_/g"<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;29328.rmvb_</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">如果替换的变量内容中含有/符号则会提示如下错误，如<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />查找当前目录下的目录文件并将相对路径替换为绝对路径<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />find . -type f | sed -n "s/\./$PWD/p"<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />sed: -e expression #1, char 19: unknown option to `s'<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />从语法上看，没有任何问题；但由于变量中包含有&#8220;/&#8221;作为分隔符，这会和sed的替换操作的分隔符&#8220;/&#8221;引起混淆；所以，只要不使用&#8220;/&#8221;做分隔符就可以解决这个问题，如果使用&#8220;%&#8221;而不是&#8220;/&#8221;来作为sed的替换操作的分隔符，就不会出错。其实使用#或%或;作为分隔符也是可以的，只要不会与替换中有相同的而且不是元字符的特殊符号都是可以的；使用时可以根据情况灵活选择。<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />find . -type f | sed -n "s%\.%$PWD%p"<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />find . -type f | sed -n "s#\.#$PWD#p"</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"># 上面例子引用了一个环境变量$RANDOM的值<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />2.sed命令使用单引号的情况下，使用'"$var"'引用<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />类似，我们可以看到<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />$ echo|sed 's/^/'"$RANDOM"'.rmvb_/g'<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;31338.rmvb_<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />sed中执行外部命令<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />1.sed命令使用单引号的情况下使用'`shell command`'或者'$(shell command)'引用命令执行的结果<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />还是以上面案例分析，例子如下<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />$ echo|sed 's/^/'`echo $RANDOM`'.rmvb_/g'<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;8063.rmvb_<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"># 上面的例子使用了旧式的命令替换，也可以采用新式的命令替换方法，如下<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />$ echo|sed 's/^/'$(echo $RANDOM)'.rmvb_/g'<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;18554.rmvb_<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"># 下面例子取用当前日期作为结果的一部分，如下<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />$ echo|sed 's/^/'$(date +"%Y%m%d")'.rmvb_/g'<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;20120108.rmvb_<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">2.sed命令使用双引号的情况下直接`shell command`或者$(shell command)引用命令执行的结果<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">类似的，双引号的情况，如下<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />$ echo|sed "s/^/$(date +"%Y%m%d").rmvb_/g"<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;20120108.rmvb_<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"># 使用环境变量$RANDOM以及旧式命令替换的例子<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />$ echo|sed "s/^/`echo $RANDOM`.rmvb_/g"<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;4988.rmvb_<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />总结<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />在sed语句里面，变量替换或者执行shell命令，双引号比单引号少绕一些弯子</p></div><img src ="http://www.cppblog.com/prayer/aggbug/216336.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-04-04 17:46 <a href="http://www.cppblog.com/prayer/archive/2019/04/04/216336.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux 比较两个文件夹不同 (diff命令, md5列表)</title><link>http://www.cppblog.com/prayer/archive/2019/04/04/216335.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Thu, 04 Apr 2019 09:46:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/04/04/216335.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216335.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/04/04/216335.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216335.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216335.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;"><strong><span style="color: #ff0000;">比较文件夹diff，可以直接使用diff命令</span></strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">[root@~]# diff -urNa dir1 dir2<br />　　-a Treat all files as text and compare them line-by-line, even if they do not seem to be text.<br />　　-N, --new-file<br />　　　　In directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory.<br />　　-r When comparing directories, recursively compare any subdirectories found.</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">　　-u Use the unified output format.</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;"><span style="color: #ff0000;"><strong>比较文件夹diff，也可以比较文件MD5列表。下面命令可以获取文件夹中文件md5列表</strong></span></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">find /home/ -type f -not \( -name '.*' \) -exec md5sum {} \;</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">说明：(1)&nbsp;/home/文件目录</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">　　 &nbsp; (2)&nbsp;-type f 文件类型为普通文件</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">　　 &nbsp; (3)&nbsp;-not \( -name '.*' \) &nbsp;过滤掉隐藏文件。可以过滤掉不需要考虑的文件</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(4)&nbsp;-exec md5sum {} \; &nbsp;对每个文件执行md5sum命令&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;"><span style="color: #ff0000;"><strong>&nbsp;用tar命令压缩后，比较文件的MD5是不行的。tar压缩会带上文件的时间</strong></span></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 25px; background-color: #ffffff;"><img src="https://images2015.cnblogs.com/blog/466768/201703/466768-20170303081158188-1578572513.png" alt="" style="border: 0px; max-width: 900px; height: auto;" /></p><img src ="http://www.cppblog.com/prayer/aggbug/216335.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-04-04 17:46 <a href="http://www.cppblog.com/prayer/archive/2019/04/04/216335.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SHELL 在指定行的前/后插入指定内容</title><link>http://www.cppblog.com/prayer/archive/2019/04/04/216334.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Thu, 04 Apr 2019 09:13:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/04/04/216334.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216334.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/04/04/216334.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216334.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216334.html</trackback:ping><description><![CDATA[<div>https://www.jianshu.com/p/66f79ad53406<br /><br /><h3>如果知道行号可以用下面的方法</h3><pre bash"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">sed -i <span style="box-sizing: border-box; color: #98c379;">'88 r b.file'</span> a.file    <span style="box-sizing: border-box; color: #929292;">#在a.txt的第88行插入文件b.txt</span> awk <span style="box-sizing: border-box; color: #98c379;">'1;NR==88{system("cat b.file")}'</span> a.file &gt; a.file </code></pre><h3>如果不知道行号，可以用正則匹配</h3><pre bash"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">sed -i <span style="box-sizing: border-box; color: #98c379;">'/regex/ r b.txt'</span> a.txt <span style="box-sizing: border-box; color: #929292;"># regex是正则表达式</span> awk <span style="box-sizing: border-box; color: #98c379;">'/target/{system("cat b.file")}'</span> a.file &gt; c.file </code></pre><h3>sed的話如果不改变源文件，可以去掉-i开关，修改会输出到STDOUT</h3><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">原文件：</p><pre ruby"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># cat -n file </span>      <span style="box-sizing: border-box; color: #d19a66;">1</span>  aaaa      <span style="box-sizing: border-box; color: #d19a66;">2</span>  bbbb      <span style="box-sizing: border-box; color: #d19a66;">3</span>  cccc      <span style="box-sizing: border-box; color: #d19a66;">4</span>  dddd </code></pre><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">现在要在第二行即&#8220;bbbb&#8221;行的下面添加一行，内容为&#8220;xiaowu&#8221;</p><pre ruby"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># sed '/bbbb/a\xiaowu' file </span> aaaa bbbb xiaowu cccc dddd </code></pre><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">如果要加两行&#8220;xiaowu&#8221;可以用一下语句，注意用&#8220;\n&#8221;换行</p><pre ruby"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># sed '/bbbb/a\xiaowu\nxiaowu' file </span> aaaa bbbb xiaowu xiaowu cccc dddd </code></pre><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">如果要在第二行即&#8220;bbbb&#8221;行的上添加一行，内容为&#8220;xiaowu&#8221;，可以把参数&#8220;a&#8221;换成&#8220;i&#8221;</p><pre ruby"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># sed '/b/i\xiaowu' file </span> aaaa xiaowu bbbb cccc dddd </code></pre><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">以上文件中只有一行匹配，如果文件中有两行或者多行匹配，结果有是如何呢？</p><pre ruby"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># cat -n file </span>      <span style="box-sizing: border-box; color: #d19a66;">1</span>  aaaa      <span style="box-sizing: border-box; color: #d19a66;">2</span>  bbbb      <span style="box-sizing: border-box; color: #d19a66;">3</span>  cccc      <span style="box-sizing: border-box; color: #d19a66;">4</span>  bbbb      <span style="box-sizing: border-box; color: #d19a66;">5</span>  dddd </code></pre><pre ruby"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># sed '/bbbb/a\xiaowu' file </span> aaaa bbbb xiaowu cccc bbbb xiaowu dddd </code></pre><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">由结果可知，每个匹配行的下一行都会被添加&#8220;xiaowu&#8221;</p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">那么如果指向在第二个&#8220;bbbb&#8221;的下一行添加内容&#8220;xiaowu&#8221;，该如何操作呢？<br style="box-sizing: border-box;" />可以考虑先获取第二个&#8220;bbbb&#8221;行的行号，然后根据行号在此行的下一行添加&#8220;xiaowu&#8221;</p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">获取第二个&#8220;bbbb&#8221;行的行号的方法：<br style="box-sizing: border-box;" />方法一：</p><pre objectivec"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #61aeee;"># cat -n file |grep b |awk '{print $1}'|sed -n <span style="box-sizing: border-box; color: #98c379;">"2"</span>p</span> <span style="box-sizing: border-box; color: #d19a66;">4</span> </code></pre><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">方法二：</p><pre objectivec"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #61aeee;"># sed -n '/bbbb/=' file |sed -n <span style="box-sizing: border-box; color: #98c379;">"2"</span>p</span> <span style="box-sizing: border-box; color: #d19a66;">4</span> </code></pre><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">由结果可知第二个&#8220;bbbb&#8221;行的行号为4，然后再在第四行的前或后添加相应的内容:</p><pre ruby"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># sed -e '4a\xiaowu' file </span> aaaa bbbb cccc bbbb xiaowu dddd </code></pre><pre ruby"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># sed -e '4a\xiaowu\nxiaowu' file </span> aaaa bbbb cccc bbbb xiaowu xiaowu dddd </code></pre><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;">向指定行的末尾添加指定内容，比如在&#8220;ccccc&#8221;行的行尾介绍&#8220; eeeee&#8221;</p><pre ruby"="" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 13px; padding: 15px; margin-top: 0px; margin-bottom: 20px; line-height: 1.42857; word-wrap: normal; color: #abb2bf; background-color: #282c34; border: 1px solid #cccccc; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; word-break: break-word !important;"><code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: inherit; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; padding: 0px; border: none; vertical-align: middle;">[root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># cat file</span> aaaaa bbbbb ccccc ddddd [root@xiaowu shell]<span style="box-sizing: border-box; color: #929292;"># sed 's/cc.*/&amp; eeeee/g' file</span> aaaaa bbbbb ccccc eeeee ddddd </code></pre><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27px; background-color: #ffffff; word-break: break-word !important;"><a href="http://www.360doc.com/content/14/1125/19/7044580_428024359.shtml" target="_blank" rel="nofollow" style="box-sizing: border-box; background-color: transparent; color: #3194d0; text-decoration: none; cursor: pointer;">原文链接</a></p></div><img src ="http://www.cppblog.com/prayer/aggbug/216334.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-04-04 17:13 <a href="http://www.cppblog.com/prayer/archive/2019/04/04/216334.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux下提示/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found 解决办法</title><link>http://www.cppblog.com/prayer/archive/2019/04/04/216333.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Thu, 04 Apr 2019 02:15:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/04/04/216333.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216333.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/04/04/216333.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216333.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216333.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">在rhel6.6上安装qt后，运行qtcreator提示 &#8220;核心载入失败: /opt/Qt5.3.2/Tools/QtCreator/lib/qtcreator/plugins/libCore.so:&nbsp;无法加载库/opt/Qt5.3.2/Tools/QtCreator/lib/qtcreator/plugins/libCore.so：(/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found&nbsp;<em id="__mceDel" style="margin: 0px; padding: 0px; line-height: 1.5;">(required by /opt/Qt5.3.2/Tools/QtCreator/lib/qtcreator/plugins/libCore.so))</em></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;"><em id="__mceDel" style="margin: 0px; padding: 0px; line-height: 1.5;"><em id="__mceDel" style="margin: 0px; padding: 0px;"></em></em>在网上查找资料后，解决方法如下<em id="__mceDel" style="margin: 0px; padding: 0px; line-height: 1.5;">。</em></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">1.查看gcc版本中包含哪些库。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">strings /usr/lib64/libstdc++.so.6 | grep GLIBC</p><table border="0" align="left" style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; border-style: solid; border-color: silver; word-break: break-word; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff; height: 22px; width: 222px;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: silver; border-collapse: collapse;"><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px;">GLIBCXX_3.4<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.1<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.2<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.3<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.4<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.5<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.6<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.7<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.8<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.9<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.10<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.11<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.12<br style="margin: 0px; padding: 0px;" />GLIBCXX_3.4.13<br style="margin: 0px; padding: 0px;" />GLIBC_2.2.5<br style="margin: 0px; padding: 0px;" />GLIBC_2.3<br style="margin: 0px; padding: 0px;" />GLIBC_2.4<br style="margin: 0px; padding: 0px;" />GLIBC_2.3.2<br style="margin: 0px; padding: 0px;" />GLIBCXX_FORCE_NEW<br style="margin: 0px; padding: 0px;" />GLIBCXX_DEBUG_MESSAGE_LENGTH</p></td></tr></tbody></table><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">　　可以看出不包含GLIBCXX_3.4.14</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">2.从网上下载高版本的libstdc++.so.6.0.13以上的版本，比如libstdc++.so.6.0.17。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">3.把libstdc++.so.6.0.17拷贝到/usr/lib64目录下。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">　　cp&nbsp;libstdc++.so.6.0.17 /usr/lib64/</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">4.删除libstdc++.so.6符号连接。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">　　rm&nbsp;libstdc++.so.6</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">5.新建里符号连接。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">　　ln -s libstdc++.so.6.0.17 libstdc++.so.6</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">6.再次查看就没有问题了。</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">&nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 15px; line-height: 27px; background-color: #ffffff;">libstdc++.so.6.0.17下载地址</p><img src ="http://www.cppblog.com/prayer/aggbug/216333.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-04-04 10:15 <a href="http://www.cppblog.com/prayer/archive/2019/04/04/216333.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>lib lib32 lib64等lib文件夹的说明</title><link>http://www.cppblog.com/prayer/archive/2019/04/04/216332.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Thu, 04 Apr 2019 02:14:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/04/04/216332.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216332.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/04/04/216332.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216332.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216332.html</trackback:ping><description><![CDATA[<ul style="box-sizing: border-box; outline: 0px; margin: 0px 0px 24px; padding: 0px; list-style: none; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; word-wrap: break-word; color: rgba(0, 0, 0, 0.74902); background-color: #ffffff;"><li style="box-sizing: border-box; outline: 0px; margin: 8px 0px 0px 32px; padding: 0px; list-style-type: disc; word-wrap: break-word;">/lib&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />最基本的共享库和内核模块。&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />目的 -&gt; 存放用于启动系统和执行root文件系统的命令的如/bin /sbin的二进制文件的共享库，或者存放32位，或者64位(file命令查看)。</li><li style="box-sizing: border-box; outline: 0px; margin: 8px 0px 0px 32px; padding: 0px; list-style-type: disc; word-wrap: break-word;">/lib、 /usr/lib、/usr/local/lib&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />目的 -&gt; 就是为了区分32位和64位而设置的目录。这种情况下/lib有可能是其符号链接。</li><li style="box-sizing: border-box; outline: 0px; margin: 8px 0px 0px 32px; padding: 0px; list-style-type: disc; word-wrap: break-word;"><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; color: #4f4f4f; line-height: 26px; word-wrap: break-word;">/usr/lib、/usr/local/lib&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />程序和安装包的库路径。&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />说明 -&gt; 不依赖特定架构的库应该放到/usr/share中而不是这里。应用程序可以自己创建一个单独的子目录并把自己的库放在其中。</p></li><li style="box-sizing: border-box; outline: 0px; margin: 8px 0px 0px 32px; padding: 0px; list-style-type: disc; word-wrap: break-word;"><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; color: #4f4f4f; line-height: 26px; word-wrap: break-word;">总结&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />一般情况下：&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />系统自己会匹配应用程序与其应该调用的位数的库。&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />如果是用于/bin /sbin的库，放置到/lib*之中。&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />如果是用于用户程序或安装包的，放置到/usr/lib*或/usr/local/lib*之中。&nbsp;<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />如果某个库只是特别的用了某个专用程序，而这个程序但并不打算直接被用户或者root调用，应放置到/usr/libexec中。</p></li></ul><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; word-wrap: break-word; background-color: #ffffff;"><a href="http://unix.stackexchange.com/questions/74646/difference-between-lib-lib32-lib64-libx32-and-libexec" rel="nofollow" target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #6795b5; text-decoration: none; cursor: pointer; background-color: transparent; word-wrap: break-word;">http://unix.stackexchange.com/questions/74646/difference-between-lib-lib32-lib64-libx32-and-libexec</a></p><img src ="http://www.cppblog.com/prayer/aggbug/216332.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-04-04 10:14 <a href="http://www.cppblog.com/prayer/archive/2019/04/04/216332.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux程序分析工具介绍—ldd,nm</title><link>http://www.cppblog.com/prayer/archive/2019/04/03/216328.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Wed, 03 Apr 2019 07:56:00 GMT</pubDate><guid>http://www.cppblog.com/prayer/archive/2019/04/03/216328.html</guid><wfw:comment>http://www.cppblog.com/prayer/comments/216328.html</wfw:comment><comments>http://www.cppblog.com/prayer/archive/2019/04/03/216328.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prayer/comments/commentRss/216328.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prayer/services/trackbacks/216328.html</trackback:ping><description><![CDATA[<section style="background-color: #ffffff; width: 1616px; margin: auto; overflow: hidden; font-family: 宋体, arial; font-size: 12px; line-height: normal;"><div style="width: 1486.71875px; margin: 0px auto auto; line-height: 32px; font-size: 18px; text-align: justify; overflow: hidden;"><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">本文要介绍的ldd和nm是linux下，两个用来分析程序很实用的工具。ldd是用来分析程序运行时需要依赖的动态库的工具；nm是用来查看指定程序中的符号表相关内容的工具。下面通过例子，分别来介绍一下这两个工具：</p><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">1. ldd, 先看下面的例子, 用ldd查看cs程序所依赖的动态库：</p><ol style="font-size: 0.95em;"><li style="font-size: 0.95em;">$&nbsp;ldd&nbsp;cs&nbsp;&nbsp;</li><li style="font-size: 0.95em;">linux-gate.so.1&nbsp;=&gt;&nbsp;&nbsp;(0xffffe000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">libz.so.1&nbsp;=&gt;&nbsp;/lib/libz.so.1&nbsp;(0xb7f8c000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">libpthread.so.0&nbsp;=&gt;&nbsp;/lib/libpthread.so.0&nbsp;(0xb7f75000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">libcrypto.so.0.9.8&nbsp;=&gt;&nbsp;/usr/lib/libcrypto.so.0.9.8&nbsp;(0xb7e4d000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">libpcre.so.0&nbsp;=&gt;&nbsp;/usr/lib/libpcre.so.0&nbsp;(0xb7e21000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">libstdc++.so.6&nbsp;=&gt;&nbsp;/usr/local/gcc4.5.1/lib/libstdc++.so.6&nbsp;(0xb7d40000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">libm.so.6&nbsp;=&gt;&nbsp;/lib/libm.so.6&nbsp;(0xb7d18000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">libgcc_s.so.1&nbsp;=&gt;&nbsp;/usr/local/gcc4.5.1/lib/libgcc_s.so.1&nbsp;(0xb7cfd000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">libc.so.6&nbsp;=&gt;&nbsp;/lib/libc.so.6&nbsp;(0xb7bbc000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">/lib/ld-linux.so.2&nbsp;(0xb7fab000)&nbsp;&nbsp;</li><li style="font-size: 0.95em;">libdl.so.2&nbsp;=&gt;&nbsp;/lib/libdl.so.2&nbsp;(0xb7bb7000)&nbsp;&nbsp;</li></ol><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">在上面的例子中，ldd的结果可以分为三列来看：</p><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">&#8226;第一列：程序需要依赖什么库<br style="font-size: 0.95em;" />&#8226;第二列: 系统提供的与程序需要的库所对应的库<br style="font-size: 0.95em;" />&#8226;第三列：库加载的开始地址<br style="font-size: 0.95em;" />通过上面的信息，我们可以得到以下几个信息：</p><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">&#8226;（1） 通过对比第一列和第二列，我们可以分析程序需要依赖的库和系统实际提供的，是否相匹配<br style="font-size: 0.95em;" />&#8226;（2） 通过观察第三列，我们可以知道在当前的库中的符号在对应的进程的地址空间中的开始位置<br style="font-size: 0.95em;" />2. nm, 通过下面的例子，我们来介绍nm工具：</p><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">先看一下这个简单的程序：</p><ol style="font-size: 0.95em;"><li style="font-size: 0.95em;">#include&nbsp;"iostream"&nbsp;&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;</li><li style="font-size: 0.95em;"><strong style="font-size: 0.95em;">using</strong>&nbsp;<strong style="font-size: 0.95em;">namespace</strong>&nbsp;std;&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;</li><li style="font-size: 0.95em;"><strong style="font-size: 0.95em;">class</strong>&nbsp;Test&nbsp;&nbsp;</li><li style="font-size: 0.95em;">{&nbsp;&nbsp;</li><li style="font-size: 0.95em;"><strong style="font-size: 0.95em;">public</strong>:&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;<strong style="font-size: 0.95em;">void</strong>&nbsp;Hello()&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;&lt;&nbsp;&lt;&nbsp;"Hello&nbsp;world!"&nbsp;&lt;&lt;&nbsp;endl;&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 0.95em;">};&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;</li><li style="font-size: 0.95em;"><strong style="font-size: 0.95em;">int</strong>&nbsp;main()&nbsp;&nbsp;</li><li style="font-size: 0.95em;">{&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;Test&nbsp;test;&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;test.Hello();&nbsp;&nbsp;</li><li style="font-size: 0.95em;">}&nbsp;&nbsp;</li></ol><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">接下来，我们编译该程序，然后看nm的结果：</p><ol style="font-size: 0.95em;"><li style="font-size: 0.95em;">$&nbsp;g++&nbsp;test.cc&nbsp;-o&nbsp;test&nbsp;&nbsp;</li><li style="font-size: 0.95em;">c$&nbsp;nm&nbsp;test&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049f10&nbsp;d&nbsp;_DYNAMIC&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049ff4&nbsp;d&nbsp;_GLOBAL_OFFSET_TABLE_&nbsp;&nbsp;</li><li style="font-size: 0.95em;">080486f0&nbsp;t&nbsp;_GLOBAL__I_main&nbsp;&nbsp;</li><li style="font-size: 0.95em;">080487fc&nbsp;R&nbsp;_IO_stdin_used&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w&nbsp;_Jv_RegisterClasses&nbsp;&nbsp;</li><li style="font-size: 0.95em;">080486b0&nbsp;t&nbsp;_Z41__static_initialization_and_destruction_0ii&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804870c&nbsp;W&nbsp;_ZN4Test5HelloEv&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;_ZNSolsEPFRSoS_E@@GLIBCXX_3.4&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;_ZNSt8ios_base4InitC1Ev@@GLIBCXX_3.4&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a040&nbsp;B&nbsp;_ZSt4cout@@GLIBCXX_3.4&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@@GLIBCXX_3.4&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a0d4&nbsp;b&nbsp;_ZStL8__ioinit&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@@GLIBCXX_3.4&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049f00&nbsp;d&nbsp;__CTOR_END__&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049ef8&nbsp;d&nbsp;__CTOR_LIST__&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049f08&nbsp;D&nbsp;__DTOR_END__&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049f04&nbsp;d&nbsp;__DTOR_LIST__&nbsp;&nbsp;</li><li style="font-size: 0.95em;">080488c8&nbsp;r&nbsp;__FRAME_END__&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049f0c&nbsp;d&nbsp;__JCR_END__&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049f0c&nbsp;d&nbsp;__JCR_LIST__&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a02c&nbsp;A&nbsp;__bss_start&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;__cxa_atexit@@GLIBC_2.1.3&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a024&nbsp;D&nbsp;__data_start&nbsp;&nbsp;</li><li style="font-size: 0.95em;">080487b0&nbsp;t&nbsp;__do_global_ctors_aux&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08048610&nbsp;t&nbsp;__do_global_dtors_aux&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a028&nbsp;D&nbsp;__dso_handle&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w&nbsp;__gmon_start__&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;__gxx_personality_v0@@CXXABI_1.3&nbsp;&nbsp;</li><li style="font-size: 0.95em;">080487aa&nbsp;T&nbsp;__i686.get_pc_thunk.bx&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049ef8&nbsp;d&nbsp;__init_array_end&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08049ef8&nbsp;d&nbsp;__init_array_start&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08048740&nbsp;T&nbsp;__libc_csu_fini&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08048750&nbsp;T&nbsp;__libc_csu_init&nbsp;&nbsp;</li><li style="font-size: 0.95em;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;U&nbsp;__libc_start_main@@GLIBC_2.0&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a02c&nbsp;A&nbsp;_edata&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a0d8&nbsp;A&nbsp;_end&nbsp;&nbsp;</li><li style="font-size: 0.95em;">080487dc&nbsp;T&nbsp;_fini&nbsp;&nbsp;</li><li style="font-size: 0.95em;">080487f8&nbsp;R&nbsp;_fp_hw&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08048508&nbsp;T&nbsp;_init&nbsp;&nbsp;</li><li style="font-size: 0.95em;">080485e0&nbsp;T&nbsp;_start&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a0cc&nbsp;b&nbsp;completed.7065&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a024&nbsp;W&nbsp;data_start&nbsp;&nbsp;</li><li style="font-size: 0.95em;">0804a0d0&nbsp;b&nbsp;dtor_idx.7067&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08048670&nbsp;t&nbsp;frame_dummy&nbsp;&nbsp;</li><li style="font-size: 0.95em;">08048694&nbsp;T&nbsp;main&nbsp;&nbsp;</li></ol><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">上面便是test这个程序中所有的符号，首先需要介绍一下上面的内容的格式：</p><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">&#8226;第一列：当前符号的地址<br style="font-size: 0.95em;" />&#8226;第二列：当前符号的类型<br style="font-size: 0.95em;" />&#8226;第三列：当前符号的名称<br style="font-size: 0.95em;" />在上面的结果中，像_ZN4Test5HelloEv这样的符号，很多读者朋友可能会被它搞晕，这里介绍个小技巧，在nm的时候，加上-C选项，就可以把这些难以识别的符号，转换成便于我们阅读的符号TestHello()。这个主要是c++中的mangle机制所导致的，加上-C就是指定列出的符号是demangle了的。说了这么多，到底nm对我们程序有啥具体的帮助呢，我觉得主要有以下几个方面：<br style="font-size: 0.95em;" />（1）判断指定程序中有没有定义指定的符号 (比较常用的方式：nm -C proc | grep symbol)<br style="font-size: 0.95em;" />（2）解决程序编译时undefined reference的错误，以及mutiple definition的错误</p><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;">（3）查看某个符号的地址，以及在进程空间的大概位置（bss, data, text区，具体可以通过第二列的类型来判断）</p><p style="font-size: 0.95em; margin: 0px; line-height: 1.6em; padding: 0px; text-indent: 2em;"></p><blockquote style="background-color: #f3f7f0; padding-right: 5px; padding-left: 5px; margin-right: 0px; margin-left: 0px; font-size: 0.95em;"><p style="font-size: 14px; margin: 0px; line-height: 1.6; padding: 0px; text-indent: 2em;">本文要介绍的ldd和nm是linux下，两个用来分析程序很实用的工具。ldd是用来分析程序运行时需要依赖的动态库的工具；nm是用来查看指定程序中的符号表相关内容的工具。下面通过例子，分别来介绍一</p></blockquote></div></section><div style="width: 1519.03125px; margin: auto; overflow: hidden; font-family: 宋体, arial; font-size: 12px; line-height: normal; text-align: center; background-color: #ffffff;"><div style="width: 1427.875px; float: none; margin: 10px auto 0px;"><h1>相关推荐</h1></div></div><img src ="http://www.cppblog.com/prayer/aggbug/216328.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prayer/" target="_blank">Prayer</a> 2019-04-03 15:56 <a href="http://www.cppblog.com/prayer/archive/2019/04/03/216328.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>