{"id":17707,"date":"2024-11-18T15:47:34","date_gmt":"2024-11-18T07:47:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/17707\/"},"modified":"2024-11-18T15:47:34","modified_gmt":"2024-11-18T07:47:34","slug":"%e8%bf%9b%e7%a8%8b%e4%bc%98%e5%85%88%e7%ba%a7%e5%af%b9linux%e7%b3%bb%e7%bb%9f%e6%80%a7%e8%83%bd%e7%9a%84%e5%bd%b1%e5%93%8d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/17707\/","title":{"rendered":"\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/164\/171042534949118.jpg\" class=\"aligncenter\" title=\"\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\u63d2\u56fe\" alt=\"\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\u63d2\u56fe\" \/><\/p>\n<p>\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd<\/p>\n<p>\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u8fdb\u7a0b\u7684\u8c03\u5ea6\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u95ee\u9898\uff0c\u800c\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u5219\u662f\u5f71\u54cd\u8fdb\u7a0b\u8c03\u5ea6\u7684\u5173\u952e\u56e0\u7d20\u4e4b\u4e00\u3002Linux\u7cfb\u7edf\u4e2d\uff0c\u8fdb\u7a0b\u53ef\u4ee5\u5206\u4e3a\u5b9e\u65f6\u8fdb\u7a0b\u548c\u666e\u901a\u8fdb\u7a0b\uff0c\u800c\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u5219\u662f\u51b3\u5b9a\u7cfb\u7edf\u8c03\u5ea6\u7a0b\u5e8f\u5982\u4f55\u5b89\u6392\u8fdb\u7a0b\u6267\u884c\u7684\u4e00\u4e2a\u91cd\u8981\u53c2\u6570\u3002<\/p>\n<p>\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u7528\u4e00\u4e2a\u6570\u503c\u8868\u793a\uff0c\u8303\u56f4\u4e00\u822c\u4e3a-20\uff08\u6700\u9ad8\u4f18\u5148\u7ea7\uff09\u523019\uff08\u6700\u4f4e\u4f18\u5148\u7ea7\uff09\u3002\u6570\u503c\u8d8a\u5c0f\uff0c\u8868\u793a\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u8d8a\u9ad8\uff0c\u7cfb\u7edf\u4f1a\u66f4\u9891\u7e41\u5730\u8c03\u5ea6\u8fd9\u4e9b\u8fdb\u7a0b\u6267\u884c\u3002<\/p>\n<p>\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\u4e3b\u8981\u4f53\u73b0\u5728\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a<\/p>\n<ol>\n<li>\u54cd\u5e94\u65f6\u95f4<br \/>\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u9ad8\uff0c\u7cfb\u7edf\u8c03\u5ea6\u7a0b\u5e8f\u66f4\u503e\u5411\u4e8e\u8ba9\u8fd9\u4e9b\u8fdb\u7a0b\u83b7\u5f97CPU\u65f6\u95f4\u7247\uff0c\u4ece\u800c\u66f4\u5feb\u5730\u54cd\u5e94\u7528\u6237\u64cd\u4f5c\u3002\u56e0\u6b64\uff0c\u5728\u4e00\u4e9b\u9700\u8981\u5feb\u901f\u54cd\u5e94\u7684\u5e94\u7528\u573a\u666f\u4e0b\uff0c\u63d0\u9ad8\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u53ef\u4ee5\u660e\u663e\u5730\u6539\u5584\u7cfb\u7edf\u7684\u54cd\u5e94\u901f\u5ea6\u3002<\/li>\n<li>\u7cfb\u7edf\u541e\u5410\u91cf<br \/>\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u9ad8\uff0c\u4f1a\u66f4\u9891\u7e41\u5730\u88ab\u7cfb\u7edf\u8c03\u5ea6\u7a0b\u5e8f\u6267\u884c\uff0c\u56e0\u6b64\u7cfb\u7edf\u53ef\u80fd\u4f1a\u66f4\u591a\u5730\u82b1\u8d39\u5728\u9ad8\u4f18\u5148\u7ea7\u8fdb\u7a0b\u4e0a\uff0c\u4ece\u800c\u964d\u4f4e\u7cfb\u7edf\u6574\u4f53\u7684\u541e\u5410\u91cf\u3002\u5728\u4e00\u4e9b\u9700\u8981\u5927\u91cf\u8ba1\u7b97\u4efb\u52a1\u7684\u573a\u666f\u4e0b\uff0c\u8fc7\u591a\u5730\u63d0\u9ad8\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u541e\u5410\u91cf\u4e0b\u964d\u3002<\/li>\n<li>\u7cfb\u7edf\u7a33\u5b9a\u6027<br \/>\u8fc7\u591a\u5730\u63d0\u9ad8\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u5176\u4ed6\u8fdb\u7a0b\u5f97\u4e0d\u5230\u5145\u5206\u7684CPU\u65f6\u95f4\u7247\uff0c\u751a\u81f3\u51fa\u73b0\u201c\u9965\u997f\u201d\u73b0\u8c61\uff0c\u4ece\u800c\u5f71\u54cd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u3002\u56e0\u6b64\uff0c\u5408\u7406\u8bbe\u7f6e\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u662f\u7ef4\u6301\u7cfb\u7edf\u7a33\u5b9a\u6027\u7684\u91cd\u8981\u56e0\u7d20\u4e4b\u4e00\u3002<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u6765\u5c55\u793a\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\uff1a<\/p>\n<pre>#include &lt;stdio.h&gt;\n#include &lt;unistd.h&gt;\n\nint main() {\n    int i;\n    pid_t pid;\n\n    pid = fork();\n\n    if (pid &lt;p&gt;\u5728\u8fd9\u4e2a\u4ee3\u7801\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u5728\u5b50\u8fdb\u7a0b\u4e2d\u901a\u8fc7nice(10)\u51fd\u6570\u63d0\u9ad8\u4e86\u5b50\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u3002\u901a\u8fc7\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u89c2\u5bdf\u5230\u5b50\u8fdb\u7a0b\u4f1a\u66f4\u9891\u7e41\u5730\u6267\u884c\uff0c\u56e0\u4e3a\u5176\u4f18\u5148\u7ea7\u66f4\u9ad8\uff0c\u4ece\u800c\u5f71\u54cd\u4e86\u7cfb\u7edf\u7684\u6027\u80fd\u8868\u73b0\u3002&lt;\/p&gt;\n&lt;p&gt;\u901a\u8fc7\u5408\u7406\u8bbe\u7f6e\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u8c03\u6574\u7cfb\u7edf\u7684\u6027\u80fd\u8868\u73b0\uff0c\u63d0\u9ad8\u7cfb\u7edf\u7684\u54cd\u5e94\u901f\u5ea6\u6216\u7cfb\u7edf\u541e\u5410\u91cf\uff0c\u540c\u65f6\u4e5f\u9700\u8981\u6ce8\u610f\u5728\u63d0\u9ad8\u4f18\u5148\u7ea7\u7684\u540c\u65f6\u8981\u907f\u514d\u5bf9\u7cfb\u7edf\u7a33\u5b9a\u6027\u9020\u6210\u5f71\u54cd\u3002&lt;\/p&gt;\n&lt;p&gt;\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\u662f\u4e00\u4e2a\u590d\u6742\u7684\u95ee\u9898\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\u6765\u5408\u7406\u8bbe\u7f6e\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\uff0c\u4ee5\u8fbe\u5230\u6700\u4f73\u7684\u7cfb\u7edf\u6027\u80fd\u8868\u73b0\u3002&lt;\/p&gt;&lt;\/unistd.h&gt;&lt;\/stdio.h&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd \u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u8fdb\u7a0b\u7684\u8c03\u5ea6\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u95ee\u9898\uff0c\u800c\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u5219\u662f\u5f71\u54cd\u8fdb\u7a0b\u8c03\u5ea6\u7684\u5173\u952e\u56e0\u7d20\u4e4b\u4e00\u3002Linux\u7cfb\u7edf\u4e2d\uff0c\u8fdb\u7a0b\u53ef\u4ee5\u5206\u4e3a\u5b9e\u65f6\u8fdb\u7a0b\u548c\u666e\u901a\u8fdb\u7a0b\uff0c\u800c\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u5219\u662f\u51b3\u5b9a\u7cfb\u7edf\u8c03\u5ea6\u7a0b\u5e8f\u5982\u4f55\u5b89\u6392\u8fdb\u7a0b\u6267\u884c\u7684\u4e00\u4e2a\u91cd\u8981\u53c2\u6570\u3002 \u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u7528\u4e00\u4e2a\u6570\u503c\u8868\u793a\uff0c\u8303\u56f4\u4e00\u822c\u4e3a-20\uff08\u6700\u9ad8\u4f18\u5148\u7ea7\uff09\u523019\uff08\u6700\u4f4e\u4f18\u5148\u7ea7\uff09\u3002\u6570\u503c\u8d8a\u5c0f\uff0c\u8868\u793a\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u8d8a\u9ad8\uff0c\u7cfb\u7edf\u4f1a\u66f4\u9891\u7e41\u5730\u8c03\u5ea6\u8fd9\u4e9b\u8fdb\u7a0b\u6267\u884c\u3002 \u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\u4e3b\u8981\u4f53\u73b0\u5728\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a \u54cd\u5e94\u65f6\u95f4\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u9ad8\uff0c\u7cfb\u7edf\u8c03\u5ea6\u7a0b\u5e8f\u66f4\u503e\u5411\u4e8e\u8ba9\u8fd9\u4e9b\u8fdb\u7a0b\u83b7\u5f97CPU\u65f6\u95f4\u7247\uff0c\u4ece\u800c\u66f4\u5feb\u5730\u54cd\u5e94\u7528\u6237\u64cd\u4f5c\u3002\u56e0\u6b64\uff0c\u5728\u4e00\u4e9b\u9700\u8981\u5feb\u901f\u54cd\u5e94\u7684\u5e94\u7528\u573a\u666f\u4e0b\uff0c\u63d0\u9ad8\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u53ef\u4ee5\u660e\u663e\u5730\u6539\u5584\u7cfb\u7edf\u7684\u54cd\u5e94\u901f\u5ea6\u3002 \u7cfb\u7edf\u541e\u5410\u91cf\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u9ad8\uff0c\u4f1a\u66f4\u9891\u7e41\u5730\u88ab\u7cfb\u7edf\u8c03\u5ea6\u7a0b\u5e8f\u6267\u884c\uff0c\u56e0\u6b64\u7cfb\u7edf\u53ef\u80fd\u4f1a\u66f4\u591a\u5730\u82b1\u8d39\u5728\u9ad8\u4f18\u5148\u7ea7\u8fdb\u7a0b\u4e0a\uff0c\u4ece\u800c\u964d\u4f4e\u7cfb\u7edf\u6574\u4f53\u7684\u541e\u5410\u91cf\u3002\u5728\u4e00\u4e9b\u9700\u8981\u5927\u91cf\u8ba1\u7b97\u4efb\u52a1\u7684\u573a\u666f\u4e0b\uff0c\u8fc7\u591a\u5730\u63d0\u9ad8\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u541e\u5410\u91cf\u4e0b\u964d\u3002 \u7cfb\u7edf\u7a33\u5b9a\u6027\u8fc7\u591a\u5730\u63d0\u9ad8\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u5176\u4ed6\u8fdb\u7a0b\u5f97\u4e0d\u5230\u5145\u5206\u7684CPU\u65f6\u95f4\u7247\uff0c\u751a\u81f3\u51fa\u73b0\u201c\u9965\u997f\u201d\u73b0\u8c61\uff0c\u4ece\u800c\u5f71\u54cd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u3002\u56e0\u6b64\uff0c\u5408\u7406\u8bbe\u7f6e\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u662f\u7ef4\u6301\u7cfb\u7edf\u7a33\u5b9a\u6027\u7684\u91cd\u8981\u56e0\u7d20\u4e4b\u4e00\u3002 \u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u6765\u5c55\u793a\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\uff1a #include &lt;stdio.h&gt; #include &lt;unistd.h&gt; int main() { int i; pid_t pid; pid = fork(); if (pid &lt;p&gt;\u5728\u8fd9\u4e2a\u4ee3\u7801\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u5728\u5b50\u8fdb\u7a0b\u4e2d\u901a\u8fc7nice(10)\u51fd\u6570\u63d0\u9ad8\u4e86\u5b50\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\u3002\u901a\u8fc7\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u89c2\u5bdf\u5230\u5b50\u8fdb\u7a0b\u4f1a\u66f4\u9891\u7e41\u5730\u6267\u884c\uff0c\u56e0\u4e3a\u5176\u4f18\u5148\u7ea7\u66f4\u9ad8\uff0c\u4ece\u800c\u5f71\u54cd\u4e86\u7cfb\u7edf\u7684\u6027\u80fd\u8868\u73b0\u3002&lt;\/p&gt; &lt;p&gt;\u901a\u8fc7\u5408\u7406\u8bbe\u7f6e\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u8c03\u6574\u7cfb\u7edf\u7684\u6027\u80fd\u8868\u73b0\uff0c\u63d0\u9ad8\u7cfb\u7edf\u7684\u54cd\u5e94\u901f\u5ea6\u6216\u7cfb\u7edf\u541e\u5410\u91cf\uff0c\u540c\u65f6\u4e5f\u9700\u8981\u6ce8\u610f\u5728\u63d0\u9ad8\u4f18\u5148\u7ea7\u7684\u540c\u65f6\u8981\u907f\u514d\u5bf9\u7cfb\u7edf\u7a33\u5b9a\u6027\u9020\u6210\u5f71\u54cd\u3002&lt;\/p&gt; &lt;p&gt;\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\u662f\u4e00\u4e2a\u590d\u6742\u7684\u95ee\u9898\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\u6765\u5408\u7406\u8bbe\u7f6e\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7\uff0c\u4ee5\u8fbe\u5230\u6700\u4f73\u7684\u7cfb\u7edf\u6027\u80fd\u8868\u73b0\u3002&lt;\/p&gt;&lt;\/unistd.h&gt;&lt;\/stdio.h&gt; \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662f\u8fdb\u7a0b\u4f18\u5148\u7ea7\u5bf9Linux\u7cfb\u7edf\u6027\u80fd\u7684\u5f71\u54cd\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-17707","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17707","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=17707"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17707\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=17707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=17707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=17707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}