{"id":120,"date":"2025-06-24T15:33:46","date_gmt":"2025-06-24T07:33:46","guid":{"rendered":"http:\/\/1.14.207.80\/?p=120"},"modified":"2025-06-24T15:33:48","modified_gmt":"2025-06-24T07:33:48","slug":"linux%e5%9f%ba%e7%a1%80%ef%bc%88%e8%bf%9b%e7%a8%8b%e3%80%81%e6%80%a7%e8%83%bd%e7%ae%a1%e7%90%86%e3%80%81%e4%bb%bb%e5%8a%a1%e8%ae%a1%e5%88%92%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.zhangjianjia.xyz\/index.php\/2025\/06\/24\/linux%e5%9f%ba%e7%a1%80%ef%bc%88%e8%bf%9b%e7%a8%8b%e3%80%81%e6%80%a7%e8%83%bd%e7%ae%a1%e7%90%86%e3%80%81%e4%bb%bb%e5%8a%a1%e8%ae%a1%e5%88%92%ef%bc%89\/","title":{"rendered":"Linux\u57fa\u7840\uff08\u8fdb\u7a0b\u3001\u6027\u80fd\u7ba1\u7406\u3001\u4efb\u52a1\u8ba1\u5212\uff09"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><h1>\u8fdb\u7a0b\u3001\u6027\u80fd\u7ba1\u7406\u548c\u4efb\u52a1\u8ba1\u5212<\/h1>\n<h2>\u4ec0\u4e48\u662f\u8fdb\u7a0b<\/h2>\n<ul>\n<li><strong>\u8fdb\u7a0b\uff08Process\uff09<\/strong>\uff1a\u8fd0\u884c\u4e2d\u7684\u7a0b\u5e8f\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff08\u6216\u526f\u672c\uff09\uff0c\u662f\u88ab\u8f7d\u5165\u5185\u5b58\u7684\u4e00\u4e2a\u6307\u4ee4\u96c6\u5408\uff0c\u662f\u7cfb\u7edf\u8d44\u6e90\u5206\u914d\u7684\u57fa\u672c\u5355\u4f4d\u3002<\/li>\n<li><strong>\u8fdb\u7a0bID\uff08PID\uff09<\/strong>\uff1a\u552f\u4e00\u6807\u8bb0\u5404\u4e2a\u8fdb\u7a0b\u3002<\/li>\n<li><strong>\u6743\u9650\u7ee7\u627f<\/strong>\uff1aUID\uff08\u7528\u6237ID\uff09\u3001GID\uff08\u7ec4ID\uff09\u548cSELinux\u8bed\u5883\u51b3\u5b9a\u8fdb\u7a0b\u5bf9\u6587\u4ef6\u7cfb\u7edf\u7684\u5b58\u53d6\u6743\u9650\uff0c\u901a\u5e38\u4ece\u6267\u884c\u8fdb\u7a0b\u7684\u7528\u6237\u7ee7\u627f\u3002<\/li>\n<li><strong>\u751f\u547d\u5468\u671f<\/strong>\uff1a\u4ece\u521b\u5efa\u5230\u7ec8\u6b62\u3002<\/li>\n<\/ul>\n<h3>\u8fdb\u7a0b\u521b\u5efa<\/h3>\n<ul>\n<li><strong>init\/systemd<\/strong>\uff1a\u7b2c\u4e00\u4e2a\u8fdb\u7a0b\uff08\u6839\u8fdb\u7a0b\uff09\u3002CentOS 7+ \u4e2d\u547d\u540d\u4e3a <code>systemd<\/code>\u3002<\/li>\n<li><strong>\u7236\u5b50\u5173\u7cfb<\/strong>\uff1a\u8fdb\u7a0b\u7531\u5176\u7236\u8fdb\u7a0b\u901a\u8fc7 <code>fork()<\/code> \u7b49\u673a\u5236\u521b\u5efa\uff0c\u5f62\u6210\u7236\u5b50\u5173\u7cfb\u3002<\/li>\n<li><strong>Copy-On-Write\uff08COW\uff09<\/strong>\uff1a\u4f18\u5316\u6280\u672f\uff0c\u51cf\u5c11\u8fdb\u7a0b\u521b\u5efa\u65f6\u7684\u5185\u5b58\u4f7f\u7528\u3002<\/li>\n<li><strong>\u8fdb\u7a0b\u8d44\u6e90<\/strong>\uff1a\u5185\u5b58\u3001\u6808\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08fd\uff09\u3002<\/li>\n<\/ul>\n<hr>\n<h2>\u8fdb\u7a0b\u4e0e\u7ebf\u7a0b<\/h2>\n<h3>\u8fdb\u7a0b\uff08Process\uff09<\/h3>\n<ul>\n<li><strong>\u5b9a\u4e49<\/strong>\uff1a\u5177\u6709\u4e00\u5b9a\u72ec\u7acb\u529f\u80fd\u7684\u7a0b\u5e8f\u5728\u6570\u636e\u96c6\u4e0a\u7684\u52a8\u6001\u6267\u884c\u8fc7\u7a0b\uff0c\u662f\u64cd\u4f5c\u7cfb\u7edf\u8d44\u6e90\u5206\u914d\u548c\u8c03\u5ea6\u7684\u72ec\u7acb\u5355\u4f4d\u3002<\/li>\n<li><strong>\u7ec4\u6210<\/strong>\uff1a\n<ul>\n<li>\u7a0b\u5e8f\uff1a\u63cf\u8ff0\u8fdb\u7a0b\u529f\u80fd\u7684\u6307\u4ee4\u96c6\u3002<\/li>\n<li>\u6570\u636e\u96c6\u5408\uff1a\u7a0b\u5e8f\u6267\u884c\u6240\u9700\u7684\u6570\u636e\u548c\u5de5\u4f5c\u533a\u3002<\/li>\n<li>\u8fdb\u7a0b\u63a7\u5236\u5757\uff08PCB\uff09\uff1a\u5305\u542b\u8fdb\u7a0b\u63cf\u8ff0\u548c\u63a7\u5236\u4fe1\u606f\uff0c\u662f\u8fdb\u7a0b\u5b58\u5728\u7684\u552f\u4e00\u6807\u5fd7\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u7279\u5f81<\/strong>\uff1a\n<ul>\n<li>\u52a8\u6001\u6027\uff1a\u4e34\u65f6\u5b58\u5728\uff0c\u6709\u751f\u547d\u5468\u671f\u3002<\/li>\n<li>\u5e76\u53d1\u6027\uff1a\u53ef\u4e0e\u5176\u4ed6\u8fdb\u7a0b\u5e76\u53d1\u6267\u884c\u3002<\/li>\n<li>\u72ec\u7acb\u6027\uff1a\u8d44\u6e90\u5206\u914d\u548c\u8c03\u5ea6\u7684\u72ec\u7acb\u5355\u4f4d\u3002<\/li>\n<li>\u7ed3\u6784\u6027\uff1a\u7531\u7a0b\u5e8f\u3001\u6570\u636e\u96c6\u5408\u548cPCB\u7ec4\u6210\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u7ebf\u7a0b\uff08Threads\uff09<\/h3>\n<ul>\n<li><strong>\u5b9a\u4e49<\/strong>\uff1a\u7a0b\u5e8f\u6267\u884c\u6d41\u7684\u6700\u5c0f\u5355\u5143\uff0c\u5904\u7406\u5668\u8c03\u5ea6\u548c\u5206\u6d3e\u7684\u57fa\u672c\u5355\u4f4d\u3002<\/li>\n<li><strong>\u4e0e\u8fdb\u7a0b\u7684\u5173\u7cfb<\/strong>\uff1a\n<ul>\n<li>\u4e00\u4e2a\u8fdb\u7a0b\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u7ebf\u7a0b\u3002<\/li>\n<li>\u7ebf\u7a0b\u5171\u4eab\u8fdb\u7a0b\u7684\u5185\u5b58\u7a7a\u95f4\uff08\u4ee3\u7801\u6bb5\u3001\u6570\u636e\u96c6\u3001\u5806\u7b49\uff09\u53ca\u8fdb\u7a0b\u7ea7\u8d44\u6e90\uff08\u5982\u6253\u5f00\u7684\u6587\u4ef6\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u7ebf\u7a0b\u7ec4\u6210<\/strong>\uff1a\u7ebf\u7a0bID\u3001\u6307\u4ee4\u6307\u9488\uff08PC\uff09\u3001\u5bc4\u5b58\u5668\u3001\u5806\u6808\u3002<\/li>\n<\/ul>\n<h3>\u8fdb\u7a0b vs \u7ebf\u7a0b<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u7279\u6027<\/strong><\/th>\n<th><strong>\u8fdb\u7a0b<\/strong><\/th>\n<th><strong>\u7ebf\u7a0b<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u8d44\u6e90\u5206\u914d<\/td>\n<td>\u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u8d44\u6e90\u7684\u6700\u5c0f\u5355\u4f4d<\/td>\n<td>CPU\u8c03\u5ea6\u7684\u6700\u5c0f\u5355\u4f4d<\/td>\n<\/tr>\n<tr>\n<td>\u7ec4\u6210<\/td>\n<td>\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u7ebf\u7a0b<\/td>\n<td>\u8fdb\u7a0b\u4e2d\u7684\u4ee3\u7801\u6267\u884c\u8def\u7ebf<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u5b58\u5171\u4eab<\/td>\n<td>\u76f8\u4e92\u72ec\u7acb<\/td>\n<td>\u5171\u4eab\u8fdb\u7a0b\u5185\u5b58\u7a7a\u95f4<\/td>\n<\/tr>\n<tr>\n<td>\u53ef\u89c1\u6027<\/td>\n<td>\u5bf9\u5176\u4ed6\u8fdb\u7a0b\u53ef\u89c1<\/td>\n<td>\u540c\u4e00\u8fdb\u7a0b\u5185\u7ebf\u7a0b\u53ef\u89c1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u67e5\u770b\u7ebf\u7a0b\u4fe1\u606f<\/h3>\n<ul>\n<li><strong>\u7ebf\u7a0b\u72b6\u6001<\/strong>\uff1a<code>cat \/proc\/PID\/status<\/code><\/li>\n<li><strong>\u4e8c\u8fdb\u5236\u6587\u4ef6<\/strong>\uff1a<code>ll \/proc\/PID\/exe<\/code><\/li>\n<li><strong>\u6253\u5f00\u7684\u6587\u4ef6<\/strong>\uff1a<code>\/proc\/PID\/fd\/<\/code><\/li>\n<\/ul>\n<h3><code>\/proc<\/code> \u76ee\u5f55\u8be6\u89e3<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u8def\u5f84<\/strong><\/th>\n<th><strong>\u63cf\u8ff0<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>\/proc\/PID\/exe<\/code><\/td>\n<td>\u7b26\u53f7\u94fe\u63a5\uff0c\u6307\u5411\u542f\u52a8\u8be5\u8fdb\u7a0b\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>\/proc\/PID\/status<\/code><\/td>\n<td>\u5305\u542b\u8fdb\u7a0b\u8be6\u7ec6\u72b6\u6001\uff08PID\u3001PPID\u3001\u72b6\u6001\u3001\u4f18\u5148\u7ea7\u7b49\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>\/proc\/PID\/fd\/<\/code><\/td>\n<td>\u5305\u542b\u4e0e\u8be5\u8fdb\u7a0b\u76f8\u5173\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08\u7b26\u53f7\u94fe\u63a5\u5f62\u5f0f\u6307\u5411\u6587\u4ef6\u6216\u8d44\u6e90\uff09\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2>\u5e76\u884c\u4e0e\u5e76\u53d1<\/h2>\n<ul>\n<li><strong>\u5e76\u53d1<\/strong>\uff1a\u8f6e\u6d41\u6267\u884c\uff08\u5355\u6838CPU\u5904\u7406\u591a\u4efb\u52a1\uff09\u3002<\/li>\n<li><strong>\u5e76\u884c<\/strong>\uff1a\u540c\u65f6\u6267\u884c\uff08\u591a\u6838CPU\u540c\u65f6\u5904\u7406\u4efb\u52a1\uff09\u3002<\/li>\n<\/ul>\n<hr>\n<h2>\u8fdb\u7a0b\u7ed3\u6784<\/h2>\n<ul>\n<li><strong>\u4efb\u52a1\u961f\u5217<\/strong>\uff1a\u5185\u6838\u5c06\u8fdb\u7a0b\u5b58\u653e\u5728\u53cc\u5411\u5faa\u73af\u94fe\u8868\u4e2d\uff0c\u94fe\u8868\u9879\u4e3a <code>task_struct<\/code>\uff08\u8fdb\u7a0b\u63a7\u5236\u5757\uff0cPCB\uff09\u3002<\/li>\n<li><strong>PCB \u5305\u542b\u4fe1\u606f<\/strong>\uff1a\n<ul>\n<li>\u8fdb\u7a0bID\u3001\u7528\u6237ID\u3001\u7ec4ID<\/li>\n<li>\u7a0b\u5e8f\u8ba1\u6570\u5668<\/li>\n<li>\u8fdb\u7a0b\u72b6\u6001\uff08\u5c31\u7eea\u3001\u8fd0\u884c\u3001\u963b\u585e\uff09<\/li>\n<li>CPU\u5bc4\u5b58\u5668\u503c<\/li>\n<li>\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4fe1\u606f<\/li>\n<li>\u63a7\u5236\u7ec8\u7aef\u4fe1\u606f<\/li>\n<li>\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55<\/li>\n<li>\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868<\/li>\n<li>\u8d44\u6e90\u4f7f\u7528\u4e0a\u9650\uff08\u53ef\u901a\u8fc7 <code>ulimit -a<\/code> \u67e5\u770b\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr>\n<h2>\u8fdb\u7a0b\u76f8\u5173\u6982\u5ff5<\/h2>\n<h3>\u5185\u5b58\u7ba1\u7406<\/h3>\n<ul>\n<li><strong>Page Frame<\/strong>\uff1a\u5b58\u50a8\u9875\u9762\u6570\u636e\u7684\u9875\u6846\uff08\u9ed8\u8ba44KB\uff09\u3002<\/li>\n<li><strong>MMU<\/strong>\uff1a\u5185\u5b58\u7ba1\u7406\u5355\u5143\uff0c\u8d1f\u8d23\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u8f6c\u6362\u3002<\/li>\n<li><strong>TLB<\/strong>\uff1a\u7ffb\u8bd1\u540e\u5907\u7f13\u51b2\u533a\uff0c\u7f13\u5b58\u865a\u62df\u5730\u5740\u4e0e\u7269\u7406\u5730\u5740\u7684\u6620\u5c04\u5173\u7cfb\u3002<\/li>\n<\/ul>\n<h3>\u7528\u6237\u4e0e\u5185\u6838\u7a7a\u95f4<\/h3>\n<ul>\n<li><strong>\u7528\u6237\u7a7a\u95f4<\/strong>\uff1a\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u533a\u57df\u3002<\/li>\n<li><strong>\u5185\u6838\u7a7a\u95f4<\/strong>\uff1a\u64cd\u4f5c\u7cfb\u7edf\u6838\u5fc3\u4ee3\u7801\u8fd0\u884c\u533a\u57df\u3002<\/li>\n<\/ul>\n<h3>\u8fdb\u7a0b\u5185\u5b58\u5e03\u5c40<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u6bb5<\/strong><\/th>\n<th><strong>\u7528\u9014<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u4ee3\u7801\u6bb5<\/td>\n<td>\u5b58\u653e\u53ef\u6267\u884c\u6307\u4ee4\uff08\u53ea\u8bfb\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u636e\u6bb5<\/td>\n<td>\u5b58\u653e\u5df2\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\u3002<\/td>\n<\/tr>\n<tr>\n<td>BSS\u6bb5<\/td>\n<td>\u5b58\u653e\u672a\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\uff08\u52a0\u8f7d\u65f6\u521d\u59cb\u5316\u4e3a\u96f6\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u5806\uff08Heap\uff09<\/td>\n<td>\u52a8\u6001\u5206\u914d\u7684\u5185\u5b58\uff08\u5982 <code>malloc<\/code> \u5206\u914d\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6808\uff08Stack\uff09<\/td>\n<td>\u5b58\u653e\u5c40\u90e8\u53d8\u91cf\u3001\u51fd\u6570\u8c03\u7528\u4fe1\u606f\uff08\u53c2\u6570\u3001\u8fd4\u56de\u5730\u5740\u7b49\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u961f\u5217<\/td>\n<td>\u5148\u8fdb\u5148\u51fa\uff08FIFO\uff09\u6570\u636e\u7ed3\u6784\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u5185\u5b58\u95ee\u9898<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u95ee\u9898\u7c7b\u578b<\/strong><\/th>\n<th><strong>\u5b9a\u4e49<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u5185\u5b58\u6cc4\u6f0f<\/td>\n<td>\u7a0b\u5e8f\u7533\u8bf7\u5185\u5b58\u540e\u672a\u91ca\u653e\uff08<code>malloc<\/code>\/<code>new<\/code> \u672a\u914d\u5bf9 <code>free<\/code>\/<code>delete<\/code>\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u5b58\u6ea2\u51fa<\/td>\n<td>\u5411\u7533\u8bf7\u7684\u5185\u5b58\u7a7a\u95f4\u5199\u5165\u8d85\u8fc7\u5176\u5927\u5c0f\u7684\u6570\u636e\uff08\u7f13\u51b2\u533a\u6ea2\u51fa\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u5b58\u4e0d\u8db3<\/td>\n<td>\u7a0b\u5e8f\u65e0\u6cd5\u7533\u8bf7\u5230\u8db3\u591f\u5185\u5b58\uff08OOM\uff09\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Linux \u5185\u6838\u53c2\u6570\u8bbe\u7f6e<\/h3>\n<pre><code class=\"language-bash\"># \u7981\u6b62\u5185\u5b58\u8fc7\u5ea6\u63d0\u4ea4\necho 2 &gt; \/proc\/sys\/vm\/overcommit_memory\n\n# \u8bbe\u7f6e\u7269\u7406RAM\u7684\u8fc7\u5ea6\u63d0\u4ea4\u6bd4\u4f8b\uff0880%\uff09\necho 80 &gt; \/proc\/sys\/vm\/overcommit_ratio\n\n# \u7981\u6b62OOM\u65f6\u91cd\u542f\u7cfb\u7edf\necho 0 &gt; \/proc\/sys\/vm\/panic_on_oom\n<\/code><\/pre>\n<hr>\n<h2>\u8fdb\u7a0b\u72b6\u6001<\/h2>\n<h3>\u57fa\u672c\u72b6\u6001\u53ca\u8f6c\u6362<\/h3>\n<ol>\n<li><strong>\u521b\u5efa\u72b6\u6001<\/strong>\uff1a\u7533\u8bf7\u7a7a\u767dPCB\u5e76\u586b\u5199\u4fe1\u606f\u3002<\/li>\n<li><strong>\u5c31\u7eea\u72b6\u6001<\/strong>\uff1a\u5df2\u5206\u914d\u8d44\u6e90\uff0c\u7b49\u5f85CPU\u8c03\u5ea6\u3002<\/li>\n<li><strong>\u6267\u884c\u72b6\u6001<\/strong>\uff1a\u6b63\u5728\u8fd0\u884c\u3002<\/li>\n<li><strong>\u963b\u585e\u72b6\u6001<\/strong>\uff1a\u7b49\u5f85\u4e8b\u4ef6\uff08\u5982I\/O\u64cd\u4f5c\uff09\u3002<\/li>\n<li><strong>\u7ec8\u6b62\u72b6\u6001<\/strong>\uff1a\u8fdb\u7a0b\u7ed3\u675f\u3002<\/li>\n<li><strong>\u7761\u7720\u6001<\/strong>\uff1a\n<ul>\n<li>\u53ef\u4e2d\u65ad\u7761\u7720\uff08<code>S<\/code>\uff09\uff1a\u53ef\u88ab\u4fe1\u53f7\u5524\u9192\u3002<\/li>\n<li>\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\uff08<code>D<\/code>\uff09\uff1a\u7b49\u5f85I\/O\u5b8c\u6210\uff0c\u4e0d\u53ef\u4e2d\u65ad\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u505c\u6b62\u6001<\/strong>\uff1a\u6682\u505c\u6267\u884c\uff08<code>T<\/code>\uff09\u3002<\/li>\n<li><strong>\u50f5\u6b7b\u6001\uff08Zombie\uff09<\/strong>\uff1a\u8fdb\u7a0b\u5df2\u7ec8\u6b62\uff0c\u4f46\u7236\u8fdb\u7a0b\u672a\u56de\u6536\u8d44\u6e90\uff08<code>Z<\/code>\uff09\u3002<\/li>\n<\/ol>\n<h3>\u72b6\u6001\u8f6c\u6362\u89c4\u5219<\/h3>\n<ul>\n<li><strong>\u8fd0\u884c \u2192 \u5c31\u7eea<\/strong>\uff1a\u65f6\u95f4\u7247\u7528\u5b8c\u6216\u66f4\u9ad8\u4f18\u5148\u7ea7\u8fdb\u7a0b\u62a2\u5360\u3002<\/li>\n<li><strong>\u5c31\u7eea \u2192 \u8fd0\u884c<\/strong>\uff1a\u8c03\u5ea6\u5668\u5206\u914dCPU\u3002<\/li>\n<li><strong>\u8fd0\u884c \u2192 \u963b\u585e<\/strong>\uff1a\u7b49\u5f85\u4e8b\u4ef6\uff08\u5982I\/O\u8bf7\u6c42\uff09\u3002<\/li>\n<li><strong>\u963b\u585e \u2192 \u5c31\u7eea<\/strong>\uff1a\u7b49\u5f85\u4e8b\u4ef6\u53d1\u751f\u3002<\/li>\n<li><strong>\u4e0d\u53ef\u80fd\u8f6c\u6362<\/strong>\uff1a\u963b\u585e \u2192 \u8fd0\u884c\u3001\u5c31\u7eea \u2192 \u963b\u585e\u3002<\/li>\n<\/ul>\n<h3><code>ps -ef<\/code> \u8f93\u51fa\u5c5e\u6027<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u5b57\u6bb5<\/strong><\/th>\n<th><strong>\u8bf4\u660e<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>PID<\/td>\n<td>\u8fdb\u7a0bID\u3002<\/td>\n<\/tr>\n<tr>\n<td>UID<\/td>\n<td>\u542f\u52a8\u8fdb\u7a0b\u7684\u7528\u6237ID\u3002<\/td>\n<\/tr>\n<tr>\n<td>PPID<\/td>\n<td>\u7236\u8fdb\u7a0bID\u3002<\/td>\n<\/tr>\n<tr>\n<td>VSZ<\/td>\n<td>\u865a\u62df\u5185\u5b58\u5927\u5c0f\uff08KB\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>RSS<\/td>\n<td>\u5e38\u9a7b\u5185\u5b58\u96c6\u5927\u5c0f\uff08KB\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>STAT<\/td>\n<td>\u8fdb\u7a0b\u72b6\u6001\uff08<code>R<\/code>\u8fd0\u884c\u3001<code>S<\/code>\u7761\u7720\u3001<code>D<\/code>\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u7b49\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>NI<\/td>\n<td>Nice\u503c\uff08\u4f18\u5148\u7ea7\u8c03\u6574\u503c\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>PRI<\/td>\n<td>\u4f18\u5148\u7ea7\uff08\u6570\u503c\u8d8a\u5c0f\u4f18\u5148\u7ea7\u8d8a\u9ad8\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>RTPRIO<\/td>\n<td>\u5b9e\u65f6\u4f18\u5148\u7ea7\u3002<\/td>\n<\/tr>\n<tr>\n<td>PSR<\/td>\n<td>\u6700\u540e\u8fd0\u884c\u7684CPU\u7f16\u53f7\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2>LRU\u7b97\u6cd5<\/h2>\n<ul>\n<li><strong>\u5b9a\u4e49<\/strong>\uff1a\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\uff08Least Recently Used\uff09\uff0c\u7f13\u5b58\u6dd8\u6c70\u7b56\u7565\u3002<\/li>\n<li><strong>\u539f\u7406<\/strong>\uff1a\u4f18\u5148\u6dd8\u6c70\u6700\u4e45\u672a\u4f7f\u7528\u7684\u6570\u636e\u3002<\/li>\n<li><strong>\u64cd\u4f5c<\/strong>\uff1a\n<ul>\n<li><code>Get<\/code>\uff1a\u5b58\u5728\u5219\u79fb\u81f3\u94fe\u8868\u5934\u90e8\u3002<\/li>\n<li><code>Put<\/code>\uff1a\u63d2\u5165\u65b0\u6570\u636e\u5230\u5934\u90e8\uff1b\u8d85\u5bb9\u65f6\u6dd8\u6c70\u5c3e\u90e8\u6570\u636e\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u590d\u6742\u5ea6<\/strong>\uff1a<code>O(1)<\/code>\uff08\u54c8\u5e0c\u8868+\u53cc\u5411\u94fe\u8868\uff09\u3002<\/li>\n<li><strong>\u5e94\u7528\u573a\u666f<\/strong>\uff1a\u9875\u9762\u7f13\u5b58\u3001\u56fe\u7247\u7f13\u5b58\u3001\u6570\u636e\u5e93\u67e5\u8be2\u7f13\u5b58\u3002<\/li>\n<\/ul>\n<hr>\n<h2>IPC\u8fdb\u7a0b\u95f4\u901a\u4fe1<\/h2>\n<table>\n<thead>\n<tr>\n<th><strong>\u7c7b\u578b<\/strong><\/th>\n<th><strong>\u673a\u5236<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u540c\u4e00\u4e3b\u673a<\/td>\n<td>\u7ba1\u9053\u3001\u5171\u4eab\u5185\u5b58\u3001\u4fe1\u53f7\u91cf\u3001\u6d88\u606f\u961f\u5217\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u4e0d\u540c\u4e3b\u673a<\/td>\n<td>Socket\uff08IP+\u7aef\u53e3\u53f7\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528<\/td>\n<td>RPC\uff08\u5982gRPC\uff09\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2>\u8fdb\u7a0b\u4f18\u5148\u7ea7<\/h2>\n<h3>\u5206\u7c7b<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u7c7b\u578b<\/strong><\/th>\n<th><strong>\u8303\u56f4<\/strong><\/th>\n<th><strong>\u8c03\u5ea6\u7b97\u6cd5<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u5b9e\u65f6\u4f18\u5148\u7ea7<\/td>\n<td>0\u201399<\/td>\n<td>\u5b9e\u65f6\u8c03\u5ea6\u7b97\u6cd5\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u666e\u901a\u4f18\u5148\u7ea7<\/td>\n<td>100\u2013139<\/td>\n<td>\u5b8c\u5168\u516c\u5e73\u8c03\u5ea6\u7b97\u6cd5\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4fee\u6539\u4f18\u5148\u7ea7<\/h3>\n<pre><code class=\"language-bash\"># \u542f\u52a8\u65f6\u8bbe\u7f6eNice\u503c\nnice -n 10 command\n\n# \u8c03\u6574\u8fd0\u884c\u4e2d\u8fdb\u7a0b\u7684Nice\u503c\nrenice 5 -p PID\n<\/code><\/pre>\n<hr>\n<h2>\u8fdb\u7a0b\u7ba1\u7406\u4e0e\u6027\u80fd\u5de5\u5177<\/h2>\n<h3>\u8fdb\u7a0b\u6811\uff08pstree\uff09<\/h3>\n<pre><code class=\"language-bash\">pstree -a -p  # \u663e\u793a\u5b8c\u6574\u547d\u4ee4\u884c\u548cPID\n<\/code><\/pre>\n<h3>ps\u547d\u4ee4<\/h3>\n<pre><code class=\"language-bash\">ps -elf       # \u957f\u683c\u5f0f\u663e\u793a\u8fdb\u7a0b\u4fe1\u606f\nps -eo pid,ni,comm  # \u81ea\u5b9a\u4e49\u8f93\u51fa\u5b57\u6bb5\nps -aux       # \u663e\u793a\u6240\u6709\u7528\u6237\u8fdb\u7a0b\uff08\u542b\u65e0\u63a7\u5236\u7ec8\u7aef\u7684\u8fdb\u7a0b\uff09\n<\/code><\/pre>\n<h3>prtstat<\/h3>\n<pre><code class=\"language-bash\">prtstat -r PID  # \u6253\u5370\u6307\u5b9a\u8fdb\u7a0b\u7684\u7edf\u8ba1\u4fe1\u606f\n<\/code><\/pre>\n<h3>pgrep\/pidof<\/h3>\n<pre><code class=\"language-bash\">pgrep -l nginx    # \u67e5\u627e\u8fdb\u7a0b\u5e76\u663e\u793a\u540d\u79f0\npidof nginx       # \u67e5\u627e\u8fdb\u7a0bID\n<\/code><\/pre>\n<h3>uptime<\/h3>\n<pre><code class=\"language-bash\">uptime -p  # \u6613\u8bfb\u683c\u5f0f\u663e\u793a\u8fd0\u884c\u65f6\u95f4\n<\/code><\/pre>\n<h3>mpstat<\/h3>\n<pre><code class=\"language-bash\">mpstat -P ALL 1  # \u76d1\u63a7\u6240\u6709CPU\u6838\u5fc3\uff08\u6bcf\u79d2\u5237\u65b0\uff09\n<\/code><\/pre>\n<h3>top\u5feb\u6377\u952e<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u5feb\u6377\u952e<\/strong><\/th>\n<th><strong>\u529f\u80fd<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>P<\/code><\/td>\n<td>\u6309CPU\u4f7f\u7528\u7387\u6392\u5e8f\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>M<\/code><\/td>\n<td>\u6309\u5185\u5b58\u4f7f\u7528\u91cf\u6392\u5e8f\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>k<\/code><\/td>\n<td>\u7ec8\u6b62\u8fdb\u7a0b\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>r<\/code><\/td>\n<td>\u8c03\u6574\u8fdb\u7a0b\u4f18\u5148\u7ea7\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>c<\/code><\/td>\n<td>\u5207\u6362\u663e\u793a\u547d\u4ee4\u540d\/\u5b8c\u6574\u547d\u4ee4\u884c\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>free<\/h3>\n<pre><code class=\"language-bash\">free -h  # \u4eba\u6027\u5316\u663e\u793a\u5185\u5b58\u4f7f\u7528\n<\/code><\/pre>\n<h3>\u7f13\u51b2\uff08Buffer\uff09 vs \u7f13\u5b58\uff08Cache\uff09<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u7279\u6027<\/strong><\/th>\n<th><strong>Buffer<\/strong><\/th>\n<th><strong>Cache<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u7528\u9014<\/td>\n<td>\u4e34\u65f6\u5b58\u50a8\u5f85\u5199\u5165\u78c1\u76d8\u7684\u6570\u636e\u3002<\/td>\n<td>\u5b58\u50a8\u4ece\u78c1\u76d8\u8bfb\u53d6\u7684\u6570\u636e\u526f\u672c\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u76ee\u6807<\/td>\n<td>\u4f18\u5316\u5199\u5165\u6027\u80fd\uff08\u5408\u5e76I\/O\uff09\u3002<\/td>\n<td>\u52a0\u901f\u91cd\u590d\u8bfb\u53d6\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u751f\u547d\u5468\u671f<\/td>\n<td>\u6570\u636e\u5199\u5165\u78c1\u76d8\u540e\u91ca\u653e\u3002<\/td>\n<td>\u957f\u671f\u4fdd\u7559\u76f4\u5230\u5185\u5b58\u4e0d\u8db3\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u6e05\u9664\u7f13\u5b58<\/h3>\n<pre><code class=\"language-bash\">sync  # \u540c\u6b65\u6570\u636e\u5230\u78c1\u76d8\necho 3 &gt; \/proc\/sys\/vm\/drop_caches  # \u6e05\u9664\u9875\u9762\/\u76ee\u5f55\u9879\/\u7d22\u5f15\u8282\u70b9\u7f13\u5b58\n<\/code><\/pre>\n<h3>pmap<\/h3>\n<pre><code class=\"language-bash\">pmap -x PID  # \u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u6620\u5c04\n<\/code><\/pre>\n<h3>vmstat<\/h3>\n<pre><code class=\"language-bash\">vmstat 1 5  # \u6bcf\u79d2\u8f93\u51fa1\u6b21\uff0c\u51715\u6b21\n<\/code><\/pre>\n<h3>iostat<\/h3>\n<pre><code class=\"language-bash\">iostat -x -k  # \u6269\u5c55\u7edf\u8ba1+KB\u5355\u4f4d\u663e\u793a\n<\/code><\/pre>\n<h3>\u7f51\u7edc\u76d1\u63a7\u5de5\u5177<\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u5de5\u5177<\/strong><\/th>\n<th><strong>\u529f\u80fd<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>iftop<\/td>\n<td>\u5b9e\u65f6\u6d41\u91cf\u76d1\u63a7\uff08\u6309\u8fde\u63a5\u6392\u5e8f\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>nload<\/td>\n<td>\u7b80\u6d01\u7684\u5b9e\u65f6\u5e26\u5bbd\u76d1\u63a7\u3002<\/td>\n<\/tr>\n<tr>\n<td>NetHogs<\/td>\n<td>\u6309\u8fdb\u7a0b\u663e\u793a\u7f51\u7edc\u6d41\u91cf\u3002<\/td>\n<\/tr>\n<tr>\n<td>iptraf-ng<\/td>\n<td>\u7efc\u5408IP\u6d41\u91cf\u7edf\u8ba1\uff08TCP\/UDP\/ICMP\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>dstat<\/td>\n<td>\u591a\u529f\u80fd\u8d44\u6e90\u7edf\u8ba1\uff08CPU\/\u5185\u5b58\/\u78c1\u76d8\/\u7f51\u7edc\uff09\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>ss\u547d\u4ee4<\/h3>\n<pre><code class=\"language-bash\">ss -t -a  # \u663e\u793a\u6240\u6709TCP\u8fde\u63a5\n<\/code><\/pre>\n<hr>\n<h2>\u4efb\u52a1\u8ba1\u5212<\/h2>\n<h3>at\u547d\u4ee4\uff08\u4e00\u6b21\u6027\u4efb\u52a1\uff09<\/h3>\n<pre><code class=\"language-bash\">echo &quot;tar -zcf \/backup.tgz \/home&quot; | at 02:00  # \u51cc\u66682\u70b9\u5907\u4efd\natq     # \u67e5\u770b\u4efb\u52a1\natrm 1  # \u5220\u9664\u4efb\u52a1ID=1\n<\/code><\/pre>\n<h3>cron\u670d\u52a1\uff08\u5468\u671f\u6027\u4efb\u52a1\uff09<\/h3>\n<pre><code class=\"language-bash\">crontab -e  # \u7f16\u8f91\u8ba1\u5212\u4efb\u52a1\n<\/code><\/pre>\n<p><strong>crontab\u683c\u5f0f<\/strong>\uff1a<\/p>\n<pre><code>* * * * * command\n\u252c \u252c \u252c \u252c \u252c\n\u2502 \u2502 \u2502 \u2502 \u2514\u2500 \u661f\u671f (0\u20137, 0\u548c7\u5747\u4e3a\u5468\u65e5)\n\u2502 \u2502 \u2502 \u2514\u2500\u2500\u2500 \u6708 (1\u201312)\n\u2502 \u2502 \u2514\u2500\u2500\u2500\u2500\u2500 \u65e5 (1\u201331)\n\u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u65f6 (0\u201323)\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u5206 (0\u201359)\n<\/code><\/pre>\n<p><strong>\u7279\u6b8a\u5b57\u7b26\u4e32<\/strong>\uff1a<\/p>\n<ul>\n<li><code>@reboot<\/code>\uff1a\u7cfb\u7edf\u542f\u52a8\u65f6\u8fd0\u884c\u3002<\/li>\n<li><code>@daily<\/code>\uff1a\u6bcf\u5929\u5348\u591c\u8fd0\u884c\u3002<\/li>\n<li><code>@hourly<\/code>\uff1a\u6bcf\u5c0f\u65f6\u8fd0\u884c\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">crontab -l  # \u67e5\u770b\u5f53\u524d\u4efb\u52a1\ncrontab -r  # \u5220\u9664\u6240\u6709\u4efb\u52a1\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-120","post","type-post","status-publish","format-standard","hentry","category-linux"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":1,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":121,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts\/120\/revisions\/121"}],"wp:attachment":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}