{"id":52340,"date":"2024-12-03T08:32:59","date_gmt":"2024-12-03T00:32:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52340\/"},"modified":"2024-12-03T08:32:59","modified_gmt":"2024-12-03T00:32:59","slug":"%e5%9c%a8linux%e4%b8%8bcore%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52340\/","title":{"rendered":"\u5728linux\u4e0bcore\u600e\u4e48\u4f7f\u7528"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5728linux\u4e0bcore\u600e\u4e48\u4f7f\u7528<\/h1>\n<p><span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5728linux\u4e0bcore\u600e\u4e48\u4f7f\u7528\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span><\/p>\n<\/p>\n<blockquote>\n<p>\u5728linux\u4e0bcore\u662f\u4e00\u4e2a\u5185\u5b58\u6620\u50cf\uff0c\u540c\u65f6\u52a0\u4e0a\u8c03\u8bd5\u4fe1\u606f\uff1b\u5728linux\u4e0b\u9047\u5230\u7a0b\u5e8f\u5f02\u5e38\u9000\u51fa\u6216\u8005\u4e2d\u6b62\uff0c\u6211\u4eec\u90fd\u4f1a\u4f7f\u7528core\u6587\u4ef6\u8fdb\u884c\u5206\u6790\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u5185\u5b58\u3001\u5bc4\u5b58\u5668\u3001\u5806\u6808\u6307\u9488\u7b49\u4fe1\u606f\uff0c\u683c\u5f0f\u4e3aELF\uff0c\u53ef\u4ee5\u7406\u89e3\u662f\u7a0b\u5e8f\u5de5\u4f5c\u5f53\u524d\u72b6\u6001\u8f6c\u50a8\u6210\u4e00\u4e2a\u6587\u4ef6\u3002<\/p>\n<\/blockquote>\n<p><strong>\u5728linux\u4e0bcore\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<p>Linux\u4e0bcore\u6587\u4ef6\u7684\u4f7f\u7528\u65b9\u6cd5\u8be6\u89e3<\/p>\n<p>\u6709\u65f6\u5019\u7a0b\u5e8f\u4f1a\u5f02\u5e38\u9000\u51fa\u800c\u4e0d\u5e26\u4efb\u4f55\u65e5\u5fd7\uff0c\u6b64\u65f6\u5c31\u53ef\u4ee5\u4f7f\u7528 code \u6587\u4ef6\u8fdb\u884c\u5206\u6790\uff0c\u5b83\u4f1a\u8bb0\u5f55\u7a0b\u5e8f\u8fd0\u884c\u7684\u5185\u5b58\uff0c\u5bc4\u5b58\u5668\uff0c\u5806\u6808\u6307\u9488\u7b49\u4fe1\u606f<\/p>\n<p>core\u6587\u4ef6\uff1a<\/p>\n<p>\u901a\u5e38\u5728 Linux \u4e0b\u9047\u5230\u7a0b\u5e8f\u5f02\u5e38\u9000\u51fa\u6216\u8005\u4e2d\u6b62\uff0c\u6211\u4eec\u90fd\u4f1a\u4f7f\u7528 core \u6587\u4ef6\u8fdb\u884c\u5206\u6790\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u5185\u5b58\uff0c\u5bc4\u5b58\u5668\uff0c\u5806\u6808\u6307\u9488\u7b49\u4fe1\u606f\uff0c\u683c\u5f0f\u4e3a ELF \uff0c\u53ef\u4ee5\u7406\u89e3\u662f\u7a0b\u5e8f\u5de5\u4f5c\u5f53\u524d\u72b6\u6001\u8f6c\u50a8\u6210\u4e00\u4e2a\u6587\u4ef6\uff0c\u901a\u8fc7\u5de5\u5177\u5206\u6790\u8fd9\u4e2a\u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4f4d\u5230\u7a0b\u5e8f\u5f02\u5e38\u9000\u51fa\u6216\u8005\u7ec8\u6b62\u65f6\u76f8\u5e94\u7684\u5806\u6808\u8c03\u7528\u7b49\u4fe1\u606f\uff0c\u4e3a\u89e3\u51b3\u95ee\u9898\u63d0\u4f9b\u5e2e\u52a9\u3002<\/p>\n<p><strong>\u4f7f\u7528core\u6587\u4ef6\u8c03\u8bd5 <\/strong><\/p>\n<p><strong>\u751f\u6210\u65b9\u6cd5 <\/strong><\/p>\n<p>\u67e5\u770b\u5f53\u524d core \u6587\u4ef6\u7684\u72b6\u6001<\/p>\n<pre>$&nbsp;ulimit&nbsp;-a\n...\n-c:&nbsp;core&nbsp;file&nbsp;size&nbsp;(blocks)&nbsp;&nbsp;&nbsp;0&nbsp;#&nbsp;\u5173\u95ed\u72b6\u6001\n...<\/pre>\n<p>\u6253\u5f00\u751f\u6210\u5f00\u5173<\/p>\n<pre>ulimit&nbsp;-c&nbsp;unlimited\nulimit&nbsp;-a\n...\n-c:&nbsp;core&nbsp;file&nbsp;size&nbsp;(blocks)&nbsp;&nbsp;&nbsp;unlimited\n...<\/pre>\n<p>\u5bf9 core \u6587\u4ef6\u7684\u5927\u5c0f\u8fdb\u884c\u9650\u5236\uff0c\u5355\u4f4d\u4e3a blocks \uff0c\u4e00\u822c 1 block=512 bytes \uff0c\u8bbe\u7f6e\u592a\u5c0f\u53ef\u80fd\u5bfc\u81f4\u4e0d\u4f1a\u751f\u6210\u6587\u4ef6<\/p>\n<pre>$&nbsp;ulimit&nbsp;-c&nbsp;1024\n$&nbsp;ulimit&nbsp;-a\n...\n-c:&nbsp;core&nbsp;file&nbsp;size&nbsp;(blocks)&nbsp;&nbsp;&nbsp;1024\n...<\/pre>\n<p>\u5173\u95ed\u751f\u6210\u5f00\u5173<\/p>\n<pre>ulimit&nbsp;-c&nbsp;0\nulimit&nbsp;-a\n...\n-c:&nbsp;core&nbsp;file&nbsp;size&nbsp;(blocks)&nbsp;&nbsp;&nbsp;0\n...<\/pre>\n<p>\u4e0a\u9762\u5bf9 core \u6587\u4ef6\u7684\u64cd\u4f5c\u4ec5\u5bf9\u5f53\u524d\u751f\u6548\uff0c\u82e5\u9700\u8981\u6c38\u4e45\u751f\u6548\uff0c\u5219\u8981\u5c06\u76f8\u5e94\u64cd\u4f5c\u5199\u5165 \/etc\/profile<\/p>\n<p><strong>\u751f\u6210\u8def\u5f84<\/strong><\/p>\n<p>core \u6587\u4ef6\u9ed8\u8ba4\u751f\u6210\u5728\u7a0b\u5e8f\u7684\u5de5\u4f5c\u76ee\u5f55\uff0c\u53ef\u4ee5\u5bf9\u751f\u6210\u8def\u5f84\u8fdb\u884c\u8bbe\u7f6e\uff0c\u9700\u8981\u4fdd\u8bc1\u5bf9\u5bf9\u5e94\u76ee\u5f55\u6709\u8db3\u591f\u7a7a\u95f4\u5e76\u5177\u6709\u5199\u6743\u9650<\/p>\n<pre>echo&nbsp;\/MyCoreDumpDir\/core.%e.%p&nbsp;&gt;&nbsp;\/proc\/sys\/kernel\/core_pattern<\/pre>\n<p>\u5176\u4e2d\u547d\u540d\u4f7f\u7528\u7684\u53c2\u6570\u5217\u8868<\/p>\n<pre>%p&nbsp;-&nbsp;insert&nbsp;pid&nbsp;into&nbsp;filename&nbsp;#&nbsp;\u6dfb\u52a0&nbsp;pid&nbsp;\n%u&nbsp;-&nbsp;insert&nbsp;current&nbsp;uid&nbsp;into&nbsp;filename&nbsp;#&nbsp;\u6dfb\u52a0\u5f53\u524d&nbsp;uid&nbsp;\n%g&nbsp;-&nbsp;insert&nbsp;current&nbsp;gid&nbsp;into&nbsp;filename&nbsp;#&nbsp;\u6dfb\u52a0\u5f53\u524d&nbsp;gid&nbsp;\n%s&nbsp;-&nbsp;insert&nbsp;signal&nbsp;that&nbsp;caused&nbsp;the&nbsp;coredump&nbsp;into&nbsp;the&nbsp;filename&nbsp;#&nbsp;\u6dfb\u52a0\u5bfc\u81f4\u4ea7\u751f&nbsp;core&nbsp;\u7684\u4fe1\u53f7&nbsp;\n%t&nbsp;-&nbsp;insert&nbsp;UNIX&nbsp;time&nbsp;that&nbsp;the&nbsp;coredump&nbsp;occurred&nbsp;into&nbsp;filename&nbsp;#&nbsp;\u6dfb\u52a0&nbsp;core&nbsp;\u6587\u4ef6\u751f\u6210\u65f6\u7684&nbsp;unix&nbsp;\u65f6\u95f4&nbsp;\n%h&nbsp;-&nbsp;insert&nbsp;hostname&nbsp;where&nbsp;the&nbsp;coredump&nbsp;happened&nbsp;into&nbsp;filename&nbsp;#&nbsp;\u6dfb\u52a0\u4e3b\u673a\u540d&nbsp;\n%e&nbsp;-&nbsp;insert&nbsp;coredumping&nbsp;executable&nbsp;name&nbsp;into&nbsp;filename&nbsp;#&nbsp;\u6dfb\u52a0\u547d\u4ee4\u540d<\/pre>\n<p>\/proc\/sys\/kernel\/core_uses_pid \u8fd9\u4e2a\u6587\u4ef6\u7684\u503c\u82e5\u4e3a\uff11\uff0c\u5219\u65e0\u8bba\u65f6\u5019\u914d\u7f6e %p ,\u6700\u540e\u751f\u6210\u7684 core \u6587\u4ef6\u90fd\u4f1a\u6dfb\u52a0 pid<\/p>\n<p><strong>\u8c03\u8bd5\u65b9\u6cd5 <\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 gdb \u5bf9 core \u6587\u4ef6\u8fdb\u884c\u8c03\u8bd5\uff0c\u7f16\u8bd1\u662f\u9700\u8981\u5e26\u4e0a -g \u9009\u9879<\/p>\n<pre>$&nbsp;gdb&nbsp;a.out\n...\n(gdb)&nbsp;core-file&nbsp;core\n...\n(gdb)&nbsp;bt&nbsp;\n...<\/pre>\n<p>\u5982\u9700\u8981\u5728 PC \u4e0a\u8c03\u8bd5\u5d4c\u5165\u5f0f\u8bbe\u5907\u4ea7\u751f\u7684 core \u6587\u4ef6\uff0c\u5219\u9700\u8981\u9009\u53d6\u76f8\u5e94\u5e73\u53f0\u7684 gdb \u5de5\u5177\uff0c\u5e76\u5728\u8fdb\u5165 gdb \u540e\u8bbe\u7f6e\u7b26\u53f7\u6587\u4ef6\u7684\u4f4d\u7f6e<\/p>\n<pre>$&nbsp;xxx-xxx-gdb&nbsp;a.out\n...\n(gdb)&nbsp;solib-search-path&nbsp;xxx.so:xxx.so\n...\n(gdb)&nbsp;core-file&nbsp;core\n...\n(gdb)&nbsp;bt\n...<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5728linux\u4e0bcore\u600e\u4e48\u4f7f\u7528\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8eLinux,core\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728linux\u4e0bcore\u600e\u4e48\u4f7f\u7528 \u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898\u662f\u300a\u5728linux\u4e0bcore\u600e\u4e48\u4f7f\u7528\u300b\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e\u6587\u7ae0\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01 \u5728linux\u4e0bcore\u662f\u4e00\u4e2a\u5185\u5b58\u6620\u50cf\uff0c\u540c\u65f6\u52a0\u4e0a\u8c03\u8bd5\u4fe1\u606f\uff1b\u5728linux\u4e0b\u9047\u5230\u7a0b\u5e8f\u5f02\u5e38\u9000\u51fa\u6216\u8005\u4e2d\u6b62\uff0c\u6211\u4eec\u90fd\u4f1a\u4f7f\u7528core\u6587\u4ef6\u8fdb\u884c\u5206\u6790\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u5185\u5b58\u3001\u5bc4\u5b58\u5668\u3001\u5806\u6808\u6307\u9488\u7b49\u4fe1\u606f\uff0c\u683c\u5f0f\u4e3aELF\uff0c\u53ef\u4ee5\u7406\u89e3\u662f\u7a0b\u5e8f\u5de5\u4f5c\u5f53\u524d\u72b6\u6001\u8f6c\u50a8\u6210\u4e00\u4e2a\u6587\u4ef6\u3002 \u5728linux\u4e0bcore\u662f\u4ec0\u4e48\uff1f Linux\u4e0bcore\u6587\u4ef6\u7684\u4f7f\u7528\u65b9\u6cd5\u8be6\u89e3 \u6709\u65f6\u5019\u7a0b\u5e8f\u4f1a\u5f02\u5e38\u9000\u51fa\u800c\u4e0d\u5e26\u4efb\u4f55\u65e5\u5fd7\uff0c\u6b64\u65f6\u5c31\u53ef\u4ee5\u4f7f\u7528 code \u6587\u4ef6\u8fdb\u884c\u5206\u6790\uff0c\u5b83\u4f1a\u8bb0\u5f55\u7a0b\u5e8f\u8fd0\u884c\u7684\u5185\u5b58\uff0c\u5bc4\u5b58\u5668\uff0c\u5806\u6808\u6307\u9488\u7b49\u4fe1\u606f core\u6587\u4ef6\uff1a \u901a\u5e38\u5728 Linux \u4e0b\u9047\u5230\u7a0b\u5e8f\u5f02\u5e38\u9000\u51fa\u6216\u8005\u4e2d\u6b62\uff0c\u6211\u4eec\u90fd\u4f1a\u4f7f\u7528 core \u6587\u4ef6\u8fdb\u884c\u5206\u6790\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u5185\u5b58\uff0c\u5bc4\u5b58\u5668\uff0c\u5806\u6808\u6307\u9488\u7b49\u4fe1\u606f\uff0c\u683c\u5f0f\u4e3a ELF \uff0c\u53ef\u4ee5\u7406\u89e3\u662f\u7a0b\u5e8f\u5de5\u4f5c\u5f53\u524d\u72b6\u6001\u8f6c\u50a8\u6210\u4e00\u4e2a\u6587\u4ef6\uff0c\u901a\u8fc7\u5de5\u5177\u5206\u6790\u8fd9\u4e2a\u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4f4d\u5230\u7a0b\u5e8f\u5f02\u5e38\u9000\u51fa\u6216\u8005\u7ec8\u6b62\u65f6\u76f8\u5e94\u7684\u5806\u6808\u8c03\u7528\u7b49\u4fe1\u606f\uff0c\u4e3a\u89e3\u51b3\u95ee\u9898\u63d0\u4f9b\u5e2e\u52a9\u3002 \u4f7f\u7528core\u6587\u4ef6\u8c03\u8bd5 \u751f\u6210\u65b9\u6cd5 \u67e5\u770b\u5f53\u524d core \u6587\u4ef6\u7684\u72b6\u6001 $&nbsp;ulimit&nbsp;-a &#8230; -c:&nbsp;core&nbsp;file&nbsp;size&nbsp;(blocks)&nbsp;&nbsp;&nbsp;0&nbsp;#&nbsp;\u5173\u95ed\u72b6\u6001 &#8230; \u6253\u5f00\u751f\u6210\u5f00\u5173 ulimit&nbsp;-c&nbsp;unlimited ulimit&nbsp;-a &#8230; -c:&nbsp;core&nbsp;file&nbsp;size&nbsp;(blocks)&nbsp;&nbsp;&nbsp;unlimited &#8230; \u5bf9 core \u6587\u4ef6\u7684\u5927\u5c0f\u8fdb\u884c\u9650\u5236\uff0c\u5355\u4f4d\u4e3a blocks \uff0c\u4e00\u822c 1 block=512 bytes \uff0c\u8bbe\u7f6e\u592a\u5c0f\u53ef\u80fd\u5bfc\u81f4\u4e0d\u4f1a\u751f\u6210\u6587\u4ef6 $&nbsp;ulimit&nbsp;-c&nbsp;1024 $&nbsp;ulimit&nbsp;-a &#8230; -c:&nbsp;core&nbsp;file&nbsp;size&nbsp;(blocks)&nbsp;&nbsp;&nbsp;1024 &#8230; \u5173\u95ed\u751f\u6210\u5f00\u5173 ulimit&nbsp;-c&nbsp;0 ulimit&nbsp;-a &#8230; -c:&nbsp;core&nbsp;file&nbsp;size&nbsp;(blocks)&nbsp;&nbsp;&nbsp;0 &#8230; \u4e0a\u9762\u5bf9 core \u6587\u4ef6\u7684\u64cd\u4f5c\u4ec5\u5bf9\u5f53\u524d\u751f\u6548\uff0c\u82e5\u9700\u8981\u6c38\u4e45\u751f\u6548\uff0c\u5219\u8981\u5c06\u76f8\u5e94\u64cd\u4f5c\u5199\u5165 \/etc\/profile [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-52340","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52340"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52340\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}