{"id":142696,"date":"2019-05-06T11:37:31","date_gmt":"2019-05-06T03:37:31","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=142696"},"modified":"2019-04-16T12:38:19","modified_gmt":"2019-04-16T04:38:19","slug":"system-call-mode","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/system-call-mode.html","title":{"rendered":"fork\u7cfb\u7edf\u8c03\u7528\u65b9\u5f0f\u6210\u4e3a\u8d1f\u62c5\uff0c\u9700\u8981\u6dd8\u6c70"},"content":{"rendered":"

\u5fae\u8f6f\u7814\u7a76\u4eba\u5458\u53d1\u8868\u8bba\u6587\u79f0\u7528\u4e8e\u521b\u5efa\u8fdb\u7a0b\u7684 fork \u7cfb\u7edf\u8c03\u7528\u65b9\u5f0f\u5df2\u7ecf\u5f88\u843d\u540e\uff0c\u5e76\u4e14\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u7684\u7814\u7a76\u4e0e\u53d1\u5c55\u4ea7\u751f\u4e86\u6781\u5927\u7684\u8d1f\u9762\u5f71\u54cd\uff0c\u9700\u8981\u6dd8\u6c70\uff0c\u4f5c\u8005\u540c\u65f6\u63d0\u51fa\u4e86\u66ff\u4ee3\u65b9\u6848\u3002
\n\"\"
\n\u76f8\u4fe1\u6bcf\u4f4d\u5f00\u53d1\u8005\u90fd\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684 fork () \u6709\u4e00\u5b9a\u7684\u4e86\u89e3\uff0c\u81f3\u5c11\u77e5\u9053\u5b83\u662f\u7528\u6765\u521b\u5efa\u8fdb\u7a0b\u7684\u3002fork \u7cfb\u7edf\u8c03\u7528\u65b9\u5f0f\u5728 20 \u4e16\u7eaa 70 \u5e74\u4ee3\u88ab\u521b\u9020\u51fa\u6765\uff0c\u5b83\u901a\u5e38\u4e0e exec () \u7ec4\u5408\u4f7f\u7528\uff0c\u975e\u5e38\u7b80\u5355\u5374\u5f88\u5f3a\u5927\uff0c\u88ab\u8ba4\u4e3a\u662f\u4e00\u79cd\u5929\u624d\u5f0f\u7684\u8bbe\u8ba1\u3001Unix \u7684\u4f1f\u5927\u601d\u60f3\uff0c\u81f3\u4eca 50 \u4f59\u5e74\u4e00\u76f4\u4f5c\u4e3a POSIX \u64cd\u4f5c\u7cfb\u7edf\u7684\u539f\u8bed\u5b58\u5728\uff0c\u540c\u65f6\u51e0\u4e4e\u6bcf\u4e2a Unix shell\u3001\u4e3b\u8981 Web \u548c\u6570\u636e\u5e93\u670d\u52a1\u5668\u3001Google Chrome\u3001Redis \u751a\u81f3 Node.js \u90fd\u4f7f\u7528 fork\u3002<\/p>\n

\u3000\u3000\u7136\u800c\u5fae\u8f6f\u7cfb\u7edf\u7814\u7a76\u5b9e\u9a8c\u5ba4 Redmond \u7684\u7814\u7a76\u4eba\u5458 3 \u6708\u4efd\u5374\u53d1\u8868\u4e86\u4e00\u7bc7\u8bba\u6587\uff0c\u8868\u793a fork \u4f5c\u4e3a\u64cd\u4f5c\u7cfb\u7edf\u539f\u8bed\u7ee7\u7eed\u5b58\u5728\uff0c\u963b\u788d\u4e86\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u7684\u7814\u7a76\uff0c\u201c\u5b83\u662f\u6765\u81ea\u53e6\u4e00\u4e2a\u65f6\u4ee3\u7684\u9057\u7269\uff0c\u4e0d\u9002\u5408\u73b0\u4ee3\u7cfb\u7edf\uff0c\u5e76\u4e14\u4f1a\u5e26\u6765\u4e00\u7cfb\u5217\u8d1f\u9762\u5f71\u54cd\u201d\uff0c\u7814\u7a76\u4eba\u5458\u8ba4\u4e3a\u662f\u65f6\u5019\u5c06 fork \u6dd8\u6c70\u4e86\u3002<\/p>\n

\u3000\u3000fork \u7b80\u5355\u5df2\u6210\u795e\u8bdd<\/p>\n

\u3000\u3000\u8bba\u6587\u4e2d\u627f\u8ba4\u4e86 fork API \u7684\u4f18\u70b9\uff0c\u5305\u62ec\u7b80\u5355\u4e0e\u7f13\u89e3\u5e76\u53d1\u6027\uff0c\u4e5f\u80af\u5b9a\u4e86 fork \u5728\u5386\u53f2\u4e0a\u7684\u91cd\u8981\u8d21\u732e\uff0c\u4f46\u66f4\u591a\u5730\u662f\u5217\u51fa\u4e86\u5b83\u5728\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u7814\u7a76\u4e0e\u53d1\u5c55\u4e2d\u7684\u5f0a\u7aef\u3002<\/p>\n

\u3000\u3000\u7814\u7a76\u4eba\u5458\u8ba4\u4e3a fork \u672c\u8eab\u5c31\u5b58\u5728\u8bb8\u591a\u95ee\u9898\uff0c\u53e6\u4e00\u65b9\u9762\uff0cfork \u5728\u64cd\u4f5c\u7cfb\u7edf\u7684\u7814\u7a76\u4e0e\u53d1\u5c55\u4e0a\u4e5f\u8d77\u4e86\u9650\u5236\u4f5c\u7528\uff0c\u8bba\u6587\u6307\u51fa\u6709\u660e\u786e\u7684\u8bc1\u636e\u8868\u660e\u652f\u6301 fork \u9650\u5236\u4e86 OS \u4f53\u7cfb\u7ed3\u6784\u7684\u53d8\u5316\uff0c\u5e76\u9650\u5236\u4e86\u64cd\u4f5c\u7cfb\u7edf\u9002\u5e94\u786c\u4ef6\u6f14\u8fdb\u7684\u80fd\u529b\u3002<\/p>\n

\u3000\u3000\u4e4d\u4e00\u770b\u53ef\u80fd\u4f1a\u89c9\u5f97 fork \u5f88\u7b80\u5355\uff0c\u800c\u8fd9\u4e5f\u662f\u5b83\u7684\u4e00\u5927\u7279\u5f81\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\uff0c\u201c\u8fd9\u662f\u4e00\u4e2a\u5177\u6709\u6b3a\u9a97\u6027\u7684\u795e\u8bdd\u201d\u3002<\/p>\n

\u3000\u3000fork \u7684\u8bed\u4e49\u5df2\u7ecf\u5f71\u54cd\u4e86\u6bcf\u4e2a\u521b\u5efa\u8fdb\u7a0b\u72b6\u6001\u7684\u65b0 API \u7684\u8bbe\u8ba1\uff0cPOSIX \u89c4\u8303\u73b0\u5728\u5217\u51fa\u4e86\u5173\u4e8e\u5982\u4f55\u5c06\u7236\u72b6\u6001\u590d\u5236\u5230\u5b50\u8fdb\u5ea6\u7684 25 \u4e2a\u7279\u6b8a\u60c5\u51b5\uff0c\u5305\u62ec\u6587\u4ef6\u9501\u5b9a\u3001\u5b9a\u65f6\u5668\u3001\u5f02\u6b65 IO \u64cd\u4f5c\u4e0e\u8ddf\u8e2a\u7b49\u3002\u6b64\u5916\uff0c\u8bb8\u591a\u7cfb\u7edf\u8c03\u7528\u6807\u5fd7\u63a7\u5236 fork \u5173\u4e8e\u5185\u5b58\u6620\u5c04\uff08Linux madvise () \u6807\u8bb0 MADV_DONTFORK\/DOFORK\/WIPEONFORK \u7b49\uff09\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08O_CLOEXEC\u3001FD_CLOEXEC\uff09\u548c\u7ebf\u7a0b\uff08pthread_atfork ()\uff09\u7684\u884c\u4e3a\u3002\u4efb\u4f55\u91cd\u8981\u7684\u64cd\u4f5c\u7cfb\u7edf\u5de5\u5177\u90fd\u5fc5\u987b\u901a\u8fc7 fork \u8bb0\u5f55\u5176\u884c\u4e3a\uff0c\u5e76\u4e14\u7528\u6237\u6a21\u5f0f\u5e93\u5fc5\u987b\u505a\u597d\u51c6\u5907\uff0c\u4ee5\u4fbf\u968f\u65f6 fork \u5b83\u4eec\u7684\u72b6\u6001\u3002fork \u5df2\u7ecf\u4e0d\u518d\u7b80\u5355\u3002<\/p>\n

\u3000\u3000fork \u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0cUnix \u8fdb\u7a0b\u652f\u6301\u7ebf\u7a0b\uff0c\u4f46 fork \u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\uff08\u8c03\u7528\u7ebf\u7a0b\u7684\u526f\u672c\uff09\uff0c\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u5728 fork \u65f6\uff0c\u5982\u679c\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u6b64\u65f6\u8fdb\u884c\u5185\u5b58\u5206\u914d\u5e76\u6301\u6709\u5806\u9501\uff0c\u4efb\u4f55\u5728\u5b50\u8fdb\u7a0b\u4e2d\u5206\u914d\u5185\u5b58\u7684\u5c1d\u8bd5\uff08\u4ece\u800c\u83b7\u5f97\u76f8\u540c\u7684\u9501\uff09\u90fd\u5c06\u7acb\u5373\u53d1\u751f\u6b7b\u9501\u3002<\/p>\n

\u3000\u3000fork \u5f88\u6162\uff0cfork \u7684\u6027\u80fd\u4e00\u76f4\u662f\u4e2a\u95ee\u9898\uff0c\u6b64\u524d\u4f7f\u7528\u5199\u65f6\u590d\u5236\u6280\u672f\u4f7f\u5176\u6027\u80fd\u53ef\u63a5\u53d7\uff0c\u4f46\u662f\u5728\u4eca\u5929\uff0c\u5efa\u7acb\u5199\u65f6\u590d\u5236\u6620\u5c04\u672c\u8eab\u90fd\u6210\u4e86\u4e00\u4e2a\u6027\u80fd\u95ee\u9898\uff0c\u6bd4\u5982 Chrome \u5728 fork \u65f6\u4f1a\u7ecf\u5386\u4e86\u957f\u8fbe 100 \u6beb\u79d2\u7684\u5ef6\u8fdf\uff0cNode.js \u5e94\u7528\u5728 exec \u4e4b\u524d fork \u65f6\uff0c\u53ef\u4ee5\u88ab\u963b\u585e\u51e0\u79d2\u949f\u3002fork+exec \u4e0e spawn \u7684\u6027\u80fd\u5bf9\u6bd4\u60c5\u51b5\u53ef\u4ee5\u901a\u8fc7\u672c\u6587\u5f00\u5934\u7684\u56fe\u7247\u76f4\u89c2\u770b\u5230\u3002<\/p>\n

\u3000\u3000fork \u65e0\u6cd5\u6269\u5c55\uff0c\u7cfb\u7edf\u89c4\u6a21\u7684\u8bbe\u8ba1\u9996\u5148\u8981\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u5171\u4eab\uff0c\u4f46 fork \u8fdb\u7a0b\u4f1a\u4e0e\u5176\u7236\u8fdb\u7a0b\u5171\u4eab\u6240\u6709\u5185\u5bb9\uff0c\u7531\u4e8e fork \u590d\u5236\u4e86\u8fdb\u7a0b\u64cd\u4f5c\u7cfb\u7edf\u72b6\u6001\u7684\u5404\u4e2a\u65b9\u9762\uff0c\u8fd9\u6837\u590d\u5236\u4e0e\u5f15\u7528\u8ba1\u6570\u6210\u672c\u4f1a\u6bd4\u8f83\u4f4e\uff0c\u6240\u4ee5 fork \u5176\u5b9e\u662f\u8d8b\u5411\u4e8e\u5c06\u72b6\u6001\u96c6\u4e2d\u5728\u5355\u7247\u5185\u6838\u4e2d\uff0c\u8fd9\u5c31\u4f7f\u5f97\u96be\u4ee5\u5b9e\u73b0\u4e00\u4e9b\u65b0\u6280\u672f\uff0c\u6bd4\u5982\u7528\u4e8e\u5b89\u5168\u6027\u548c\u53ef\u9760\u6027\u7684\u5185\u6838\u5212\u5206\u3002<\/p>\n

\u3000\u3000fork \u4e0e\u5f02\u6784\u786c\u4ef6\u4e0d\u517c\u5bb9\uff0c\u5b83\u5c06\u8fdb\u7a0b\u7684\u62bd\u8c61\u4e0e\u5305\u542b\u5b83\u7684\u786c\u4ef6\u5730\u5740\u7a7a\u95f4\u6df7\u4e3a\u4e00\u8c08\u3002fork \u5c06\u8fdb\u7a0b\u7684\u5b9a\u4e49\u9650\u5236\u4e3a\u5355\u4e2a\u5730\u5740\u7a7a\u95f4\uff0c\u5e76\u4e14\u662f\u5728\u67d0\u4e2a\u6838\u5fc3\u4e0a\u8fd0\u884c\u7684\u5355\u4e2a\u7ebf\u7a0b\u3002\u4f46\u73b0\u4ee3\u786c\u4ef6\u548c\u5728\u5176\u4e0a\u8fd0\u884c\u7684\u7a0b\u5e8f\u5e76\u4e0d\u662f\u8fd9\u6837\uff0c\u786c\u4ef6\u5f02\u6784\u5316\u8d8a\u6765\u8d8a\u4e25\u91cd\uff0c\u4f7f\u7528\u6709\u5185\u6838\u65c1\u8def NIC \u7684 DPDK \u6216\u5e26\u6709 GPU \u7684 OpenCL \u7684\u8fdb\u7a0b\u65e0\u6cd5\u5b89\u5168\u5730 fork\uff0c\u56e0\u4e3a\u64cd\u4f5c\u7cfb\u7edf\u65e0\u6cd5\u590d\u5236 NIC\/GPU \u4e0a\u7684\u8fdb\u7a0b\u72b6\u6001\u3002\u8fd9\u4e2a\u95ee\u9898\u81f3\u5c11\u5df2\u7ecf\u56f0\u6270\u4e86 GPU \u7a0b\u5e8f\u5458\u5341\u5e74\uff0c\u800c\u968f\u7740\u672a\u6765\u7684\u82af\u7247\u4e0a\u7cfb\u7edf\u5305\u542b\u8d8a\u6765\u8d8a\u591a\u7684\u72b6\u6001\u52a0\u901f\u5668\uff0c\u60c5\u51b5\u53ea\u4f1a\u53d8\u5f97\u66f4\u7cdf\u3002<\/p>\n

\u3000\u3000\u201cGET THE FORK OUT OF MY OS!\u201d<\/p>\n

\u3000\u3000\u8bba\u6587\u63d0\u51fa\u4e86\u66ff\u4ee3 fork \u7684\u65b9\u6848\uff1a\u5305\u62ec\u4e00\u4e2a\u9ad8\u7ea7 Spawn API \u548c\u4e00\u4e2a\u4f4e\u7ea7\u7c7b\u5fae\u5185\u6838 API \u7684\u7ec4\u5408\u3002\u6d89\u53ca\u5230 posix_spawn ()\u3001vfork ()\u3001\u8de8\u8fdb\u7a0b\u64cd\u4f5c\u3001clone ()\u3001\u6539\u8fdb\u5199\u65f6\u590d\u5236\u5185\u5b58\u7b49\u5185\u5bb9\u3002<\/p>\n

\u3000\u3000fork \u7684\u95ee\u9898\u8d8a\u6765\u8d8a\u4e25\u91cd\uff0c\u4f5c\u8005\u6700\u540e\u603b\u7ed3\u51fa\u5fc5\u987b\u505a\u4e09\u4ef6\u4e8b\u6765\u7ea0\u6b63\u8fd9\u79cd\u60c5\u51b5\uff0c\u4e0d\u4ec5\u8981\u5f03\u7528 fork\uff0c\u8fd8\u8981\u6539\u5584\u66ff\u4ee3\u65b9\u6848\uff0c\u540c\u65f6\u7ea0\u6b63\u6211\u4eec\u5173\u4e8e fork \u7684\u6559\u5b66\u5185\u5bb9\uff0c\u4e0d\u80fd\u518d\u9519\u8bef\u5730\u5ba3\u626c fork \u7684\u80fd\u529b\u4e0e\u8bbe\u8ba1\u6c34\u5e73\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5fae\u8f6f\u7814\u7a76\u4eba\u5458\u53d1\u8868\u8bba\u6587\u79f0\u7528\u4e8e\u521b\u5efa\u8fdb\u7a0b\u7684 fork \u7cfb\u7edf\u8c03\u7528\u65b9\u5f0f\u5df2\u7ecf\u5f88\u843d\u540e\uff0c\u5e76\u4e14\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u7684\u7814\u7a76\u4e0e\u53d1\u5c55\u4ea7\u751f\u4e86\u6781\u5927\u7684 […]<\/p>\n","protected":false},"author":1481,"featured_media":142698,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[21],"tags":[],"class_list":["post-142696","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=142696"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142696\/revisions"}],"predecessor-version":[{"id":142699,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/142696\/revisions\/142699"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/142698"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=142696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=142696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=142696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}