{"id":101398,"date":"2026-09-06T19:33:08","date_gmt":"2026-09-06T11:33:08","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/101398.html"},"modified":"2026-09-06T19:33:08","modified_gmt":"2026-09-06T11:33:08","slug":"re-linux%e7%b3%bb%e7%bb%9f%e7%af%87%ef%bc%88%e5%8d%81%e5%85%ab%ef%bc%89%ef%bc%9a%e8%bf%9b%e7%a8%8b%e7%af%87%ef%bc%88%e4%b8%83%ef%bc%89%ef%bc%9a-%e8%bf%9b%e7%a8%8b%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/101398.html","title":{"rendered":"Re: Linux\u7cfb\u7edf\u7bc7\uff08\u5341\u516b\uff09\uff1a\u8fdb\u7a0b\u7bc7\uff08\u4e03\uff09\uff1a \u8fdb\u7a0b\u6df1\u5ea6\u89e3\u6790\uff1a\u4ece fork \u521b\u5efa\u5230\u9000\u51fa\u7684\u5b8c\u6574\u65c5\u7a0b\uff08\u9644\u5199\u65f6\u62f7\u8d1d\u539f\u7406 + \u4ee3\u7801\u5b9e\u6218\uff09"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260906113307-6a9d4f7319505.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p> <b>\u89c2\u4f17\u8001\u7237\u4eec\u5927\u5bb6\u597d \u8fd9\u91cc\u662f\u90aa\u4feeKING\u7684\u72ec\u5bb6\u9891\u9053<\/b><\/p>\n<p> <b>\u672c\u6587\u5c5e\u4e8e\u7cfb\u5217Linux\u7cfb\u7edf\u7bc7 \u2014\u2014\u64cd\u4f5c\u6307\u4ee4<\/b><\/p>\n<p> <b>\u4e00\u8d77\u5b66Linux\u7684\u5c0f\u4f19\u4f34\u53ef\u8ba2\u9605\u4e13\u680f&#xff1a; Linux\u7cfb\u7edf\u7bc7 <\/b><\/p>\n<p>\u6211\u4eec\u5e38\u8bf4 Linux \u662f\u591a\u4efb\u52a1\u64cd\u4f5c\u7cfb\u7edf&#xff0c;\u201c\u4efb\u52a1\u201d \u7684\u6838\u5fc3\u8f7d\u4f53\u5c31\u662f\u8fdb\u7a0b\u3002\u4ece\u4f60\u6572\u4e0b\u4e00\u6761\u7ec8\u7aef\u547d\u4ee4&#xff0c;\u5230\u540e\u53f0\u5e38\u9a7b\u7684\u670d\u52a1\u7a0b\u5e8f&#xff0c;\u672c\u8d28\u90fd\u662f\u4e00\u4e2a\u4e2a\u8fdb\u7a0b\u5728 CPU \u4e0a\u8c03\u5ea6\u8fd0\u884c\u3002\u800c\u8fdb\u7a0b\u4ece\u54ea\u91cc\u6765&#xff1f;\u53c8\u600e\u4e48\u5e73\u7a33\u6d88\u5931&#xff1f;\u8fd9\u80cc\u540e\u85cf\u7740\u64cd\u4f5c\u7cfb\u7edf\u6700\u7ecf\u5178\u7684\u8bbe\u8ba1\u601d\u60f3&#xff1a;fork \u5206\u88c2\u521b\u5efa\u3001\u5199\u65f6\u62f7\u8d1d\u4f18\u5316\u3001\u5206\u5c42\u9000\u51fa\u673a\u5236\u3002<\/p>\n<p>\u4eca\u5929\u6211\u4eec\u987a\u7740\u300c\u521b\u5efa \u2192 \u8fd0\u884c \u2192 \u9000\u51fa \u2192 \u56de\u6536\u300d\u8fd9\u6761\u5b8c\u6574\u94fe\u8def&#xff0c;\u628a\u6bcf\u4e2a\u5e95\u5c42\u673a\u5236\u8bb2\u900f&#xff0c;\u914d\u4e0a\u53ef\u8fd0\u884c\u4ee3\u7801\u548c\u539f\u7406\u793a\u610f\u56fe&#xff0c;\u5f7b\u5e95\u641e\u61c2 Linux \u8fdb\u7a0b\u7684\u4e00\u751f\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u8fdb\u7a0b\u521b\u5efa&#xff1a;fork \u51fd\u6570\u7684\u5206\u88c2\u9b54\u6cd5<\/h3>\n<h4>1.1 fork \u51fd\u6570\u521d\u8bc6&#xff1a;\u4e00\u6b21\u8c03\u7528&#xff0c;\u4e24\u6b21\u8fd4\u56de<\/h4>\n<p>\u5728 Linux \u7cfb\u7edf\u7f16\u7a0b\u4e2d&#xff0c;\u521b\u5efa\u65b0\u8fdb\u7a0b\u6700\u6838\u5fc3\u7684\u51fd\u6570\u5c31\u662ffork()\u3002 \u51fd\u6570\u539f\u578b&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><br \/>\n<span class=\"token class-name\">pid_t<\/span> <span class=\"token function\">fork<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">void<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5f88\u591a\u521d\u5b66\u8005\u7b2c\u4e00\u6b21\u63a5\u89e6 fork \u90fd\u4f1a\u56f0\u60d1&#xff1a;\u4e3a\u4ec0\u4e48\u4e00\u4e2a\u51fd\u6570\u4f1a\u6709\u4e24\u4e2a\u8fd4\u56de\u503c&#xff1f; \u6211\u4eec\u53ef\u4ee5\u628a fork \u7406\u89e3\u6210\u7ec6\u80de\u5206\u88c2&#xff1a;<\/p>\n<ul>\n<li>\u8c03\u7528 fork \u4e4b\u524d&#xff0c;\u53ea\u6709\u4e00\u4e2a\u7236\u8fdb\u7a0b\u5728\u72ec\u7acb\u8fd0\u884c<\/li>\n<li>\u8c03\u7528 fork \u4e4b\u540e&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u590d\u5236\u51fa\u4e00\u4e2a\u51e0\u4e4e\u4e00\u6a21\u4e00\u6837\u7684\u5b50\u8fdb\u7a0b<\/li>\n<li>\u7236\u8fdb\u7a0b\u4e2d&#xff0c;fork \u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684 PID \u53f7&#xff08;\u5927\u4e8e 0 \u7684\u6574\u6570&#xff09;<\/li>\n<li>\u5b50\u8fdb\u7a0b\u4e2d&#xff0c;fork \u8fd4\u56de0<\/li>\n<li>\u521b\u5efa\u5931\u8d25\u65f6&#xff0c;\u8fd4\u56de**-1**<\/li>\n<\/ul>\n<p>\u3010fork \u6267\u884c\u6d41\u793a\u610f\u56fe\u3011<\/p>\n<p>        \u7236\u8fdb\u7a0b (pid&#061;1234)<br \/>\n            |<br \/>\n          fork()<br \/>\n         \/      \\\\<br \/>\n\u7236\u8fdb\u7a0b\u7ee7\u7eed\u6267\u884c   \u5b50\u8fdb\u7a0b\u5f00\u59cb\u6267\u884c<br \/>\n\u8fd4\u56de\u503c&#061;\u5b50PID    \u8fd4\u56de\u503c&#061;0<\/p>\n<p>\u6211\u4eec\u5199\u4e00\u6bb5\u6700\u7b80\u6d4b\u8bd5\u4ee3\u7801&#xff0c;\u76f4\u89c2\u611f\u53d7\u8fd9\u4e2a\u8fc7\u7a0b&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdio.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;&#061;&#061;&#061; fork\u4e4b\u524d&#xff0c;\u53ea\u6709\u7236\u8fdb\u7a0b\u5728\u8fd0\u884c&#xff0c;pid&#061;%d &#061;&#061;&#061;\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">getpid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token class-name\">pid_t<\/span> id <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">fork<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>id <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5b50\u8fdb\u7a0b\u6267\u884c\u5206\u652f<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6211\u662f\u5b50\u8fdb\u7a0b&#xff0c;pid&#061;%d&#xff0c;fork\u8fd4\u56de\u503c &#061; %d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">getpid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>id <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u7236\u8fdb\u7a0b\u6267\u884c\u5206\u652f<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6211\u662f\u7236\u8fdb\u7a0b&#xff0c;pid&#061;%d&#xff0c;fork\u8fd4\u56de\u503c &#061; %d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">getpid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;fork\u521b\u5efa\u5931\u8d25&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c\u89e3\u8bfb&#xff1a; fork\u4e4b\u524d\u7684\u5185\u5bb9\u53ea\u4f1a\u6253\u5370\u4e00\u6b21&#xff0c;\u800c\u540e\u7eed\u4e24\u884c\u4f1a\u5206\u522b\u8f93\u51fa\u7236\u5b50\u8fdb\u7a0b\u7684\u4fe1\u606f\u3002\u8fd9\u5c31\u8bc1\u660e&#xff1a;fork \u4e4b\u540e\u4ee3\u7801\u6267\u884c\u6d41\u4e00\u5206\u4e3a\u4e8c&#xff0c;\u4e24\u4e2a\u8fdb\u7a0b\u5404\u81ea\u72ec\u7acb\u6267\u884c\u540e\u7eed\u4ee3\u7801\u3002<\/p>\n<h4>1.2 fork \u4e4b\u540e\u7684\u6267\u884c\u6d41\u8868\u73b0<\/h4>\n<p>\u5f88\u591a\u4eba\u4f1a\u95ee&#xff1a;fork \u4e4b\u540e\u662f\u7236\u8fdb\u7a0b\u5148\u8fd0\u884c&#xff0c;\u8fd8\u662f\u5b50\u8fdb\u7a0b\u5148\u8fd0\u884c&#xff1f; \u7b54\u6848\u662f&#xff1a;\u5b8c\u5168\u4e0d\u786e\u5b9a&#xff0c;\u7531\u64cd\u4f5c\u7cfb\u7edf\u7684\u8fdb\u7a0b\u8c03\u5ea6\u5668\u51b3\u5b9a\u3002<\/p>\n<p>\u7236\u5b50\u8fdb\u7a0b\u662f\u4e24\u4e2a\u5b8c\u5168\u72ec\u7acb\u7684\u6267\u884c\u5355\u5143&#xff0c;\u8c01\u5148\u62a2\u5230 CPU \u65f6\u95f4\u7247\u8c01\u5c31\u5148\u6267\u884c\u3002\u5355\u6838 CPU \u4e0a\u662f\u5206\u65f6\u4ea4\u66ff\u8fd0\u884c&#xff0c;\u591a\u6838 CPU \u4e0a\u751a\u81f3\u53ef\u4ee5\u771f\u6b63\u540c\u65f6\u8fd0\u884c\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u7528\u5faa\u73af\u6253\u5370\u9a8c\u8bc1\u8c03\u5ea6\u7684\u968f\u673a\u6027&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdio.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">fork<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u7236\u5b50\u8fdb\u7a0b\u90fd\u4f1a\u6267\u884c\u8fd9\u6bb5\u5faa\u73af<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;pid&#061;%d, \u6253\u5370\u7b2c%d\u6b21\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">getpid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> i<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u591a\u6b21\u8fd0\u884c\u4f60\u4f1a\u53d1\u73b0&#xff0c;\u8f93\u51fa\u987a\u5e8f\u6bcf\u6b21\u90fd\u53ef\u80fd\u4e0d\u540c&#xff0c;\u8fd9\u5c31\u662f\u5185\u6838\u8c03\u5ea6\u7684\u968f\u673a\u6027\u3002<\/p>\n<h4>1.3 \u5199\u65f6\u62f7\u8d1d&#xff08;Copy-On-Write&#xff09;&#xff1a;fork \u7684\u7075\u9b42\u4f18\u5316<\/h4>\n<p>\u5982\u679c fork \u771f\u7684\u628a\u7236\u8fdb\u7a0b\u6240\u6709\u5185\u5b58\u5b8c\u5b8c\u6574\u6574\u590d\u5236\u4e00\u4efd&#xff0c;\u90a3\u521b\u5efa\u5927\u8fdb\u7a0b\u4f1a\u975e\u5e38\u6162&#xff1b;\u800c\u4e14\u5f88\u591a\u573a\u666f\u4e0b&#xff0c;\u5b50\u8fdb\u7a0b\u521b\u5efa\u540e\u9a6c\u4e0a\u4f1a\u6267\u884c\u5168\u65b0\u7684\u7a0b\u5e8f&#xff0c;\u539f\u6765\u7684\u5185\u5b58\u6839\u672c\u7528\u4e0d\u4e0a&#xff0c;\u590d\u5236\u5c31\u6210\u4e86\u7eaf\u6d6a\u8d39\u3002<\/p>\n<p>\u4e8e\u662f Linux \u8bbe\u8ba1\u4e86\u5199\u65f6\u62f7\u8d1d&#xff08;COW&#xff09; \u673a\u5236&#xff0c;\u8fd9\u662f\u64cd\u4f5c\u7cfb\u7edf \u201c\u60f0\u6027\u4f18\u5316\u201d \u601d\u60f3\u7684\u7ecf\u5178\u4f53\u73b0\u3002<\/p>\n<h5>1.3.1 \u5199\u65f6\u62f7\u8d1d\u662f\u5982\u4f55\u5b9e\u73b0\u7684<\/h5>\n<p>fork \u521b\u5efa\u5b50\u8fdb\u7a0b\u65f6&#xff0c;\u5e76\u4e0d\u4f1a\u7acb\u523b\u590d\u5236\u7269\u7406\u5185\u5b58&#xff0c;\u800c\u662f\u8ba9\u7236\u5b50\u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4&#xff0c;\u6620\u5c04\u5230\u540c\u4e00\u5757\u7269\u7406\u5185\u5b58\u9875\u9762\u4e0a&#xff0c;\u540c\u65f6\u628a\u8fd9\u4e9b\u9875\u9762\u7684\u6743\u9650\u6807\u8bb0\u4e3a \u201c\u53ea\u8bfb\u201d\u3002<\/p>\n<ul>\n<li>\u5f53\u7236\u5b50\u8fdb\u7a0b\u90fd\u53ea\u662f\u8bfb\u53d6\u6570\u636e\u65f6&#xff0c;\u5927\u5bb6\u5171\u4eab\u540c\u4e00\u4efd\u7269\u7406\u5185\u5b58&#xff0c;\u76f8\u5b89\u65e0\u4e8b<\/li>\n<li>\u4e00\u65e6\u4efb\u610f\u4e00\u65b9\u5c1d\u8bd5\u4fee\u6539\u5185\u5b58&#xff0c;CPU \u5c31\u4f1a\u89e6\u53d1\u9875\u9519\u8bef&#xff08;Page Fault&#xff09;<\/li>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u6355\u83b7\u5f02\u5e38\u540e&#xff0c;\u5206\u914d\u65b0\u7684\u7269\u7406\u9875\u3001\u590d\u5236\u6570\u636e\u3001\u66f4\u65b0\u9875\u8868\u6620\u5c04&#xff0c;\u518d\u8ba9\u8fdb\u7a0b\u7ee7\u7eed\u6267\u884c<\/li>\n<\/ul>\n<p>\u3010\u5199\u65f6\u62f7\u8d1d\u539f\u7406\u793a\u610f\u56fe\u3011<\/p>\n<p>\u4fee\u6539\u524d&#xff1a;<br \/>\n\u7236\u8fdb\u7a0b\u865a\u62df\u5730\u5740 \u2192 \u7269\u7406\u9875A&#xff08;\u53ea\u8bfb\u6807\u8bb0&#xff09;<br \/>\n\u5b50\u8fdb\u7a0b\u865a\u62df\u5730\u5740 \u2192 \u7269\u7406\u9875A&#xff08;\u53ea\u8bfb\u6807\u8bb0&#xff09;<\/p>\n<p>\u5b50\u8fdb\u7a0b\u4fee\u6539\u6570\u636e\u540e&#xff1a;<br \/>\n\u7236\u8fdb\u7a0b\u865a\u62df\u5730\u5740 \u2192 \u7269\u7406\u9875A&#xff08;\u4fdd\u6301\u53ea\u8bfb&#xff09;<br \/>\n\u5b50\u8fdb\u7a0b\u865a\u62df\u5730\u5740 \u2192 \u7269\u7406\u9875B&#xff08;\u8bfb\u5199\u6743\u9650&#xff0c;\u590d\u5236\u4e86A\u7684\u5168\u90e8\u6570\u636e&#xff09;<\/p>\n<h5>1.3.2 \u4e3a\u4ec0\u4e48\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u53d1\u751f\u5199\u65f6\u62f7\u8d1d<\/h5>\n<p>\u672c\u8d28\u662f**\u201c\u80fd\u665a\u505a\u5c31\u665a\u505a\u3001\u80fd\u4e0d\u505a\u5c31\u4e0d\u505a\u201d \u7684\u60f0\u6027\u601d\u60f3**\u3002 \u6700\u5178\u578b\u7684\u573a\u666f\u5c31\u662f shell \u6267\u884c\u547d\u4ee4&#xff1a;shell fork \u51fa\u5b50\u8fdb\u7a0b&#xff0c;\u5b50\u8fdb\u7a0b\u7acb\u523b\u52a0\u8f7d\u65b0\u7684\u547d\u4ee4\u7a0b\u5e8f&#xff0c;\u539f\u6765\u7684\u5185\u5b58\u6570\u636e\u5b8c\u5168\u7528\u4e0d\u4e0a\u3002\u5982\u679c fork \u65f6\u5168\u91cf\u590d\u5236&#xff0c;\u6240\u6709\u62f7\u8d1d\u5de5\u4f5c\u90fd\u4f1a\u767d\u767d\u6d6a\u8d39\u3002\u5199\u65f6\u62f7\u8d1d\u5b8c\u7f8e\u907f\u5f00\u4e86\u8fd9\u79cd\u65e0\u610f\u4e49\u7684\u5f00\u9500\u3002<\/p>\n<h5>1.3.3 \u64cd\u4f5c\u7cfb\u7edf\u600e\u4e48\u5206\u8fa8\u54ea\u4e9b\u662f\u6570\u636e\u6bb5<\/h5>\n<p>\u4e0d\u662f\u6240\u6709\u5185\u5b58\u90fd\u4f1a\u89e6\u53d1\u5199\u65f6\u62f7\u8d1d&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7\u9875\u8868\u6807\u8bb0\u7cbe\u51c6\u533a\u5206&#xff1a;<\/p>\n<ul>\n<li>\u4ee3\u7801\u6bb5&#xff1a;\u672c\u8eab\u5c31\u662f\u53ea\u8bfb\u5c5e\u6027&#xff0c;\u7236\u5b50\u8fdb\u7a0b\u6c38\u4e45\u5171\u4eab&#xff0c;\u6c38\u8fdc\u4e0d\u9700\u8981\u62f7\u8d1d<\/li>\n<li>\u6570\u636e\u6bb5\u3001\u5806\u3001\u6808&#xff1a;\u53ef\u8bfb\u5199\u533a\u57df&#xff0c;\u624d\u4f1a\u8bbe\u7f6e\u5199\u65f6\u62f7\u8d1d\u6807\u8bb0 \u53ea\u6709\u53ef\u5199\u533a\u57df\u7684\u5199\u5165\u64cd\u4f5c&#xff0c;\u624d\u4f1a\u89e6\u53d1\u9875\u9519\u8bef\u548c\u62f7\u8d1d\u6d41\u7a0b\u3002<\/li>\n<\/ul>\n<h5>1.3.4 \u67e5\u8be2\u9875\u8868\u7684\u51e0\u79cd\u60c5\u51b5<\/h5>\n<li>\u53ea\u8bfb\u8bbf\u95ee&#xff1a;\u76f4\u63a5\u5171\u4eab\u7269\u7406\u9875&#xff0c;\u4e0d\u505a\u4efb\u4f55\u989d\u5916\u64cd\u4f5c<\/li>\n<li>\u5199\u5165\u8bbf\u95ee&#xff1a;\u89e6\u53d1\u9875\u9519\u8bef&#xff0c;\u6267\u884c\u5199\u65f6\u62f7\u8d1d&#xff0c;\u5206\u914d\u72ec\u7acb\u7684\u65b0\u9875\u9762<\/li>\n<li>\u6267\u884c\u8bbf\u95ee&#xff1a;\u4ee3\u7801\u6bb5\u53ea\u8bfb\u53ef\u6267\u884c&#xff0c;\u76f4\u63a5\u5171\u4eab\u5373\u53ef<\/li>\n<h5>1.3.5 \u4e3a\u4ec0\u4e48\u4e00\u5b9a\u8981\u8bbe\u8ba1\u5199\u65f6\u62f7\u8d1d<\/h5>\n<ul>\n<li>\u63d0\u5347 fork \u6027\u80fd&#xff1a;\u4e0d\u7528\u590d\u5236\u5927\u91cf\u5185\u5b58&#xff0c;fork \u51e0\u4e4e\u53ef\u4ee5\u77ac\u95f4\u5b8c\u6210<\/li>\n<li>\u8282\u7701\u5185\u5b58\u8d44\u6e90&#xff1a;\u53ea\u8bfb\u6570\u636e\u5168\u5c40\u5171\u4eab&#xff0c;\u5185\u5b58\u5229\u7528\u7387\u5927\u5e45\u63d0\u9ad8<\/li>\n<li>\u9002\u914d exec \u573a\u666f&#xff1a;\u5b50\u8fdb\u7a0b\u6267\u884c\u65b0\u7a0b\u5e8f\u65f6&#xff0c;\u65e7\u5185\u5b58\u76f4\u63a5\u91ca\u653e&#xff0c;\u6ca1\u6709\u591a\u4f59\u5f00\u9500<\/li>\n<\/ul>\n<h5>1.3.6 \u8bfb\u5199\u6743\u9650\u7684\u6062\u590d\u6ce8\u610f\u4e8b\u9879<\/h5>\n<ul>\n<li>\u62f7\u8d1d\u5b8c\u6210\u540e&#xff0c;\u65b0\u5206\u914d\u7684\u9875\u9762\u4f1a\u6062\u590d\u8bfb\u5199\u6743\u9650&#xff0c;\u4f9b\u4fee\u6539\u7684\u8fdb\u7a0b\u72ec\u7acb\u4f7f\u7528<\/li>\n<li>\u539f\u6765\u7684\u65e7\u9875\u9762\u5982\u679c\u8fd8\u6709\u5176\u4ed6\u8fdb\u7a0b\u5171\u4eab&#xff0c;\u4f1a\u7ee7\u7eed\u4fdd\u6301\u53ea\u8bfb\u72b6\u6001<\/li>\n<li>\u5f53\u6700\u540e\u4e00\u4e2a\u5171\u4eab\u8fdb\u7a0b\u4e5f\u9000\u51fa\u6216\u4fee\u6539\u540e&#xff0c;\u65e7\u9875\u9762\u624d\u4f1a\u6062\u590d\u6b63\u5e38\u8bfb\u5199\u6743\u9650<\/li>\n<\/ul>\n<h4>1.4 fork \u5e38\u89c1\u7528\u6cd5<\/h4>\n<p>fork \u7684\u76ee\u7684\u4ece\u6765\u4e0d\u662f\u521b\u5efa\u4e24\u4e2a\u4e00\u6a21\u4e00\u6837\u7684\u8fdb\u7a0b&#xff0c;\u5b9e\u9645\u5f00\u53d1\u4e2d\u4e3b\u8981\u6709\u4e24\u79cd\u7ecf\u5178\u7528\u6cd5&#xff1a;<\/p>\n<p>\u7528\u6cd5 1&#xff1a;\u4e3b\u8fdb\u7a0b\u6d3e\u751f\u5b50\u8fdb\u7a0b\u5904\u7406\u4efb\u52a1 \u6bd4\u5982\u7f51\u7edc\u670d\u52a1\u5668\u6a21\u578b&#xff0c;\u4e3b\u8fdb\u7a0b\u8d1f\u8d23\u76d1\u542c\u8fde\u63a5&#xff0c;\u6bcf\u6765\u4e00\u4e2a\u5ba2\u6237\u7aef\u5c31 fork \u5b50\u8fdb\u7a0b\u53bb\u5904\u7406\u4ea4\u4e92&#xff0c;\u4e3b\u8fdb\u7a0b\u7ee7\u7eed\u7b49\u5f85\u65b0\u8fde\u63a5\u3002<\/p>\n<p><span class=\"token comment\">\/\/ \u7b80\u5316\u7248\u7f51\u7edc\u670d\u52a1\u6a21\u578b<\/span><br \/>\n<span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> client <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">accept<\/span><span class=\"token punctuation\">(<\/span>listen_fd<span class=\"token punctuation\">,<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token class-name\">pid_t<\/span> pid <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">fork<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>pid <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5b50\u8fdb\u7a0b&#xff1a;\u5904\u7406\u5ba2\u6237\u7aef\u4e1a\u52a1\u903b\u8f91<\/span><br \/>\n        <span class=\"token function\">handle_client<\/span><span class=\"token punctuation\">(<\/span>client<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u7236\u8fdb\u7a0b&#xff1a;\u5173\u95ed\u5ba2\u6237\u7aef\u63cf\u8ff0\u7b26&#xff0c;\u7ee7\u7eed\u5faa\u73af\u7b49\u5f85<\/span><br \/>\n    <span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span>client<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7528\u6cd5 2&#xff1a;fork &#043; exec \u6267\u884c\u5168\u65b0\u7a0b\u5e8f \u8fd9\u5c31\u662f shell \u7ec8\u7aef\u7684\u5de5\u4f5c\u539f\u7406&#xff1a;\u4f60\u8f93\u5165\u4e00\u6761\u547d\u4ee4&#xff0c;shell fork \u51fa\u5b50\u8fdb\u7a0b&#xff0c;\u5b50\u8fdb\u7a0b\u8c03\u7528 exec \u52a0\u8f7d\u547d\u4ee4\u7a0b\u5e8f&#xff0c;\u66ff\u6362\u6389\u81ea\u5df1\u7684\u5185\u5b58\u7a7a\u95f4&#xff0c;\u6267\u884c\u65b0\u7684\u7a0b\u5e8f\u903b\u8f91\u3002<\/p>\n<h4>1.5 fork \u8c03\u7528\u5931\u8d25\u7684\u539f\u56e0<\/h4>\n<p>fork \u4e0d\u662f\u6c38\u8fdc\u80fd\u6210\u529f&#xff0c;\u5e38\u89c1\u5931\u8d25\u539f\u56e0\u6709\u4e09\u7c7b&#xff1a;<\/p>\n<li>\u7528\u6237\u8fdb\u7a0b\u6570\u8fbe\u5230\u4e0a\u9650&#xff1a;\u6bcf\u4e2a\u7528\u6237\u90fd\u6709\u6700\u5927\u8fdb\u7a0b\u6570\u9650\u5236&#xff0c;\u53ef\u901a\u8fc7ulimit -u\u67e5\u770b<\/li>\n<li>\u7cfb\u7edf\u5185\u5b58\u4e0d\u8db3&#xff1a;\u8fde\u9875\u8868\u7ed3\u6784\u90fd\u65e0\u6cd5\u5206\u914d\u65f6<\/li>\n<li>\u7cfb\u7edf PID \u8fbe\u5230\u4e0a\u9650&#xff1a;\u5185\u6838\u53c2\u6570pid_max\u8017\u5c3d&#xff0c;\u65e0\u6cd5\u5206\u914d\u65b0\u7684\u8fdb\u7a0b\u53f7<\/li>\n<hr \/>\n<h3>\u4e8c\u3001\u8fdb\u7a0b\u9000\u51fa&#xff1a;\u5584\u59cb\u4e5f\u8981\u5584\u7ec8<\/h3>\n<p>\u8fdb\u7a0b\u6709\u521b\u5efa\u5c31\u6709\u9000\u51fa&#xff0c;\u9000\u51fa\u4e0d\u662f\u7b80\u5355\u7684 \u201c\u6d88\u5931\u201d&#xff0c;\u800c\u662f\u6709\u4e00\u5957\u5b8c\u6574\u7684\u6e05\u7406\u3001\u4f20\u503c\u3001\u56de\u6536\u6d41\u7a0b\u3002<\/p>\n<h4>2.1 \u8fdb\u7a0b\u9000\u51fa\u573a\u666f<\/h4>\n<h5>2.1.1 \u8fdb\u7a0b\u9000\u51fa\u7684\u4e09\u79cd\u573a\u666f<\/h5>\n<li>\u6b63\u5e38\u8fd0\u884c\u7ed3\u675f&#xff0c;\u81ea\u613f\u9000\u51fa&#xff1a;main \u51fd\u6570\u6267\u884c return \u8fd4\u56de<\/li>\n<li>\u4e3b\u52a8\u8c03\u7528\u9000\u51fa\u51fd\u6570&#xff0c;\u81ea\u613f\u9000\u51fa&#xff1a;\u4ee3\u7801\u4e2d\u8c03\u7528exit()\u3001_exit()<\/li>\n<li>\u5f02\u5e38\u7ec8\u6b62&#xff0c;\u88ab\u8feb\u9000\u51fa&#xff1a;\u6536\u5230\u5916\u90e8\u4fe1\u53f7&#xff08;Ctrl&#043;C\u3001kill \u547d\u4ee4&#xff09;\u3001\u6bb5\u9519\u8bef\u5d29\u6e83\u3001\u8c03\u7528 abort \u7ec8\u6b62<\/li>\n<h5>2.1.2 \u4ec0\u4e48\u662f\u9000\u51fa\u7801<\/h5>\n<p>\u8fdb\u7a0b\u9000\u51fa\u65f6&#xff0c;\u4f1a\u7ed9\u7236\u8fdb\u7a0b\u7559\u4e0b\u4e00\u4e2a8 \u4f4d\u7684\u9000\u51fa\u72b6\u6001\u7801&#xff08;\u53d6\u503c 0~255&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u884c\u4e1a\u7ea6\u5b9a&#xff1a;0 \u4ee3\u8868\u7a0b\u5e8f\u6267\u884c\u6210\u529f&#xff0c;\u975e0 \u4ee3\u8868\u6267\u884c\u5931\u8d25<\/li>\n<li>\u4e0d\u540c\u7684\u975e 0 \u503c\u5bf9\u5e94\u4e0d\u540c\u7684\u9519\u8bef\u539f\u56e0&#xff0c;\u65b9\u4fbf\u7236\u8fdb\u7a0b\u5224\u65ad\u5b50\u8fdb\u7a0b\u7684\u6267\u884c\u7ed3\u679c<\/li>\n<\/ul>\n<h4>2.2 \u8fdb\u7a0b\u5e38\u89c1\u9000\u51fa\u65b9\u6cd5\u4e0e\u6838\u5fc3\u673a\u5236<\/h4>\n<h5>2.2.1 return \u673a\u5236\u4e0e\u8fd4\u56de\u503c\u7f16\u7801\u539f\u7406<\/h5>\n<p>\u53ea\u6709\u5728main\u51fd\u6570\u91cc\u6267\u884creturn\u624d\u4f1a\u89e6\u53d1\u8fdb\u7a0b\u9000\u51fa&#xff0c;\u666e\u901a\u51fd\u6570\u7684 return \u53ea\u662f\u8fd4\u56de\u51fd\u6570\u503c\u3002 main \u51fd\u6570 return \u7684\u8fd4\u56de\u503c&#xff0c;\u6700\u7ec8\u4f1a\u88ab\u7cfb\u7edf\u4f20\u9012\u7ed9 exit \u51fd\u6570&#xff0c;\u672c\u8d28\u4e0a\u8fd8\u662f\u8d70 exit \u7684\u5b8c\u6574\u9000\u51fa\u6d41\u7a0b\u3002<\/p>\n<h5>2.2.2 exit \u4e0e _exit \u7684\u5e95\u5c42\u533a\u522b<\/h5>\n<p>\u8fd9\u662f\u7cfb\u7edf\u7f16\u7a0b\u7684\u9ad8\u9891\u8003\u70b9&#xff0c;\u4e8c\u8005\u6838\u5fc3\u5dee\u5f02\u5728\u4e8e\u662f\u5728\u7528\u6237\u6001\u6e05\u7406\u8fd8\u662f\u76f4\u63a5\u8fdb\u5185\u6838\u3002<\/p>\n<p>\u8868\u683c<\/p>\n<table>\n<tr>\u51fd\u6570\u5c42\u7ea7\u6267\u884c\u884c\u4e3a<\/tr>\n<tbody>\n<tr>\n<td>exit()<\/td>\n<td>C \u5e93\u51fd\u6570<\/td>\n<td>1. \u6267\u884c\u7528\u6237\u6ce8\u518c\u7684 atexit \u6e05\u7406\u51fd\u65702. \u5237\u65b0\u6240\u6709 C \u5e93 IO \u7f13\u51b2\u533a3. \u5173\u95ed\u6253\u5f00\u7684\u6587\u4ef6\u6d414. \u6700\u7ec8\u8c03\u7528_exit\u8fdb\u5165\u5185\u6838<\/td>\n<\/tr>\n<tr>\n<td>_exit()<\/td>\n<td>\u7cfb\u7edf\u8c03\u7528<\/td>\n<td>\u76f4\u63a5\u9677\u5165\u5185\u6838&#xff0c;\u91ca\u653e\u8fdb\u7a0b\u8d44\u6e90&#xff0c;\u4e0d\u5904\u7406\u4efb\u4f55\u7528\u6237\u6001\u6570\u636e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6700\u76f4\u89c2\u7684\u533a\u522b\u5c31\u662f\u5bf9 IO \u7f13\u51b2\u533a\u7684\u5904\u7406&#xff0c;\u6211\u4eec\u7528\u4ee3\u7801\u5c31\u80fd\u9a8c\u8bc1&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdio.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdlib.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;hello linux&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6ce8\u610f&#xff1a;\u6ca1\u6709\u52a0\\\\n&#xff0c;\u7f13\u51b2\u533a\u4e0d\u4f1a\u81ea\u52a8\u5237\u65b0<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u5206\u522b\u6ce8\u91ca\u4e24\u884c\u6d4b\u8bd5\u6548\u679c<\/span><br \/>\n    <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ \u4f1a\u6253\u5370 hello linux<\/span><br \/>\n    <span class=\"token comment\">\/\/ _exit(0); \/\/ \u4e0d\u4f1a\u6253\u5370&#xff0c;\u7f13\u51b2\u533a\u76f4\u63a5\u4e22\u5f03<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u539f\u7406\u8bf4\u660e&#xff1a;printf \u662f C \u5e93\u51fd\u6570&#xff0c;\u7ec8\u7aef\u9ed8\u8ba4\u884c\u7f13\u51b2&#xff0c;\u9047\u5230\\\\n\u624d\u4f1a\u628a\u6570\u636e\u5237\u5230\u5c4f\u5e55\u3002\u6ca1\u52a0\\\\n\u65f6&#xff0c;\u6570\u636e\u8fd8\u505c\u7559\u5728\u7528\u6237\u6001\u7684\u7f13\u51b2\u533a\u91cc\u3002<\/p>\n<ul>\n<li>exit\u4f1a\u4e3b\u52a8\u5237\u65b0\u6240\u6709\u7f13\u51b2\u533a&#xff0c;\u6240\u4ee5\u5185\u5bb9\u80fd\u6b63\u5e38\u6253\u5370<\/li>\n<li>_exit\u76f4\u63a5\u8fdb\u5165\u5185\u6838&#xff0c;\u7528\u6237\u6001\u7f13\u51b2\u533a\u76f4\u63a5\u88ab\u4e22\u5f03&#xff0c;\u6240\u4ee5\u4ec0\u4e48\u90fd\u4e0d\u8f93\u51fa<\/li>\n<\/ul>\n<h5>2.2.3 \u6df1\u5ea6\u89e3\u5256&#xff1a;\u6211\u4eec\u8c08\u8bba\u7684\u7f13\u51b2\u533a<\/h5>\n<p>\u8fd9\u91cc\u7684\u7f13\u51b2\u533a\u662fC \u6807\u51c6\u5e93\u5728\u7528\u6237\u6001\u7ef4\u62a4\u7684 IO \u7f13\u51b2\u533a&#xff0c;\u548c\u5185\u6838\u7f13\u51b2\u533a\u4e0d\u662f\u4e00\u56de\u4e8b\u3002\u5206\u4e3a\u4e09\u79cd\u7c7b\u578b&#xff1a;<\/p>\n<ul>\n<li>\u5168\u7f13\u51b2&#xff1a;\u666e\u901a\u6587\u4ef6\u9ed8\u8ba4&#xff0c;\u7f13\u51b2\u533a\u6ee1\u4e86\u624d\u5237\u65b0<\/li>\n<li>\u884c\u7f13\u51b2&#xff1a;\u7ec8\u7aef\u9ed8\u8ba4&#xff0c;\u9047\u5230\u6362\u884c\u7b26\\\\n\u624d\u5237\u65b0<\/li>\n<li>\u65e0\u7f13\u51b2&#xff1a;\u6bd4\u5982\u6807\u51c6\u9519\u8bef\u8f93\u51fa stderr&#xff0c;\u51fa\u9519\u7acb\u523b\u8f93\u51fa<\/li>\n<\/ul>\n<p>\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u7f16\u7801\u89c4\u8303\u91cc\u5e38\u5efa\u8bae printf \u52a0\\\\n\u2014\u2014 \u4e0d\u53ea\u662f\u6362\u884c&#xff0c;\u66f4\u662f\u786e\u4fdd\u5185\u5bb9\u53ca\u65f6\u8f93\u51fa&#xff0c;\u4e0d\u4f1a\u7559\u5728\u7f13\u51b2\u533a\u91cc\u4e22\u5931\u3002<\/p>\n<h4>2.3 \u9000\u51fa\u7801\u7684\u56de\u6536\u4e0e\u8bbf\u95ee<\/h4>\n<p>\u5b50\u8fdb\u7a0b\u9000\u51fa\u540e&#xff0c;\u7cfb\u7edf\u8d44\u6e90\u4e0d\u4f1a\u7acb\u523b\u91ca\u653e&#xff0c;\u5fc5\u987b\u7531\u7236\u8fdb\u7a0b\u56de\u6536&#xff0c;\u5426\u5219\u5b50\u8fdb\u7a0b\u4f1a\u53d8\u6210 \u201c\u50f5\u5c38\u8fdb\u7a0b\u201d&#xff0c;\u5360\u7528\u7cfb\u7edf\u8d44\u6e90\u3002<\/p>\n<h5>2.3.1 \u5b50\u8fdb\u7a0b\u9000\u51fa\u7801\u56de\u6536<\/h5>\n<p>\u7236\u8fdb\u7a0b\u901a\u8fc7wait()\u6216waitpid()\u51fd\u6570\u7b49\u5f85\u5b50\u8fdb\u7a0b\u9000\u51fa&#xff0c;\u540c\u65f6\u83b7\u53d6\u9000\u51fa\u72b6\u6001\u4fe1\u606f\u3002<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdio.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;sys\/wait.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdlib.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">pid_t<\/span> pid <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">fork<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>pid <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5b50\u8fdb\u7a0b\u5f00\u59cb\u8fd0\u884c&#xff0c;pid&#061;%d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">getpid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">123<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5b50\u8fdb\u7a0b\u9000\u51fa&#xff0c;\u8fd4\u56de\u9000\u51fa\u7801123<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u7236\u8fdb\u7a0b\u963b\u585e\u7b49\u5f85\u5b50\u8fdb\u7a0b\u9000\u51fa<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> status<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">wait<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <\/p>\n<p>    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">WIFEXITED<\/span><span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5b50\u8fdb\u7a0b\u6b63\u5e38\u9000\u51fa&#xff0c;\u63d0\u53d6\u9000\u51fa\u7801<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5b50\u8fdb\u7a0b\u6b63\u5e38\u9000\u51fa&#xff0c;\u9000\u51fa\u7801&#xff1a;%d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">WEXITSTATUS<\/span><span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">WIFSIGNALED<\/span><span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5b50\u8fdb\u7a0b\u88ab\u4fe1\u53f7\u7ec8\u6b62<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5b50\u8fdb\u7a0b\u88ab\u4fe1\u53f7\u6740\u6b7b&#xff0c;\u4fe1\u53f7\u7f16\u53f7&#xff1a;%d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">WTERMSIG<\/span><span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h5>2.3.2 \u9000\u51fa\u7801\u7684\u8bbf\u95ee<\/h5>\n<p>status\u53d8\u91cf\u4e0d\u662f\u76f4\u63a5\u7684\u9000\u51fa\u7801&#xff0c;\u91cc\u9762\u540c\u65f6\u5305\u542b\u4e86\u9000\u51fa\u7c7b\u578b\u548c\u9000\u51fa\u7801\u4fe1\u606f&#xff0c;\u5fc5\u987b\u7528\u5b8f\u6765\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>WIFEXITED(status)&#xff1a;\u975e\u96f6\u8868\u793a\u8fdb\u7a0b\u6b63\u5e38\u9000\u51fa<\/li>\n<li>WEXITSTATUS(status)&#xff1a;\u83b7\u53d6\u6b63\u5e38\u9000\u51fa\u7684\u9000\u51fa\u7801<\/li>\n<li>WIFSIGNALED(status)&#xff1a;\u975e\u96f6\u8868\u793a\u8fdb\u7a0b\u88ab\u4fe1\u53f7\u7ec8\u6b62<\/li>\n<li>WTERMSIG(status)&#xff1a;\u83b7\u53d6\u7ec8\u6b62\u8fdb\u7a0b\u7684\u4fe1\u53f7\u7f16\u53f7<\/li>\n<\/ul>\n<h5>2.3.3 \u9000\u51fa\u7801\u53ef\u4ee5\u8f6c\u5316\u4e3a\u9519\u8bef\u4fe1\u606f<\/h5>\n<p>\u7eaf\u6570\u5b57\u7684\u9519\u8bef\u7801\u4e0d\u76f4\u89c2&#xff0c;\u6211\u4eec\u53ef\u4ee5\u7528strerror()\u628a\u9519\u8bef\u7801\u8f6c\u6210\u53ef\u8bfb\u5b57\u7b26\u4e32&#xff0c;\u6216\u8005\u7528perror()\u76f4\u63a5\u6253\u5370\u9519\u8bef\u63cf\u8ff0\u3002<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;stdio.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;string.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;errno.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    errno <span class=\"token operator\">&#061;<\/span> ENOENT<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6a21\u62df\u201c\u6587\u4ef6\u4e0d\u5b58\u5728\u201d\u9519\u8bef<\/span><br \/>\n    <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u9519\u8bef\u63cf\u8ff0&#xff1a;%s\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">strerror<\/span><span class=\"token punctuation\">(<\/span>errno<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6253\u5f00\u914d\u7f6e\u6587\u4ef6\u5931\u8d25&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<hr \/>\n<h3>\u4e09\u3001\u5168\u6587\u603b\u7ed3<\/h3>\n<p>\u8fdb\u7a0b\u7684\u4e00\u751f&#xff0c;\u4ece fork \u5206\u88c2\u521b\u5efa\u5f00\u59cb&#xff0c;\u501f\u52a9\u5199\u65f6\u62f7\u8d1d\u673a\u5236\u9ad8\u6548\u5730\u590d\u5236\u51fa\u72ec\u7acb\u8fd0\u884c\u73af\u5883&#xff1b;\u8fd0\u884c\u5b8c\u6210\u540e&#xff0c;\u901a\u8fc7 exit\/_exit \u5206\u5c42\u9000\u51fa\u5e76\u7559\u4e0b\u9000\u51fa\u72b6\u6001&#xff1b;\u6700\u540e\u7531\u7236\u8fdb\u7a0b\u8c03\u7528 wait \u56de\u6536\u8d44\u6e90&#xff0c;\u5b8c\u6574\u95ed\u73af\u3002<\/p>\n<p>\u7406\u89e3\u8fd9\u6574\u5957\u673a\u5236&#xff0c;\u4f60\u5c31\u770b\u61c2\u4e86 Linux \u591a\u4efb\u52a1\u7684\u5e95\u5c42\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>fork \u7684 \u201c\u4e00\u6b21\u8c03\u7528\u4e24\u6b21\u8fd4\u56de\u201d&#xff0c;\u662f\u591a\u8fdb\u7a0b\u7684\u8d77\u70b9<\/li>\n<li>\u5199\u65f6\u62f7\u8d1d\u662f\u6027\u80fd\u4f18\u5316\u7684\u7cbe\u9ad3&#xff0c;\u7528\u60f0\u6027\u590d\u5236\u6362\u6765\u4e86\u6781\u9ad8\u7684\u521b\u5efa\u6548\u7387<\/li>\n<li>exit \u548c_exit \u7684\u533a\u522b&#xff0c;\u672c\u8d28\u662f\u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\u7684\u8fb9\u754c\u5212\u5206<\/li>\n<li>\u7236\u8fdb\u7a0b\u4e3b\u52a8\u56de\u6536\u5b50\u8fdb\u7a0b&#xff0c;\u662f\u64cd\u4f5c\u7cfb\u7edf\u8d44\u6e90\u7ba1\u7406\u7684\u57fa\u672c\u89c4\u5219<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u89c2\u4f17\u8001\u7237\u4eec\u5927\u5bb6\u597d \u8fd9\u91cc\u662f\u90aa\u4feeKING\u7684\u72ec\u5bb6\u9891\u9053\u672c\u6587\u5c5e\u4e8e\u7cfb\u5217Linux\u7cfb\u7edf\u7bc7 \u2014\u2014\u64cd\u4f5c\u6307\u4ee4\u4e00\u8d77\u5b66Linux\u7684\u5c0f\u4f19\u4f34\u53ef\u8ba2\u9605\u4e13\u680f&#xff1a; Linux\u7cfb\u7edf\u7bc7 \u6211\u4eec\u5e38\u8bf4 Linux \u662f\u591a\u4efb\u52a1\u64cd\u4f5c\u7cfb\u7edf&#xff0c;\u201c\u4efb\u52a1\u201d \u7684\u6838\u5fc3\u8f7d\u4f53\u5c31\u662f\u8fdb\u7a0b\u3002\u4ece\u4f60\u6572\u4e0b\u4e00\u6761\u7ec8\u7aef\u547d\u4ee4&#xff0c;\u5230\u540e\u53f0\u5e38\u9a7b\u7684\u670d\u52a1\u7a0b\u5e8f&#xff0c;\u672c\u8d28\u90fd\u662f\u4e00\u4e2a\u4e2a\u8fdb\u7a0b\u5728 CPU \u4e0a\u8c03\u5ea6\u8fd0\u884c\u3002\u800c\u8fdb\u7a0b\u4ece\u54ea\u91cc\u6765&#xff1f;\u53c8\u600e\u4e48\u5e73\u7a33\u6d88\u5931&#xff1f;\u8fd9\u80cc\u540e\u85cf\u7740\u64cd\u4f5c\u7cfb\u7edf\u6700\u7ecf\u5178\u7684\u8bbe\u8ba1\u601d\u60f3&#xff1a;fork \u5206\u88c2<\/p>\n","protected":false},"author":2,"featured_media":101397,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,58,44],"topic":[],"class_list":["post-101398","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-linux","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Re: Linux\u7cfb\u7edf\u7bc7\uff08\u5341\u516b\uff09\uff1a\u8fdb\u7a0b\u7bc7\uff08\u4e03\uff09\uff1a \u8fdb\u7a0b\u6df1\u5ea6\u89e3\u6790\uff1a\u4ece fork \u521b\u5efa\u5230\u9000\u51fa\u7684\u5b8c\u6574\u65c5\u7a0b\uff08\u9644\u5199\u65f6\u62f7\u8d1d\u539f\u7406 + \u4ee3\u7801\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/101398.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Re: Linux\u7cfb\u7edf\u7bc7\uff08\u5341\u516b\uff09\uff1a\u8fdb\u7a0b\u7bc7\uff08\u4e03\uff09\uff1a \u8fdb\u7a0b\u6df1\u5ea6\u89e3\u6790\uff1a\u4ece fork \u521b\u5efa\u5230\u9000\u51fa\u7684\u5b8c\u6574\u65c5\u7a0b\uff08\u9644\u5199\u65f6\u62f7\u8d1d\u539f\u7406 + \u4ee3\u7801\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u89c2\u4f17\u8001\u7237\u4eec\u5927\u5bb6\u597d \u8fd9\u91cc\u662f\u90aa\u4feeKING\u7684\u72ec\u5bb6\u9891\u9053\u672c\u6587\u5c5e\u4e8e\u7cfb\u5217Linux\u7cfb\u7edf\u7bc7 \u2014\u2014\u64cd\u4f5c\u6307\u4ee4\u4e00\u8d77\u5b66Linux\u7684\u5c0f\u4f19\u4f34\u53ef\u8ba2\u9605\u4e13\u680f&#xff1a; Linux\u7cfb\u7edf\u7bc7 \u6211\u4eec\u5e38\u8bf4 Linux \u662f\u591a\u4efb\u52a1\u64cd\u4f5c\u7cfb\u7edf&#xff0c;\u201c\u4efb\u52a1\u201d \u7684\u6838\u5fc3\u8f7d\u4f53\u5c31\u662f\u8fdb\u7a0b\u3002\u4ece\u4f60\u6572\u4e0b\u4e00\u6761\u7ec8\u7aef\u547d\u4ee4&#xff0c;\u5230\u540e\u53f0\u5e38\u9a7b\u7684\u670d\u52a1\u7a0b\u5e8f&#xff0c;\u672c\u8d28\u90fd\u662f\u4e00\u4e2a\u4e2a\u8fdb\u7a0b\u5728 CPU \u4e0a\u8c03\u5ea6\u8fd0\u884c\u3002\u800c\u8fdb\u7a0b\u4ece\u54ea\u91cc\u6765&#xff1f;\u53c8\u600e\u4e48\u5e73\u7a33\u6d88\u5931&#xff1f;\u8fd9\u80cc\u540e\u85cf\u7740\u64cd\u4f5c\u7cfb\u7edf\u6700\u7ecf\u5178\u7684\u8bbe\u8ba1\u601d\u60f3&#xff1a;fork \u5206\u88c2\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/101398.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-06T11:33:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260906113307-6a9d4f7319505.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/101398.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/101398.html\",\"name\":\"Re: Linux\u7cfb\u7edf\u7bc7\uff08\u5341\u516b\uff09\uff1a\u8fdb\u7a0b\u7bc7\uff08\u4e03\uff09\uff1a \u8fdb\u7a0b\u6df1\u5ea6\u89e3\u6790\uff1a\u4ece fork \u521b\u5efa\u5230\u9000\u51fa\u7684\u5b8c\u6574\u65c5\u7a0b\uff08\u9644\u5199\u65f6\u62f7\u8d1d\u539f\u7406 + \u4ee3\u7801\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-06T11:33:08+00:00\",\"dateModified\":\"2026-09-06T11:33:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/101398.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/101398.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/101398.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Re: Linux\u7cfb\u7edf\u7bc7\uff08\u5341\u516b\uff09\uff1a\u8fdb\u7a0b\u7bc7\uff08\u4e03\uff09\uff1a \u8fdb\u7a0b\u6df1\u5ea6\u89e3\u6790\uff1a\u4ece fork \u521b\u5efa\u5230\u9000\u51fa\u7684\u5b8c\u6574\u65c5\u7a0b\uff08\u9644\u5199\u65f6\u62f7\u8d1d\u539f\u7406 + \u4ee3\u7801\u5b9e\u6218\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Re: Linux\u7cfb\u7edf\u7bc7\uff08\u5341\u516b\uff09\uff1a\u8fdb\u7a0b\u7bc7\uff08\u4e03\uff09\uff1a \u8fdb\u7a0b\u6df1\u5ea6\u89e3\u6790\uff1a\u4ece fork \u521b\u5efa\u5230\u9000\u51fa\u7684\u5b8c\u6574\u65c5\u7a0b\uff08\u9644\u5199\u65f6\u62f7\u8d1d\u539f\u7406 + \u4ee3\u7801\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/101398.html","og_locale":"zh_CN","og_type":"article","og_title":"Re: Linux\u7cfb\u7edf\u7bc7\uff08\u5341\u516b\uff09\uff1a\u8fdb\u7a0b\u7bc7\uff08\u4e03\uff09\uff1a \u8fdb\u7a0b\u6df1\u5ea6\u89e3\u6790\uff1a\u4ece fork \u521b\u5efa\u5230\u9000\u51fa\u7684\u5b8c\u6574\u65c5\u7a0b\uff08\u9644\u5199\u65f6\u62f7\u8d1d\u539f\u7406 + \u4ee3\u7801\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u89c2\u4f17\u8001\u7237\u4eec\u5927\u5bb6\u597d \u8fd9\u91cc\u662f\u90aa\u4feeKING\u7684\u72ec\u5bb6\u9891\u9053\u672c\u6587\u5c5e\u4e8e\u7cfb\u5217Linux\u7cfb\u7edf\u7bc7 \u2014\u2014\u64cd\u4f5c\u6307\u4ee4\u4e00\u8d77\u5b66Linux\u7684\u5c0f\u4f19\u4f34\u53ef\u8ba2\u9605\u4e13\u680f&#xff1a; Linux\u7cfb\u7edf\u7bc7 \u6211\u4eec\u5e38\u8bf4 Linux \u662f\u591a\u4efb\u52a1\u64cd\u4f5c\u7cfb\u7edf&#xff0c;\u201c\u4efb\u52a1\u201d \u7684\u6838\u5fc3\u8f7d\u4f53\u5c31\u662f\u8fdb\u7a0b\u3002\u4ece\u4f60\u6572\u4e0b\u4e00\u6761\u7ec8\u7aef\u547d\u4ee4&#xff0c;\u5230\u540e\u53f0\u5e38\u9a7b\u7684\u670d\u52a1\u7a0b\u5e8f&#xff0c;\u672c\u8d28\u90fd\u662f\u4e00\u4e2a\u4e2a\u8fdb\u7a0b\u5728 CPU \u4e0a\u8c03\u5ea6\u8fd0\u884c\u3002\u800c\u8fdb\u7a0b\u4ece\u54ea\u91cc\u6765&#xff1f;\u53c8\u600e\u4e48\u5e73\u7a33\u6d88\u5931&#xff1f;\u8fd9\u80cc\u540e\u85cf\u7740\u64cd\u4f5c\u7cfb\u7edf\u6700\u7ecf\u5178\u7684\u8bbe\u8ba1\u601d\u60f3&#xff1a;fork \u5206\u88c2","og_url":"https:\/\/www.wsisp.com\/helps\/101398.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-06T11:33:08+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260906113307-6a9d4f7319505.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/101398.html","url":"https:\/\/www.wsisp.com\/helps\/101398.html","name":"Re: Linux\u7cfb\u7edf\u7bc7\uff08\u5341\u516b\uff09\uff1a\u8fdb\u7a0b\u7bc7\uff08\u4e03\uff09\uff1a \u8fdb\u7a0b\u6df1\u5ea6\u89e3\u6790\uff1a\u4ece fork \u521b\u5efa\u5230\u9000\u51fa\u7684\u5b8c\u6574\u65c5\u7a0b\uff08\u9644\u5199\u65f6\u62f7\u8d1d\u539f\u7406 + \u4ee3\u7801\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-06T11:33:08+00:00","dateModified":"2026-09-06T11:33:08+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/101398.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/101398.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/101398.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Re: Linux\u7cfb\u7edf\u7bc7\uff08\u5341\u516b\uff09\uff1a\u8fdb\u7a0b\u7bc7\uff08\u4e03\uff09\uff1a \u8fdb\u7a0b\u6df1\u5ea6\u89e3\u6790\uff1a\u4ece fork \u521b\u5efa\u5230\u9000\u51fa\u7684\u5b8c\u6574\u65c5\u7a0b\uff08\u9644\u5199\u65f6\u62f7\u8d1d\u539f\u7406 + \u4ee3\u7801\u5b9e\u6218\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/101398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=101398"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/101398\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/101397"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=101398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=101398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=101398"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=101398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}