{"id":51999,"date":"2024-12-03T17:56:05","date_gmt":"2024-12-03T09:56:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/51999\/"},"modified":"2024-12-03T17:56:05","modified_gmt":"2024-12-03T09:56:05","slug":"linux%e5%88%9b%e5%bb%ba%e8%bf%9b%e7%a8%8b%e7%9a%84%e5%91%bd%e4%bb%a4%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/51999\/","title":{"rendered":"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b<\/h1>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300alinux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<\/p>\n<blockquote>\n<p>linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\uff1a1\u3001fork\u547d\u4ee4\uff0c\u53ef\u4ee5\u4ece\u5df2\u5b58\u5728\u8fdb\u7a0b\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u8fdb\u7a0b\uff0c\u8be5\u65b0\u8fdb\u7a0b\u4e3a\u5b50\u8fdb\u7a0b\uff0c\u800c\u539f\u8fdb\u7a0b\u4e3a\u7236\u8fdb\u7a0b\uff1b\u5b50\u8fdb\u7a0b\u5b8c\u5168\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u8d44\u6e90\u30022\u3001vfork\u547d\u4ee4\uff0c\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u4e0e\u7236\u8fdb\u7a0b\u5171\u4eab\u5730\u5740\u7a7a\u95f4\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b50\u8fdb\u7a0b\u5b8c\u5168\u8fd0\u884c\u5728\u7236\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u4e0a\u30023\u3001clone\u547d\u4ee4\uff0c\u53ef\u4ee5\u5c06\u7236\u8fdb\u7a0b\u8d44\u6e90\u6709\u9009\u62e9\u5730\u590d\u5236\u7ed9\u5b50\u8fdb\u7a0b\uff0c\u800c\u6ca1\u6709\u590d\u5236\u7684\u6570\u636e\u7ed3\u6784\u5219\u901a\u8fc7\u6307\u9488\u7684\u590d\u5236\u8ba9\u5b50\u8fdb\u7a0b\u5171\u4eab\u3002<\/p>\n<\/blockquote>\n<p>Linux\u7cfb\u7edf\u79cd\u521b\u5efa\u8fdb\u7a0b\u6709fork\u3001vfork\u3001clone\u8fd9\u4e2a\u4e09\u540d\u547d\u4ee4\u53ef\u4f9b\u4f7f\u7528\u3002<\/p>\n<p><strong>fork<\/strong><\/p>\n<p>fork\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u5b50\u8fdb\u7a0b\u53ea\u662f\u5b8c\u5168\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u8d44\u6e90\uff0c\u590d\u5236\u51fa\u6765\u7684\u5b50\u8fdb\u7a0b\u6709\u81ea\u5df1\u7684task_struct\u7ed3\u6784\u548cpid,\u4f46\u5374\u590d\u5236\u7236\u8fdb\u7a0b\u5176\u5b83\u6240\u6709\u7684\u8d44\u6e90\u3002\u4f8b\u5982\uff0c\u8981\u662f\u7236\u8fdb\u7a0b\u6253\u5f00\u4e86\u4e94\u4e2a\u6587\u4ef6\uff0c\u90a3\u4e48\u5b50\u8fdb\u7a0b\u4e5f\u6709\u4e94\u4e2a\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u800c\u4e14\u8fd9\u4e9b\u6587\u4ef6\u7684\u5f53\u524d\u8bfb\u5199\u6307\u9488\u4e5f\u505c\u5728\u76f8\u540c\u7684\u5730\u65b9\u3002\u6240\u4ee5\uff0c\u8fd9\u4e00\u6b65\u6240\u505a\u7684\u662f\u590d\u5236\u3002\u8fd9\u6837\u5f97\u5230\u7684\u5b50\u8fdb\u7a0b\u72ec\u7acb\u4e8e\u7236\u8fdb\u7a0b\uff0c \u5177\u6709\u826f\u597d\u7684\u5e76\u53d1\u6027\uff0c\u4f46\u662f\u4e8c\u8005\u4e4b\u95f4\u7684\u901a\u8baf\u9700\u8981\u901a\u8fc7\u4e13\u95e8\u7684\u901a\u8baf\u673a\u5236\uff0c\u5982\uff1apipe\uff0c\u5171\u4eab\u5185\u5b58\u7b49\u673a\u5236\uff0c \u53e6\u5916\u901a\u8fc7fork\u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u9700\u8981\u5c06\u4e0a\u9762\u63cf\u8ff0\u7684\u6bcf\u79cd\u8d44\u6e90\u90fd\u590d\u5236\u4e00\u4e2a\u526f\u672c\u3002\u8fd9\u6837\u770b\u6765\uff0cfork\u662f\u4e00\u4e2a\u5f00\u9500\u5341\u5206\u5927\u7684\u7cfb\u7edf\u8c03\u7528\uff0c\u8fd9\u4e9b\u5f00\u9500\u5e76\u4e0d\u662f\u6240\u6709\u7684\u60c5\u51b5\u4e0b\u90fd\u662f\u5fc5\u987b\u7684\uff0c\u6bd4\u5982\u67d0\u8fdb\u7a0bfork\u51fa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u540e\uff0c\u5176\u5b50\u8fdb\u7a0b\u4ec5\u4ec5\u662f\u4e3a\u4e86\u8c03\u7528exec\u6267\u884c\u53e6\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u90a3\u4e48\u5728fork\u8fc7\u7a0b\u4e2d\u5bf9\u4e8e\u865a\u5b58\u7a7a\u95f4\u7684\u590d\u5236\u5c06\u662f\u4e00\u4e2a\u591a\u4f59\u7684\u8fc7\u7a0b\u3002\u4f46\u7531\u4e8e\u73b0\u5728Linux\u4e2d\u662f\u91c7\u53d6\u4e86copy-on-write(COW\u5199\u65f6\u590d\u5236)\u6280\u672f\uff0c\u4e3a\u4e86\u964d\u4f4e\u5f00\u9500\uff0cfork\u6700\u521d\u5e76\u4e0d\u4f1a\u771f\u7684\u4ea7\u751f\u4e24\u4e2a\u4e0d\u540c\u7684\u62f7\u8d1d\uff0c\u56e0\u4e3a\u5728\u90a3\u4e2a\u65f6\u5019\uff0c\u5927\u91cf\u7684\u6570\u636e\u5176\u5b9e\u5b8c\u5168\u662f\u4e00\u6837\u7684\u3002\u5199\u65f6\u590d\u5236\u662f\u5728\u63a8\u8fdf\u771f\u6b63\u7684\u6570\u636e\u62f7\u8d1d\u3002\u82e5\u540e\u6765\u786e\u5b9e\u53d1\u751f\u4e86\u5199\u5165\uff0c\u90a3\u610f\u5473\u7740parent\u548cchild\u7684\u6570\u636e\u4e0d\u4e00\u81f4\u4e86\uff0c\u4e8e\u662f\u4ea7\u751f\u590d\u5236\u52a8\u4f5c\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u62ff\u5230\u5c5e\u4e8e\u81ea\u5df1\u7684\u90a3\u4e00\u4efd\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u964d\u4f4e\u7cfb\u7edf\u8c03\u7528\u7684\u5f00\u9500\u3002\u6240\u4ee5\u6709\u4e86\u5199\u65f6\u590d\u5236\u540e\u5462\uff0cvfork\u5176\u5b9e\u73b0\u610f\u4e49\u5c31\u4e0d\u5927\u4e86\u3002<\/p>\n<p>\u3000\u3000fork()\u8c03\u7528\u6267\u884c\u4e00\u6b21\u8fd4\u56de\u4e24\u4e2a\u503c\uff0c\u5bf9\u4e8e\u7236\u8fdb\u7a0b\uff0cfork\u51fd\u6570\u8fd4\u56de\u5b50\u7a0b\u5e8f\u7684\u8fdb\u7a0b\u53f7\uff0c\u800c\u5bf9\u4e8e\u5b50\u7a0b\u5e8f\uff0cfork\u51fd\u6570\u5219\u8fd4\u56de\u96f6\uff0c\u8fd9\u5c31\u662f\u4e00\u4e2a\u51fd\u6570\u8fd4\u56de\u4e24\u6b21\u7684\u672c\u8d28\u3002<\/p>\n<p>\u3000\u3000\u5728fork\u4e4b\u540e\uff0c\u5b50\u8fdb\u7a0b\u548c\u7236\u8fdb\u7a0b\u90fd\u4f1a\u7ee7\u7eed\u6267\u884cfork\u8c03\u7528\u4e4b\u540e\u7684\u6307\u4ee4\u3002\u5b50\u8fdb\u7a0b\u662f\u7236\u8fdb\u7a0b\u7684\u526f\u672c\u3002\u5b83\u5c06\u83b7\u5f97\u7236\u8fdb\u7a0b\u7684\u6570\u636e\u7a7a\u95f4\uff0c\u5806\u548c\u6808\u7684\u526f\u672c\uff0c\u8fd9\u4e9b\u90fd\u662f\u526f\u672c\uff0c\u7236\u5b50\u8fdb\u7a0b\u5e76\u4e0d\u5171\u4eab\u8fd9\u90e8\u5206\u7684\u5185\u5b58\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b50\u8fdb\u7a0b\u5bf9\u7236\u8fdb\u7a0b\u4e2d\u7684\u540c\u540d\u53d8\u91cf\u8fdb\u884c\u4fee\u6539\u5e76\u4e0d\u4f1a\u5f71\u54cd\u5176\u5728\u7236\u8fdb\u7a0b\u4e2d\u7684\u503c\u3002\u4f46\u662f\u7236\u5b50\u8fdb\u7a0b\u53c8\u5171\u4eab\u4e00\u4e9b\u4e1c\u897f\uff0c\u7b80\u5355\u8bf4\u6765\u5c31\u662f\u7a0b\u5e8f\u7684\u6b63\u6587\u6bb5\u3002\u6b63\u6587\u6bb5\u5b58\u653e\u7740\u7531cpu\u6267\u884c\u7684\u673a\u5668\u6307\u4ee4\uff0c\u901a\u5e38\u662fread-only\u7684\u3002<\/p>\n<p><strong>vfork<\/strong><\/p>\n<p>\u3000\u3000vfork\u7cfb\u7edf\u8c03\u7528\u4e0d\u540c\u4e8efork\uff0c\u7528vfork\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u4e0e\u7236\u8fdb\u7a0b\u5171\u4eab\u5730\u5740\u7a7a\u95f4\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b50\u8fdb\u7a0b\u5b8c\u5168\u8fd0\u884c\u5728\u7236\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u4e0a\uff0c\u5982\u679c\u8fd9\u65f6\u5b50\u8fdb\u7a0b\u4fee\u6539\u4e86\u67d0\u4e2a\u53d8\u91cf\uff0c\u8fd9\u5c06\u5f71\u54cd\u5230\u7236\u8fdb\u7a0b\u3002<\/p>\n<p>\u3000\u3000\u56e0\u6b64\uff0c\u4e0a\u9762\u7684\u4f8b\u5b50\u5982\u679c\u6539\u7528vfork()\u7684\u8bdd\uff0c\u90a3\u4e48\u4e24\u6b21\u6253\u5370a,b\u7684\u503c\u662f\u76f8\u540c\u7684\uff0c\u6240\u5728\u5730\u5740\u4e5f\u662f\u76f8\u540c\u7684\u3002<\/p>\n<p>\u3000\u3000\u4f46\u6b64\u5904\u6709\u4e00\u70b9\u8981\u6ce8\u610f\u7684\u662f\u7528vfork()\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u5fc5\u987b\u663e\u793a\u8c03\u7528exit()\u6765\u7ed3\u675f\uff0c\u5426\u5219\u5b50\u8fdb\u7a0b\u5c06\u4e0d\u80fd\u7ed3\u675f\uff0c\u800cfork()\u5219\u4e0d\u5b58\u5728\u8fd9\u4e2a\u60c5\u51b5\u3002<\/p>\n<p>\u3000\u3000Vfork\u4e5f\u662f\u5728\u7236\u8fdb\u7a0b\u4e2d\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684\u8fdb\u7a0b\u53f7\uff0c\u5728\u5b50\u8fdb\u7a0b\u4e2d\u8fd4\u56de0\u3002<\/p>\n<p>\u3000\u3000\u7528 vfork\u521b\u5efa\u5b50\u8fdb\u7a0b\u540e\uff0c\u7236\u8fdb\u7a0b\u4f1a\u88ab\u963b\u585e\u76f4\u5230\u5b50\u8fdb\u7a0b\u8c03\u7528exec(exec\uff0c\u5c06\u4e00\u4e2a\u65b0\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8f7d\u5165\u5230\u5730\u5740\u7a7a\u95f4\u5e76\u6267\u884c\u4e4b\u3002)\u6216exit\u3002vfork\u7684\u597d\u5904\u662f\u5728\u5b50\u8fdb\u7a0b\u88ab\u521b\u5efa\u540e\u5f80\u5f80\u4ec5\u4ec5\u662f\u4e3a\u4e86\u8c03\u7528exec\u6267\u884c\u53e6\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u56e0\u4e3a\u5b83\u5c31\u4e0d\u4f1a\u5bf9\u7236\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u6709\u4efb\u4f55\u5f15\u7528\uff0c\u6240\u4ee5\u5bf9\u5730\u5740\u7a7a\u95f4\u7684\u590d\u5236\u662f\u591a\u4f59\u7684 \uff0c\u56e0\u6b64\u901a\u8fc7vfork\u5171\u4eab\u5185\u5b58\u53ef\u4ee5\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5f00\u9500\u3002<\/p>\n<p><strong>clone<\/strong><\/p>\n<p>\u3000\u3000\u7cfb\u7edf\u8c03\u7528fork()\u548cvfork()\u662f\u65e0\u53c2\u6570\u7684\uff0c\u800cclone()\u5219\u5e26\u6709\u53c2\u6570\u3002fork()\u662f\u5168\u90e8\u590d\u5236\uff0cvfork()\u662f\u5171\u4eab\u5185\u5b58\uff0c\u800cclone() \u662f\u5219\u53ef\u4ee5\u5c06\u7236\u8fdb\u7a0b\u8d44\u6e90\u6709\u9009\u62e9\u5730\u590d\u5236\u7ed9\u5b50\u8fdb\u7a0b\uff0c\u800c\u6ca1\u6709\u590d\u5236\u7684\u6570\u636e\u7ed3\u6784\u5219\u901a\u8fc7\u6307\u9488\u7684\u590d\u5236\u8ba9\u5b50\u8fdb\u7a0b\u5171\u4eab\uff0c\u5177\u4f53\u8981\u590d\u5236\u54ea\u4e9b\u8d44\u6e90\u7ed9\u5b50\u8fdb\u7a0b\uff0c\u7531\u53c2\u6570\u5217\u8868\u4e2d\u7684 clone_flags\u6765\u51b3\u5b9a\u3002\u53e6\u5916\uff0cclone()\u8fd4\u56de\u7684\u662f\u5b50\u8fdb\u7a0b\u7684pid\u3002<\/p>\n<p>\u4e0b\u9762\u8be6\u7ec6\u4e86\u89e3fork\u547d\u4ee4\uff08\u8fdb\u7a0b\u521b\u5efa\uff09\u3002<\/p>\n<p><strong>\u6df1\u5165 fork \u51fd\u6570<\/strong><\/p>\n<p>\u5728 Linux \u4e2d fork \u51fd\u6570\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u51fd\u6570\uff0c\u5b83\u4ece\u5df2\u5b58\u5728\u8fdb\u7a0b\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u8fdb\u7a0b\u3002\u65b0\u8fdb\u7a0b\u4e3a\u5b50\u8fdb\u7a0b\uff0c\u800c\u539f\u8fdb\u7a0b\u4e3a\u7236\u8fdb\u7a0b\u3002<\/p>\n<blockquote>\n<p><strong>fork \u51fd\u6570\u7684\u8fd4\u56de\u503c:<\/strong><\/p>\n<ul>\n<li>\n<p>\u7ed9\u7236\u8fdb\u7a0b\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684 pid<\/p>\n<\/li>\n<li>\n<p>\u7ed9\u5b50\u8fdb\u7a0b\u8fd4\u56de0<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u4e3e\u4f8b\u4f7f\u7528\u4e00\u4e0bfork\u51fd\u6570 ()<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb871fbf.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe\" \/><\/p>\n<p>\u6211\u4eec\u7f16\u8bd1\uff0c\u7136\u540e\u8fd0\u884c\u4e00\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb8736c5.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe1\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe1\" \/><\/p>\n<blockquote>\n<p><strong>fork \u7684\u5e38\u89c4\u7528\u6cd5<\/strong><\/p>\n<ul>\n<li>\n<p>\u4e00\u4e2a\u7236\u8fdb\u7a0b\u5e0c\u671b\u590d\u5236\u81ea\u5df1\uff0c\u4f7f\u7236\u5b50\u8fdb\u7a0b\u540c\u65f6\u6267\u884c\u4e0d\u540c\u7684\u4ee3\u7801\u6bb5\u3002\u4f8b\u5982\uff0c\u7236\u8fdb\u7a0b\u7b49\u5f85\u5ba2\u6237\u7aef\u8bf7\u6c42\uff0c\u751f\u6210\u5b50\u8fdb\u7a0b\u6765\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e00\u4e2a\u8fdb\u7a0b\u8981\u6267\u884c\u4e00\u4e2a\u4e0d\u540c\u7684\u7a0b\u5e8f\u3002\u4f8b\u5982\u5b50\u8fdb\u7a0b\u4ecefork\u8fd4\u56de\u540e\uff0c\u8c03\u7528exec\u51fd\u6570\u3002<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<blockquote>\n<p><strong>fork\u8c03\u7528\u5931\u8d25\u7684\u539f\u56e0<\/strong><\/p>\n<ul>\n<li>\n<p>\u7cfb\u7edf\u4e2d\u6709\u592a\u591a\u7684\u8fdb\u7a0b<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u9645\u7528\u6237\u7684\u8fdb\u7a0b\u6570\u8d85\u8fc7\u4e86\u9650\u5236<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<p>\u5728\u91cd\u6e29\u4e86\u4e00\u4e0b fork \u51fd\u6570\u7684\u4f7f\u7528\u540e\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u7814\u7a76\u4e00\u4e2a\u8bdd\u9898\uff1a<\/p>\n<blockquote>\n<p>fork() \u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u64cd\u4f5c\u7cfb\u7edf\u505a\u4e86\u54ea\u4e9b\u64cd\u4f5c\uff1f<\/p>\n<\/blockquote>\n<p>\u8fdb\u7a0b\u8c03\u7528 fork\uff0c\u5f53\u63a7\u5236\u8f6c\u79fb\u5230\u5185\u6838\u4e2d\u7684fork\u4ee3\u7801\u540e\uff0c\u5185\u6838\u505a\u4e86\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<blockquote>\n<ul>\n<li>\n<p>\u5206\u914d\u65b0\u5f97\u5185\u5b58\u5757\u548c\u5185\u6838\u6570\u636e\u7ed3\u6784\u7ed9\u5b50\u8fdb\u7a0b\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06\u7236\u8fdb\u7a0b\u90e8\u5206\u6570\u636e\u7ed3\u6784\u5185\u5bb9\u62f7\u8d1d\u81f3\u5b50\u8fdb\u7a0b\u3002<\/p>\n<\/li>\n<li>\n<p>\u6dfb\u52a0\u5b50\u8fdb\u7a0b\u5230\u7cfb\u7edf\u8fdb\u7a0b\u5217\u8868\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>fork\u8fd4\u56de\uff0c\u5f00\u59cb\u8c03\u5ea6\u5668\u8c03\u5ea6\u3002<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb8770b5.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe2\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe2\" \/><\/p>\n<p>\u7236\u8fdb\u7a0b\u6267\u884c\u5b8c fork\u4e4b\u524d\u7684\u4ee3\u7801(before)\u540e\uff0c\u8c03\u7528 fork \u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u7236\u5b50\u4e24\u4e2a\u6267\u884c\u6d41\u5206\u522b\u6267\u884c\u3002\u6ce8\u610f\uff1a<strong>fork \u4e4b\u540e\uff0c<\/strong><strong>\u8c01\u5148\u6267\u884c\u5b8c\u5168\u7531\u8c03\u5ea6\u5668\u51b3\u5b9a<\/strong>\u3002<\/p>\n<p>\u8fd9\u91cc\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u5f53fork\u4e4b\u540e\uff0c\u7236\u5b50\u8fdb\u7a0b\u4ee3\u7801\u5171\u4eab\u662f after \u5171\u4eab\uff0c\u8fd8\u662f\u6240\u6709\u4ee3\u7801\u90fd\u8fdb\u884c\u5171\u4eab?\u4e3a\u4ec0\u4e48\u5b50\u8fdb\u7a0b\u603b\u51c6\u786e\u5730\u6267\u884c fork \u4e4b\u540e\u5bf9\u5e94\u7684\u4ee3\u7801\uff1f<\/p>\n<blockquote>\n<p><strong>\u7b54\u6848\uff1a \u6240\u6709\u4ee3\u7801\u5171\u4eab\uff0c\u56e0\u4e3aCPU\u8bb0\u5f55\u4e86\u8fdb\u7a0b\u7684\u6267\u884c\u4f4d\u7f6e\u3002<\/strong><\/p>\n<ul>\n<li>\n<p>\u4ee3\u7801\u8fdb\u884c\u6c47\u7f16\u4e4b\u540e\uff0c\u4f1a\u6709\u5f88\u591a\u884c\u4ee3\u7801\uff0c\u800c\u4e14\u6bcf\u884c\u4ee3\u7801\u52a0\u8f7d\u5230\u5185\u5b58\u4e4b\u540e\uff0c\u90fd\u6709\u5bf9\u5e94\u7684\u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\u56e0\u4e3a\u8fdb\u7a0b\u968f\u65f6\u90fd\u53ef\u80fd\u88ab\u4e2d\u65ad(\u53ef\u80fd\u5e76\u6ca1\u6709\u6267\u884c\u5b8c)\uff0c\u4e0b\u6b21\u7ee7\u7eed\u6267\u884c\u65f6\uff0c\u8fd8\u5fc5\u987b\u4ece\u4e4b\u524d\u7684\u4f4d\u7f6e\u7ee7\u7eed\u8fd0\u884c(\u5e76\u4e0d\u662f\u7a0b\u5e8f\u6700\u5f00\u59cb\u6216main\u51fd\u6570\u5904)\uff0c\u8fd9\u5c31\u8981\u6c42 CPU \u5fc5\u987b\u5b9e\u65f6\u8bb0\u5f55\u4e0b\u5f53\u524d\u8fdb\u7a0b\u6267\u884c\u7684\u4f4d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>\u6240\u4ee5\uff0cCPU\u5185\u6709\u5bf9\u5e94\u7684\u5bc4\u5b58\u5668\u6570\u636e\uff0c\u7528\u6765\u8bb0\u5f55\u5f53\u524d\u8fdb\u7a0b\u7684\u6267\u884c\u4f4d\u7f6e\uff0c\u6b64\u5bc4\u5b58\u5668\u53eb\u505aEIP\uff0c\u4e5f\u79f0\u4f5c\u4e3apc(point code \u7a0b\u5e8f\u8ba1\u6570\u5668)\uff0c\u7528\u6765\u8bb0\u5f55\u6b63\u5728\u6267\u884c\u4ee3\u7801\u7684\u4e0b\u4e00\u884c\u4ee3\u7801\u7684\u5730\u5740(\u4e0a\u4e0b\u6587\u6570\u636e)\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f53\u5b50\u8fdb\u7a0b\u521b\u5efa\u65f6\uff0c\u4f1a\u4fee\u6539\u5176EIP\u3002\u6b64\u65f6\u5b50\u8fdb\u7a0b\u4fbf\u4f1a\u8ba4\u4e3aEIP\u7684\u4e2d\u4fdd\u5b58\u4e0b\u7684\u6570\u636e\uff0c\u5c31\u662f\u8981\u6267\u884c\u7684\u4ee3\u7801\u3002<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<hr>\n<p>\u521b\u5efa\u5b50\u8fdb\u7a0b\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u7ed9\u5b50\u8fdb\u7a0b\u5206\u914d\u5bf9\u5e94\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b50\u8fdb\u7a0b\u72ec\u7acb\u8fd0\u884c\uff0c\u56e0\u4e3a\u8fdb\u7a0b\u5177\u6709\u72ec\u7acb\u6027\u3002<\/p>\n<p>\u7406\u8bba\u4e0a\uff0c\u5b50\u8fdb\u7a0b\u4e5f\u8981\u6709\u81ea\u5df1\u7684\u4ee3\u7801\u548c\u6570\u636e\uff0c\u4f46\u662f\u4e00\u822c\u800c\u8a00\uff0c\u521b\u5efa\u5b50\u8fdb\u7a0b\u6ca1\u6709\u52a0\u8f7d\u7684\u8fc7\u7a0b\uff0c\u5b50\u8fdb\u7a0b\u672c\u8eab\u5e76\u6ca1\u6709\u81ea\u5df1\u7684\u4ee3\u7801\u548c\u6570\u636e\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5b50\u8fdb\u7a0b\u53ea\u80fd &#8220;\u4f7f\u7528&#8221; \u7236\u8fdb\u7a0b\u7684\u4ee3\u7801\u548c\u6570\u636e\uff0c\u800c\u4ee3\u7801\u662f\u53ea\u8bfb\u7684\uff0c\u7236\u5b50\u5171\u4eab\u4e0d\u4f1a\u51b2\u7a81\uff1b\u800c\u6570\u636e\u662f\u53ef\u80fd\u88ab\u4fee\u6539\u7684\uff0c\u5fc5\u987b\u8fdb\u884c\u5206\u79bb\u3002<\/p>\n<p>\u8fd9\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4fbf\u91c7\u7528\u5199\u65f6\u62f7\u8d1d\u7684\u7b56\u7565\u3002<\/p>\n<p><strong>\u5199\u65f6\u62f7\u8d1d<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb878288.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe3\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe3\" \/><\/p>\n<blockquote>\n<p>OS \u4e3a\u4f55\u91c7\u7528\u5199\u65f6\u62f7\u8d1d\u6280\u672f\uff0c\u5bf9\u7236\u5b50\u8fdb\u7a0b\u8fdb\u884c\u5206\u79bb<\/p>\n<ul>\n<li>\n<p>\u5199\u5165\u65f6\u518d\u8fdb\u884c\u62f7\u8d1d\uff0c\u662f\u9ad8\u6548\u4f7f\u7528\u5185\u5b58\u7684\u4e00\u79cd\u8868\u73b0\u3002<\/p>\n<\/li>\n<li>\n<p>\u63d0\u9ad8\u4e86\u7cfb\u7edf\u7684\u8fd0\u884c\u6548\u7387\u3002<\/p>\n<\/li>\n<li>\n<p>OS\u65e0\u6cd5\u5728\u4ee3\u7801\u6267\u884c\u524d\u9884\u77e5\u54ea\u4e9b\u7a7a\u95f4\u4f1a\u88ab\u8bbf\u95ee\u3002<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<h3><strong>\u6269\u5c55\u77e5\u8bc6\uff1a\u8fdb\u7a0b\u7ec8\u6b62\u548c<\/strong><\/h3>\n<p><strong>\u8fdb\u7a0b\u7ec8\u6b62 <\/strong><\/p>\n<p>\u5f53\u8fdb\u7a0b\u7ec8\u6b62\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u91ca\u653e\u4e86\u8fdb\u7a0b\u7533\u8bf7\u7684\u76f8\u5173\u5185\u6838\u6570\u636e\u7ed3\u6784\u548c\u5bf9\u5e94\u7684\u4ee3\u7801\u7684\u6570\u636e\uff0c\u5176\u672c\u8d28\u5c31\u662f\u91ca\u653e\u7cfb\u7edf\u8d44\u6e90\uff0c<\/p>\n<p><strong>1\u3001\u8fdb\u7a0b\u9000\u51fa\u7801<\/strong><\/p>\n<blockquote>\n<p>\u8fdb\u7a0b\u7ec8\u6b62\u7684\u5e38\u89c1\u65b9\u5f0f\uff1a<\/p>\n<ol>\n<li>\n<p>\u4ee3\u7801\u8dd1\u5b8c\uff0c\u7ed3\u679c\u6b63\u786e\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ee3\u7801\u8dd1\u5b8c\uff0c\u7ed3\u679c\u4e0d\u6b63\u786e\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ee3\u7801\u6ca1\u6709\u8dd1\u5b8c\uff0c\u7a0b\u5e8f\u5d29\u6e83\u4e86\u3002<\/p>\n<\/li>\n<\/ol>\n<\/blockquote>\n<p>\u533a\u5206\u7b2c\u4e00\u79cd\u60c5\u51b5\u548c\u7b2c\u4e8c\u79cd\u60c5\u51b5\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8fdb\u7a0b\u7684\u9000\u51fa\u7801\u5f88\u6e05\u6670\u7684\u8fa8\u522b\u3002<\/p>\n<p>\u5173\u4e8e\u5b66\u4e60\u7684 C\u8bed\u8a00\u4e2d main \u51fd\u6570\u7684\u8fd4\u56de\u503c\uff0c\u5176\u4e2d main \u51fd\u6570\u7684\u8fd4\u56de\u503c\u5c31\u662f\u8fdb\u7a0b\u7684\u9000\u51fa\u7801\u3002\u5176\u610f\u4e49\u662f\u8fd4\u56de\u7ed9\u4e0a\u4e00\u7ea7\u8fdb\u7a0b\uff0c\u7528\u6765\u8bc4\u5224\u8be5\u8fdb\u7a0b\u6267\u884c\u7ed3\u679c\u3002<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684 C \u7a0b\u5e8f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb87a9cf.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe4\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe4\" \/><\/p>\n<p>\u7136\u540e\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<strong> echo $? <\/strong>\u83b7\u53d6\u6700\u8fd1\u4e00\u4e2a\u8fdb\u7a0b\u7684\u9000\u51fa\u7801\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb87d62f.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe5\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe5\" \/><\/p>\n<p>\u8fdb\u7a0b\u7684\u8fd4\u56de\u503c\u6709 0 \u548c\u975e0\u4e24\u79cd\u60c5\u51b5\uff0c\u5176\u4e2d 0 \u8868\u793a\u7a0b\u5e8f\u6210\u529f\u8fd0\u884c\u5e76\u7ed3\u679c\u6b63\u786e\uff0c\u800c\u975e0\u8868\u793a\u6210\u529f\u8fd0\u884c\u4f46\u7ed3\u679c\u6709\u8bef\uff0c\u975e\u96f6\u503c\u6709\u65e0\u6570\u4e2a\uff0c\u4e0d\u540c\u7684\u975e\u96f6\u503c\u5c31\u53ef\u4ee5\u5c31\u8868\u793a\u7740\u4e0d\u540c\u7684\u9519\u8bef\uff0c\u65b9\u4fbf\u6211\u4eec\u5b9a\u4e49\u9519\u8bef\u7684\u539f\u56e0\u3002<\/p>\n<blockquote>\n<p>\u90a3\u5e38\u89c1\u7684\u9519\u8bef\u4fe1\u606f\u6709\u54ea\u4e9b\u5462\uff1f<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 strerror \u5c06\u5176\u6253\u5370\u51fa\u6765<\/p>\n<\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb880e14.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe6\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe6\" \/><\/p>\n<p>\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb8847ba.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe7\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe7\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb885c41.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe8\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe8\" \/><\/p>\n<p>\u53d1\u73b0 linux \u4e0b\uff0c\u5171\u6709133\u6761\u9519\u8bef\u7801<\/p>\n<p><code>\u5f53\u7136\uff0c\u7a0b\u5e8f\u5d29\u6e83\u7684\u65f6\u5019\uff0c\u9000\u51fa\u7801\u6ca1\u6709\u610f\u4e49\u3002<\/code><\/p>\n<p>\u4f17\u6240\u5468\u77e5\uff0cLinux \u662f\u7528C\u8bed\u8a00\u5199\u7684\uff0c\u5176\u4e2d\u547d\u4ee4\u672c\u8d28\u5c31\u662fC\u8bed\u8a00\u7a0b\u5e8f\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u7684\u62ff ls \u547d\u4ee4\u6765\u4e3e\u4f8b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb889957.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe9\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe9\" \/><\/p>\n<p>\u800c 2 \u53f7\u9000\u51fa\u7801\u5bf9\u5e94\u7684\u62a5\u9519\u4fe1\u606f\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb88d0af.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe10\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe10\" \/><\/p>\n<p><strong>2\u3001exit \u4e0e _exit<\/strong><\/p>\n<p>\u5173\u4e8e\u7ec8\u6b62\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u4f7f\u7528 return \u8bed\u53e5\uff0c\u8fd8\u53ef\u4ee5\u8c03\u7528 exit \u548c _exit \u51fd\u6570<\/p>\n<p>exit\u51fd\u6570\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb89071e.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe11\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe11\" \/><\/p>\n<p>_exit\u51fd\u6570\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb892c67.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe12\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe12\" \/><\/p>\n<p>\u5173\u4e8e\u8fd9\u4e24\u4e2a\u51fd\u6570\u7684\u533a\u522b\u6709\u5f88\u591a\uff0c\u6211\u4eec\u5148\u4e3e\u4e00\u4e2a\u5c0f\u4f8b\uff1a<\/p>\n<p>\u6211\u4eec\u63a5\u4e0b\u6765\u4f7f\u7528 printf \u6253\u5370\u4e00\u6761\u4fe1\u606f\uff0c\u7136\u540esleep\u4e09\u79d2\uff0c\u518d\u4f7f\u7528 exit \u9000\u51fa\uff0c\u5e76\u89c2\u5bdf\u7ed3\u679c<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb8981a2.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe13\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe13\" \/><\/p>\n<p>\u56e0\u4e3a\u6211\u4eec\u5e26\u4e0a\u4e86 \\n \uff0c\u52a0\u4e0a \\n \u4f1a\u5237\u65b0\u7f13\u51b2\u533a\uff0c\u5c4f\u5e55\u4e0a\u5373\u51fa\u73b0\u6211\u4eec\u6253\u5370\u7684\u5185\u5bb9\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb89931d.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe14\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe14\" \/><\/p>\n<p>\u5982\u679c\u6211\u4eec\u4e0d\u5e26\u4e0a \\n \uff0c\u6211\u4eec\u518d\u89c2\u5bdf\u7ed3\u679c\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb89e5d4.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe15\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe15\" \/><\/p>\n<p>\u53d1\u73b0\uff1a\u56e0\u4e3a\u6ca1\u6709 \\n \uff0c\u6240\u4ee5 printf \u4e2d\u7684\u5185\u5bb9\u5e76\u6ca1\u6709\u5728\u4f11\u7720\u524d\u88ab\u6253\u5370\u51fa\u6765\uff0c\u800c\u662f\u8c03\u7528 exit \u540e\u5c06\u7f13\u51b2\u533a\u7684\u5185\u5bb9\u5237\u65b0\u51fa\u6765\u8f93\u51fa\u5728\u5c4f\u5e55\u4e0a\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u4f7f\u7528 _exit \u51fd\u6570<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb8a11a6.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe16\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe16\" \/><\/p>\n<p>\u8fd0\u884c\u53ef\u6267\u884c\u6587\u4ef6 b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb8a646f.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe17\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe17\" \/><\/p>\n<p>\u53d1\u73b0\u4ec0\u4e48\u5185\u5bb9\u90fd\u6ca1\u6709\u88ab\u6253\u5370\u51fa\u6765\uff0c\u4f7f\u7528 echo $? \u6253\u5370\u6700\u8fd1\u8fdb\u7a0b\u9000\u51fa\u7801\uff0c\u53d1\u73b0 b \u6587\u4ef6\u786e\u5b9e\u88ab\u6267\u884c\u4e86\u3002<\/p>\n<p>\u8fd9\u8bf4\u660e\uff0cexit\u662f\u5e93\u51fd\u6570\uff0c\u800c_exit \u662f\u7cfb\u7edf\u8c03\u7528\uff0c\u5176\u9000\u51fa\u8fdb\u7a0b\u65f6\u5e76\u6ca1\u6709\u5237\u65b0\u7f13\u51b2\u533a\u4e2d\u7684\u5185\u5bb9\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240403\/1712159672660d7bb8a9e50.jpg\" class=\"aligncenter\" title=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe18\" alt=\"linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u63d2\u56fe18\" \/><\/p>\n<p>\u6b64\u65f6\u6211\u4eec\u4fbf\u80fd\u5f97\u51fa\u4e00\u4e2a\u7ed3\u8bba\uff1a<\/p>\n<p>printf \u6570\u636e\u662f\u4fdd\u5b58\u5728&#8221;\u7f13\u51b2\u533a&#8221;\u4e2d\u7684\uff0cexit\u53ef\u4ee5\u5c06\u5176\u5237\u65b0\uff0c\u800c\u7cfb\u7edf\u8c03\u7528\u63a5\u53e3_exit\u4e0d\u80fd\u5c06\u5176\u5237\u65b0\u3002\u6240\u4ee5\uff0c\u7f13\u51b2\u533a\u5fc5\u5b9a\u4e0d\u5728\u64cd\u4f5c\u7cfb\u7edf\u5185\u90e8\uff0c\u800c\u662f\u7531C\u6807\u51c6\u5e93\u7ef4\u62a4\u7684\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b \u5b66\u4e60\u6587\u7ae0\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0\u300alinux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\u6709\u54ea\u4e9b\u300b\u5c06\u4f1a\u4ecb\u7ecd\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60\u6587\u7ae0\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01 linux\u521b\u5efa\u8fdb\u7a0b\u7684\u547d\u4ee4\uff1a1\u3001fork\u547d\u4ee4\uff0c\u53ef\u4ee5\u4ece\u5df2\u5b58\u5728\u8fdb\u7a0b\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u8fdb\u7a0b\uff0c\u8be5\u65b0\u8fdb\u7a0b\u4e3a\u5b50\u8fdb\u7a0b\uff0c\u800c\u539f\u8fdb\u7a0b\u4e3a\u7236\u8fdb\u7a0b\uff1b\u5b50\u8fdb\u7a0b\u5b8c\u5168\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u8d44\u6e90\u30022\u3001vfork\u547d\u4ee4\uff0c\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u4e0e\u7236\u8fdb\u7a0b\u5171\u4eab\u5730\u5740\u7a7a\u95f4\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b50\u8fdb\u7a0b\u5b8c\u5168\u8fd0\u884c\u5728\u7236\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u4e0a\u30023\u3001clone\u547d\u4ee4\uff0c\u53ef\u4ee5\u5c06\u7236\u8fdb\u7a0b\u8d44\u6e90\u6709\u9009\u62e9\u5730\u590d\u5236\u7ed9\u5b50\u8fdb\u7a0b\uff0c\u800c\u6ca1\u6709\u590d\u5236\u7684\u6570\u636e\u7ed3\u6784\u5219\u901a\u8fc7\u6307\u9488\u7684\u590d\u5236\u8ba9\u5b50\u8fdb\u7a0b\u5171\u4eab\u3002 Linux\u7cfb\u7edf\u79cd\u521b\u5efa\u8fdb\u7a0b\u6709fork\u3001vfork\u3001clone\u8fd9\u4e2a\u4e09\u540d\u547d\u4ee4\u53ef\u4f9b\u4f7f\u7528\u3002 fork fork\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u5b50\u8fdb\u7a0b\u53ea\u662f\u5b8c\u5168\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u8d44\u6e90\uff0c\u590d\u5236\u51fa\u6765\u7684\u5b50\u8fdb\u7a0b\u6709\u81ea\u5df1\u7684task_struct\u7ed3\u6784\u548cpid,\u4f46\u5374\u590d\u5236\u7236\u8fdb\u7a0b\u5176\u5b83\u6240\u6709\u7684\u8d44\u6e90\u3002\u4f8b\u5982\uff0c\u8981\u662f\u7236\u8fdb\u7a0b\u6253\u5f00\u4e86\u4e94\u4e2a\u6587\u4ef6\uff0c\u90a3\u4e48\u5b50\u8fdb\u7a0b\u4e5f\u6709\u4e94\u4e2a\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u800c\u4e14\u8fd9\u4e9b\u6587\u4ef6\u7684\u5f53\u524d\u8bfb\u5199\u6307\u9488\u4e5f\u505c\u5728\u76f8\u540c\u7684\u5730\u65b9\u3002\u6240\u4ee5\uff0c\u8fd9\u4e00\u6b65\u6240\u505a\u7684\u662f\u590d\u5236\u3002\u8fd9\u6837\u5f97\u5230\u7684\u5b50\u8fdb\u7a0b\u72ec\u7acb\u4e8e\u7236\u8fdb\u7a0b\uff0c \u5177\u6709\u826f\u597d\u7684\u5e76\u53d1\u6027\uff0c\u4f46\u662f\u4e8c\u8005\u4e4b\u95f4\u7684\u901a\u8baf\u9700\u8981\u901a\u8fc7\u4e13\u95e8\u7684\u901a\u8baf\u673a\u5236\uff0c\u5982\uff1apipe\uff0c\u5171\u4eab\u5185\u5b58\u7b49\u673a\u5236\uff0c \u53e6\u5916\u901a\u8fc7fork\u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u9700\u8981\u5c06\u4e0a\u9762\u63cf\u8ff0\u7684\u6bcf\u79cd\u8d44\u6e90\u90fd\u590d\u5236\u4e00\u4e2a\u526f\u672c\u3002\u8fd9\u6837\u770b\u6765\uff0cfork\u662f\u4e00\u4e2a\u5f00\u9500\u5341\u5206\u5927\u7684\u7cfb\u7edf\u8c03\u7528\uff0c\u8fd9\u4e9b\u5f00\u9500\u5e76\u4e0d\u662f\u6240\u6709\u7684\u60c5\u51b5\u4e0b\u90fd\u662f\u5fc5\u987b\u7684\uff0c\u6bd4\u5982\u67d0\u8fdb\u7a0bfork\u51fa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u540e\uff0c\u5176\u5b50\u8fdb\u7a0b\u4ec5\u4ec5\u662f\u4e3a\u4e86\u8c03\u7528exec\u6267\u884c\u53e6\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u90a3\u4e48\u5728fork\u8fc7\u7a0b\u4e2d\u5bf9\u4e8e\u865a\u5b58\u7a7a\u95f4\u7684\u590d\u5236\u5c06\u662f\u4e00\u4e2a\u591a\u4f59\u7684\u8fc7\u7a0b\u3002\u4f46\u7531\u4e8e\u73b0\u5728Linux\u4e2d\u662f\u91c7\u53d6\u4e86copy-on-write(COW\u5199\u65f6\u590d\u5236)\u6280\u672f\uff0c\u4e3a\u4e86\u964d\u4f4e\u5f00\u9500\uff0cfork\u6700\u521d\u5e76\u4e0d\u4f1a\u771f\u7684\u4ea7\u751f\u4e24\u4e2a\u4e0d\u540c\u7684\u62f7\u8d1d\uff0c\u56e0\u4e3a\u5728\u90a3\u4e2a\u65f6\u5019\uff0c\u5927\u91cf\u7684\u6570\u636e\u5176\u5b9e\u5b8c\u5168\u662f\u4e00\u6837\u7684\u3002\u5199\u65f6\u590d\u5236\u662f\u5728\u63a8\u8fdf\u771f\u6b63\u7684\u6570\u636e\u62f7\u8d1d\u3002\u82e5\u540e\u6765\u786e\u5b9e\u53d1\u751f\u4e86\u5199\u5165\uff0c\u90a3\u610f\u5473\u7740parent\u548cchild\u7684\u6570\u636e\u4e0d\u4e00\u81f4\u4e86\uff0c\u4e8e\u662f\u4ea7\u751f\u590d\u5236\u52a8\u4f5c\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u62ff\u5230\u5c5e\u4e8e\u81ea\u5df1\u7684\u90a3\u4e00\u4efd\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u964d\u4f4e\u7cfb\u7edf\u8c03\u7528\u7684\u5f00\u9500\u3002\u6240\u4ee5\u6709\u4e86\u5199\u65f6\u590d\u5236\u540e\u5462\uff0cvfork\u5176\u5b9e\u73b0\u610f\u4e49\u5c31\u4e0d\u5927\u4e86\u3002 \u3000\u3000fork()\u8c03\u7528\u6267\u884c\u4e00\u6b21\u8fd4\u56de\u4e24\u4e2a\u503c\uff0c\u5bf9\u4e8e\u7236\u8fdb\u7a0b\uff0cfork\u51fd\u6570\u8fd4\u56de\u5b50\u7a0b\u5e8f\u7684\u8fdb\u7a0b\u53f7\uff0c\u800c\u5bf9\u4e8e\u5b50\u7a0b\u5e8f\uff0cfork\u51fd\u6570\u5219\u8fd4\u56de\u96f6\uff0c\u8fd9\u5c31\u662f\u4e00\u4e2a\u51fd\u6570\u8fd4\u56de\u4e24\u6b21\u7684\u672c\u8d28\u3002 \u3000\u3000\u5728fork\u4e4b\u540e\uff0c\u5b50\u8fdb\u7a0b\u548c\u7236\u8fdb\u7a0b\u90fd\u4f1a\u7ee7\u7eed\u6267\u884cfork\u8c03\u7528\u4e4b\u540e\u7684\u6307\u4ee4\u3002\u5b50\u8fdb\u7a0b\u662f\u7236\u8fdb\u7a0b\u7684\u526f\u672c\u3002\u5b83\u5c06\u83b7\u5f97\u7236\u8fdb\u7a0b\u7684\u6570\u636e\u7a7a\u95f4\uff0c\u5806\u548c\u6808\u7684\u526f\u672c\uff0c\u8fd9\u4e9b\u90fd\u662f\u526f\u672c\uff0c\u7236\u5b50\u8fdb\u7a0b\u5e76\u4e0d\u5171\u4eab\u8fd9\u90e8\u5206\u7684\u5185\u5b58\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b50\u8fdb\u7a0b\u5bf9\u7236\u8fdb\u7a0b\u4e2d\u7684\u540c\u540d\u53d8\u91cf\u8fdb\u884c\u4fee\u6539\u5e76\u4e0d\u4f1a\u5f71\u54cd\u5176\u5728\u7236\u8fdb\u7a0b\u4e2d\u7684\u503c\u3002\u4f46\u662f\u7236\u5b50\u8fdb\u7a0b\u53c8\u5171\u4eab\u4e00\u4e9b\u4e1c\u897f\uff0c\u7b80\u5355\u8bf4\u6765\u5c31\u662f\u7a0b\u5e8f\u7684\u6b63\u6587\u6bb5\u3002\u6b63\u6587\u6bb5\u5b58\u653e\u7740\u7531cpu\u6267\u884c\u7684\u673a\u5668\u6307\u4ee4\uff0c\u901a\u5e38\u662fread-only\u7684\u3002 vfork \u3000\u3000vfork\u7cfb\u7edf\u8c03\u7528\u4e0d\u540c\u4e8efork\uff0c\u7528vfork\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u4e0e\u7236\u8fdb\u7a0b\u5171\u4eab\u5730\u5740\u7a7a\u95f4\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b50\u8fdb\u7a0b\u5b8c\u5168\u8fd0\u884c\u5728\u7236\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u4e0a\uff0c\u5982\u679c\u8fd9\u65f6\u5b50\u8fdb\u7a0b\u4fee\u6539\u4e86\u67d0\u4e2a\u53d8\u91cf\uff0c\u8fd9\u5c06\u5f71\u54cd\u5230\u7236\u8fdb\u7a0b\u3002 \u3000\u3000\u56e0\u6b64\uff0c\u4e0a\u9762\u7684\u4f8b\u5b50\u5982\u679c\u6539\u7528vfork()\u7684\u8bdd\uff0c\u90a3\u4e48\u4e24\u6b21\u6253\u5370a,b\u7684\u503c\u662f\u76f8\u540c\u7684\uff0c\u6240\u5728\u5730\u5740\u4e5f\u662f\u76f8\u540c\u7684\u3002 \u3000\u3000\u4f46\u6b64\u5904\u6709\u4e00\u70b9\u8981\u6ce8\u610f\u7684\u662f\u7528vfork()\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u5fc5\u987b\u663e\u793a\u8c03\u7528exit()\u6765\u7ed3\u675f\uff0c\u5426\u5219\u5b50\u8fdb\u7a0b\u5c06\u4e0d\u80fd\u7ed3\u675f\uff0c\u800cfork()\u5219\u4e0d\u5b58\u5728\u8fd9\u4e2a\u60c5\u51b5\u3002 \u3000\u3000Vfork\u4e5f\u662f\u5728\u7236\u8fdb\u7a0b\u4e2d\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684\u8fdb\u7a0b\u53f7\uff0c\u5728\u5b50\u8fdb\u7a0b\u4e2d\u8fd4\u56de0\u3002 \u3000\u3000\u7528 vfork\u521b\u5efa\u5b50\u8fdb\u7a0b\u540e\uff0c\u7236\u8fdb\u7a0b\u4f1a\u88ab\u963b\u585e\u76f4\u5230\u5b50\u8fdb\u7a0b\u8c03\u7528exec(exec\uff0c\u5c06\u4e00\u4e2a\u65b0\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8f7d\u5165\u5230\u5730\u5740\u7a7a\u95f4\u5e76\u6267\u884c\u4e4b\u3002)\u6216exit\u3002vfork\u7684\u597d\u5904\u662f\u5728\u5b50\u8fdb\u7a0b\u88ab\u521b\u5efa\u540e\u5f80\u5f80\u4ec5\u4ec5\u662f\u4e3a\u4e86\u8c03\u7528exec\u6267\u884c\u53e6\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u56e0\u4e3a\u5b83\u5c31\u4e0d\u4f1a\u5bf9\u7236\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u6709\u4efb\u4f55\u5f15\u7528\uff0c\u6240\u4ee5\u5bf9\u5730\u5740\u7a7a\u95f4\u7684\u590d\u5236\u662f\u591a\u4f59\u7684 \uff0c\u56e0\u6b64\u901a\u8fc7vfork\u5171\u4eab\u5185\u5b58\u53ef\u4ee5\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5f00\u9500\u3002 clone \u3000\u3000\u7cfb\u7edf\u8c03\u7528fork()\u548cvfork()\u662f\u65e0\u53c2\u6570\u7684\uff0c\u800cclone()\u5219\u5e26\u6709\u53c2\u6570\u3002fork()\u662f\u5168\u90e8\u590d\u5236\uff0cvfork()\u662f\u5171\u4eab\u5185\u5b58\uff0c\u800cclone() \u662f\u5219\u53ef\u4ee5\u5c06\u7236\u8fdb\u7a0b\u8d44\u6e90\u6709\u9009\u62e9\u5730\u590d\u5236\u7ed9\u5b50\u8fdb\u7a0b\uff0c\u800c\u6ca1\u6709\u590d\u5236\u7684\u6570\u636e\u7ed3\u6784\u5219\u901a\u8fc7\u6307\u9488\u7684\u590d\u5236\u8ba9\u5b50\u8fdb\u7a0b\u5171\u4eab\uff0c\u5177\u4f53\u8981\u590d\u5236\u54ea\u4e9b\u8d44\u6e90\u7ed9\u5b50\u8fdb\u7a0b\uff0c\u7531\u53c2\u6570\u5217\u8868\u4e2d\u7684 clone_flags\u6765\u51b3\u5b9a\u3002\u53e6\u5916\uff0cclone()\u8fd4\u56de\u7684\u662f\u5b50\u8fdb\u7a0b\u7684pid\u3002 \u4e0b\u9762\u8be6\u7ec6\u4e86\u89e3fork\u547d\u4ee4\uff08\u8fdb\u7a0b\u521b\u5efa\uff09\u3002 \u6df1\u5165 fork \u51fd\u6570 \u5728 Linux \u4e2d fork \u51fd\u6570\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u51fd\u6570\uff0c\u5b83\u4ece\u5df2\u5b58\u5728\u8fdb\u7a0b\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u8fdb\u7a0b\u3002\u65b0\u8fdb\u7a0b\u4e3a\u5b50\u8fdb\u7a0b\uff0c\u800c\u539f\u8fdb\u7a0b\u4e3a\u7236\u8fdb\u7a0b\u3002 fork \u51fd\u6570\u7684\u8fd4\u56de\u503c: \u7ed9\u7236\u8fdb\u7a0b\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684 pid \u7ed9\u5b50\u8fdb\u7a0b\u8fd4\u56de0 \u63a5\u4e0b\u6765\u6211\u4eec\u4e3e\u4f8b\u4f7f\u7528\u4e00\u4e0bfork\u51fd\u6570 () \u6211\u4eec\u7f16\u8bd1\uff0c\u7136\u540e\u8fd0\u884c\u4e00\u4e0b\uff1a fork \u7684\u5e38\u89c4\u7528\u6cd5 \u4e00\u4e2a\u7236\u8fdb\u7a0b\u5e0c\u671b\u590d\u5236\u81ea\u5df1\uff0c\u4f7f\u7236\u5b50\u8fdb\u7a0b\u540c\u65f6\u6267\u884c\u4e0d\u540c\u7684\u4ee3\u7801\u6bb5\u3002\u4f8b\u5982\uff0c\u7236\u8fdb\u7a0b\u7b49\u5f85\u5ba2\u6237\u7aef\u8bf7\u6c42\uff0c\u751f\u6210\u5b50\u8fdb\u7a0b\u6765\u5904\u7406\u8bf7\u6c42\u3002 \u4e00\u4e2a\u8fdb\u7a0b\u8981\u6267\u884c\u4e00\u4e2a\u4e0d\u540c\u7684\u7a0b\u5e8f\u3002\u4f8b\u5982\u5b50\u8fdb\u7a0b\u4ecefork\u8fd4\u56de\u540e\uff0c\u8c03\u7528exec\u51fd\u6570\u3002 fork\u8c03\u7528\u5931\u8d25\u7684\u539f\u56e0 \u7cfb\u7edf\u4e2d\u6709\u592a\u591a\u7684\u8fdb\u7a0b \u5b9e\u9645\u7528\u6237\u7684\u8fdb\u7a0b\u6570\u8d85\u8fc7\u4e86\u9650\u5236 \u5728\u91cd\u6e29\u4e86\u4e00\u4e0b fork \u51fd\u6570\u7684\u4f7f\u7528\u540e\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u7814\u7a76\u4e00\u4e2a\u8bdd\u9898\uff1a fork() \u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u64cd\u4f5c\u7cfb\u7edf\u505a\u4e86\u54ea\u4e9b\u64cd\u4f5c\uff1f \u8fdb\u7a0b\u8c03\u7528 fork\uff0c\u5f53\u63a7\u5236\u8f6c\u79fb\u5230\u5185\u6838\u4e2d\u7684fork\u4ee3\u7801\u540e\uff0c\u5185\u6838\u505a\u4e86\u4ee5\u4e0b\u64cd\u4f5c\uff1a \u5206\u914d\u65b0\u5f97\u5185\u5b58\u5757\u548c\u5185\u6838\u6570\u636e\u7ed3\u6784\u7ed9\u5b50\u8fdb\u7a0b\u3002 \u5c06\u7236\u8fdb\u7a0b\u90e8\u5206\u6570\u636e\u7ed3\u6784\u5185\u5bb9\u62f7\u8d1d\u81f3\u5b50\u8fdb\u7a0b\u3002 [&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-51999","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/51999","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=51999"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/51999\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=51999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=51999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=51999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}