{"id":368,"date":"2016-08-13T08:02:34","date_gmt":"2016-08-13T00:02:34","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=368"},"modified":"2016-08-13T09:30:52","modified_gmt":"2016-08-13T01:30:52","slug":"fork%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=368","title":{"rendered":"fork\u51fd\u6570"},"content":{"rendered":"<p>\u4e00\u4e2a\u5b58\u5728\u7684\u8fdb\u7a0b\u53ef\u4ee5\u901a\u8fc7<span style=\"color: #993300;\">fork<\/span>\u51fd\u6570\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u3002<\/p>\n<table class=\"allBorders\" border=\"1\" rules=\"none\" cellspacing=\"0\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<pre><span style=\"color: #993300;\">#include &lt;unistd.h&gt;\r\n\r\npid_t fork(void);\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">Returns: 0 in child, process ID of child in parent, 1 on error<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u88ab<span style=\"color: #993300;\">fork<\/span>\u5efa\u7acb\u7684\u65b0\u8fdb\u7a0b\u53eb\u201c\u5b50\u8fdb\u7a0b\u201d\u3002\u8fd9\u4e2a\u51fd\u6570\u8c03\u7528\u4e00\u6b21\uff0c\u4f46\u8fd4\u56de\u4e24\u6b21\u3002\u4e24\u6b21\u8fd4\u56de\u503c\u552f\u4e00\u4e0d\u540c\u7684\u5730\u65b9\u662f\uff1a\u5728\u5b50\u8fdb\u7a0b\u4e2d\u8fd4\u56de0\uff0c\u800c\u5728\u7236\u8fdb\u7a0b\u4e2d\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684ID\u3002\u8fd9\u6837\u505a\u662f\u56e0\u4e3a\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u6709\u591a\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u5982\u679c\u4e0d\u5728\u7236\u8fdb\u7a0b\u4e2d\u83b7\u5f97\u5b50\u8fdb\u7a0b\u7684ID\uff0c\u90a3\u5c06\u4e0d\u4f1a\u6709\u4efb\u4f55\u7a0b\u5e8f\u80fd\u5f97\u5230\u5b50\u8fdb\u7a0b\u7684ID\u3002<span style=\"color: #993300;\">fork<\/span>\u7684\u5b50\u8fdb\u7a0b\u8fd4\u56de0\uff0c\u662f\u56e0\u4e3a\u5b50\u8fdb\u7a0b\u53ea\u80fd\u6709\u4e00\u4e2a\u7236\u8fdb\u7a0b\uff0c\u5e76\u4e14\u5b50\u8fdb\u7a0b\u53ef\u4ee5\u8c03\u7528<span style=\"color: #993300;\">getppid<\/span>\u83b7\u5f97\u7236\u8fdb\u7a0b\u7684ID\u3002\uff08PS:\u8fdb\u7a0bID0\u662f\u9884\u7559\u7ed9\u5185\u6838\u7684\uff0c\u6240\u4ee5\u4e0d\u53ef\u80fd\u5206\u914d\u7ed9\u5b50\u8fdb\u7a0b\u3002\uff09<\/p>\n<p>\u65e0\u8bba\u5b50\u8fdb\u7a0b\u8fd8\u662f\u7236\u8fdb\u7a0b\u90fd\u4f1a\u7ee7\u7eed\u6267\u884c<span style=\"color: #993300;\">fork<\/span>\u540e\u9762\u7684\u6307\u4ee4\u3002\u5b50\u8fdb\u7a0b\u4f1a\u590d\u5236\u7236\u8fdb\u7a0b\u3002\u5982\uff1a\u5b50\u8fdb\u7a0b\u4f1a\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u6570\u636e\u7a7a\u95f4\u3001\u5806\u548c\u6808\u3002 \u6ce8\u610f\uff1a\u8fd9\u53ea\u662f\u590d\u5236\uff0c\u800c\u4e0d\u662f\u7236\u3001\u5b50\u8fdb\u7a0b\u5171\u4eab\u4e00\u6bb5\u5185\u5b58\u3002\u4f46\u7236\u3001\u5b50\u8fdb\u7a0b\u5171\u4eab\u6587\u672c\u6bb5\u3002<\/p>\n<p>\u56e0\u4e3afork\u540e\u9762\u901a\u5e38\u662f\u8ddf\u4e00\u4e2aexec\u51fd\u6570\uff0c\u6240\u4ee5\u5f53\u524d\u53d1\u884c\u7248\u672c\u90fd\u6ca1\u590d\u5236\u5b8c\u6574\u7684\u7236\u8fdb\u7a0b\u6570\u636e\u7a7a\u95f4\u3001\u6808\u548c\u5806\u7684\u590d\u5236\u3002\u53d6\u800c\u4ee3\u4e4b\u7684\u662f\u4e00\u79cd\u53eb\u505aCOW\uff08COPY-ON-WRITE\uff0c\u5199\u65f6\u590d\u5236\uff09\u7684\u6280\u672f\u88ab\u4f7f\u7528\u3002\u88ab\u7236\u3001\u5b50\u8fdb\u7a0b\u5171\u4eab\u7684\u533a\u57df\u7531\u5185\u6838\u8bbe\u7f6e\u6210\u53ea\u8bfb\u9632\u6b62\u66f4\u6539\u3002\u5982\u679c\u7236\u3001\u5b50\u8fdb\u7a0b\u4e4b\u4e00\u8bd5\u56fe\u4fee\u6539\u8fd9\u4e2a\u533a\u57df\uff0c\u90a3\u4e48\u5185\u6838\u4f1a\u751f\u6210\u8be5\u5757\u5185\u5b58\u7684\u590d\u5236\uff0c\u901a\u5e38\u662f\u865a\u62df\u5b58\u50a8\u5668\u7cfb\u7edf\u4e2d\u7684\u201c\u4e00\u9875\u201d\u3002<\/p>\n<p>Linux 2.4.22\u540c\u6837\u63d0\u4f9b\u4e86\u65b0\u7684\u5efa\u7acb\u8fdb\u7a0b\u7684\u65b9\u6cd5\u2014\u2014<span style=\"color: #993300;\">clone<\/span>\u7cfb\u7edf\u8c03\u7528\uff0c\u5b83\u4ecefork\u4e2d\u884d\u751f\u51fa\u6765\uff0c\u5e76\u4e14\u5141\u8bb8\u8c03\u7528\u8005\u63a7\u5236\u7236\u3001\u5b50\u8fdb\u7a0b\u7684\u54ea\u4e9b\u53ef\u4ee5\u5171\u4eab\u3002<\/p>\n<p>\u4e00\u822c\u6765\u8bf4\u4e0d\u4f1a\u77e5\u9053\u5b50\u8fdb\u7a0b\u662f\u5728\u7236\u8fdb\u7a0b\u4e4b\u524d\u6267\u884c\u8fd8\u662f\u4e4b\u540e\u3002\u8fd9\u4f9d\u8d56\u4e8e\u5185\u6838\u7684\u8fdb\u7a0b\u8c03\u5ea6\u7b97\u6cd5\u3002\u5982\u679c\u9700\u8981\u7236\u3001\u5b50\u8fdb\u7a0b\u540c\u90e8\uff0c\u9700\u8981\u4f7f\u7528\u67d0\u4e9b\u8fdb\u7a0b\u95f4\u901a\u4fe1\u7684\u65b9\u6cd5\u3002<\/p>\n<p><span style=\"color: #993300;\">strlen<\/span>\u8ba1\u7b97\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u4e0d\u5305\u542b\u6700\u540e\u7684null\u5b57\u7b26\u3002<span style=\"color: #993300;\">sizeof<\/span>\u8ba1\u7b97\u7f13\u5b58\u7684\u957f\u5ea6\uff0c\u5305\u542b\u6700\u540e\u7684null\u5b57\u7b26\u3002\u5b83\u4eec\u4e24\u4e2a\u7684\u533a\u522b\u662f\uff1a<span style=\"color: #993300;\">strlen<\/span>\u9700\u8981\u51fd\u6570\u8c03\u7528\uff0c\u800c<span style=\"color: #993300;\">sizeof<\/span>\u662f\u5728\u7f16\u8bd1\u65f6\u523b\u624d\u8fd0\u884c\u7684\uff0c\u56e0\u4e3a\u7f13\u5b58\u4f7f\u7528\u5df2\u77e5\u7684\u5b57\u7b26\u4e32\u521d\u59cb\u5316\uff0c\u5e76\u4e14\u5b83\u662f\u56fa\u5b9a\u957f\u5ea6\u7684\u3002<\/p>\n<p>\u6ce8\u610f\u5728fork\u7684\u7a0b\u5e8f\u4e2d\u4f7f\u7528i\/o\u64cd\u4f5c\u65f6\uff0c\u5b83\u4eec\u4e4b\u95f4\u7684\u76f8\u4e92\u4f5c\u7528\u3002<span style=\"color: #993300;\">write<\/span>\u51fd\u6570\u662f\u65e0\u7f13\u51b2\u7684\u3002\u800c\u6807\u51c6\u51fd\u6570\u5e93\u5728\u8fde\u63a5\u5230\u7ec8\u7aef\u8bbe\u5907\u65f6\u662f\u884c\u7f13\u51b2\u7684\uff0c\u5176\u5b83\u60c5\u51b5\u662f\u5168\u7f13\u51b2\u7684\u3002\u5728\u4ea4\u4e92\u73af\u5883\u4f7f\u7528<span style=\"color: #993300;\">printf<\/span>\u65f6\uff0c\u6362\u884c\u4f1a\u5237\u65b0\u7f13\u51b2\u533a\u3002\u4f46\u662f\u5f53\u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u51fa\u5230\u6587\u4ef6\u65f6\uff0c\u4f1a\u5f97\u5230\u4e24\u4e2a<span style=\"color: #993300;\">printf<\/span>\u7684\u884c\u62f7\u8d1d\uff0c<span style=\"color: #993300;\">printf<\/span>\u5728<span style=\"color: #993300;\">fork<\/span>\u4e4b\u524d\u8c03\u7528\u4e00\u6b21\uff0c\u4f46\u662f\u7f13\u5b58\u4f1a\u4fdd\u7559\u5230<span style=\"color: #993300;\">fork<\/span>\u8c03\u7528\uff0c\u4e4b\u540e\u5728\u590d\u5236\u7236\u8fdb\u7a0b\u6570\u636e\u7a7a\u95f4\u5230\u5b50\u8fdb\u7a0b\u65f6\uff0c\u8fd9\u4e2a\u7f13\u5b58\u4f1a\u590d\u5236\u5230\u5b50\u8fdb\u7a0b\u3002<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<pre>#include \"apue.h\"\r\n\r\nint     glob = 6;       \/* external variable in initialized data *\/\r\nchar    buf[] = \"a write to stdout\\n\";\r\n\r\nint\r\nmain(void)\r\n{\r\n    int       var;      \/* automatic variable on the stack *\/\r\n    pid_t     pid;\r\n\r\n    var = 88;\r\n    if (write(STDOUT_FILENO, buf, sizeof(buf)-1) != sizeof(buf)-1)\r\n        err_sys(\"write error\");\r\n    printf(\"before fork\\n\");    \/* we don't flush stdout *\/\r\n\r\n    if ((pid = fork()) &lt; 0) {\r\n        err_sys(\"fork error\");\r\n    } else if (pid == 0) {      \/* child *\/\r\n        glob++;                 \/* modify variables *\/\r\n        var++;\r\n    } else {\r\n        sleep(2);               \/* parent *\/\r\n    }\r\n\r\n    printf(\"pid = %d, glob = %d, var = %d\\n\", getpid(), glob, var);\r\n    exit(0);\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<p class=\"docText\">If we execute this program, we get<\/p>\n<pre>$ .\/<span class=\"docEmphStrong\">a.out<\/span>\r\na write to stdout\r\nbefore fork\r\npid = 430, glob = 7, var = 89      <span class=\"docEmphItalicAlt\">child's variables were changed<\/span>\r\npid = 429, glob = 6, var = 88      <span class=\"docEmphItalicAlt\">parent's copy was not changed<\/span>\r\n<span style=\"text-decoration: underline;\">$ .\/<span class=\"docEmphStrong\">a.out &gt; temp.out<\/span><\/span>\r\n$ <span class=\"docEmphStrong\">cat temp.out<\/span>\r\na write to stdout\r\nbefore fork\r\npid = 432, glob = 7, var = 89\r\nbefore fork\r\npid = 431, glob = 6, var = 88\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u6587\u4ef6\u5171\u4eab<\/h2>\n<p>\u5728\u7236\u8fdb\u7a0b\u4e2d\u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u51fa\uff0c\u5b50\u8fdb\u7a0b\u7684\u6807\u51c6\u8f93\u51fa\u4e5f\u4f1a\u88ab\u91cd\u5b9a\u5411\u3002\u5b9e\u9645\u4e0a\uff0cfork\u7684\u4e00\u4e2a\u7279\u6027\u662f\uff1a\u6240\u6709\u5728\u7236\u8fdb\u7a0b\u4e2d\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u90fd\u4f1a\u590d\u5236\uff08duplicated\uff09\u5230\u5b50\u8fdb\u7a0b\u4e2d\u3002\u8bf4\u590d\u5236\uff08duplicated\uff09\u7684\u539f\u56e0\u662f\u5b83\u7684\u884c\u4e3a\u5982\u540c\u5728\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e0a\u8c03\u7528\u4e86dup\u7a0b\u5e8f\u3002\u7236\u3001\u5b50\u8fdb\u7a0b\u5171\u4eab\u540c\u4e00\u4e2a\u6587\u4ef6\u8868\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u7236\u3001\u5b50\u8fdb\u7a0b\u5171\u4eab\u540c\u4e00\u4e2a\u6587\u4ef6\u504f\u79fb\u91cf\uff0c\u8fd9\u70b9\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p>\u8fd9\u6709\u4e24\u4e2a\u5e38\u7528\u65b9\u6cd5\uff0c\u7528\u4e8e\u5904\u7406<span style=\"color: #993300;\">fork<\/span>\u540e\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002<\/p>\n<ol>\n<li>\u7236\u8fdb\u7a0b\u7b49\u5f85\u5b50\u8fdb\u7a0b\u5b8c\u6210\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7236\u8fdb\u7a0b\u4e0d\u5bf9\u6587\u4ef6\u63cf\u8ff0\u7b26\u505a\u4efb\u4f55\u64cd\u4f5c\u3002\u5f53\u5b50\u8fdb\u7a0b\u7ed3\u675f\u540e\uff0c\u504f\u79fb\u91cf\u4f1a\u76f8\u5e94\u7684\u66f4\u65b0\u3002<\/li>\n<li>\u7236\u3001\u5b50\u8fdb\u7a0b\u505a\u4ed6\u4eec\u81ea\u5df1\u60f3\u505a\u7684\u4e8b\u3002\u5728\u8fd9\uff0c\u5f53fork\u540e\uff0c\u7236\u8fdb\u7a0b\u5173\u95ed\u4e0d\u9700\u8981\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5b50\u8fdb\u7a0b\u4e5f\u505a\u540c\u6837\u7684\u4e8b\u60c5\u3002\u8fd9\u6837\u5c31\u4e0d\u4f1a\u5e72\u6270\u5bf9\u65b9\u4f7f\u7528\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e86\u3002\u8fd9\u79cd\u65b9\u6cd5\u5e38\u7528\u5728\u7f51\u7edc\u670d\u52a1\u8fdb\u7a0b\u4e2d\u3002<\/li>\n<\/ol>\n<p>\u9664\u4e86\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e4b\u5916\uff0c\u8fd8\u6709\u5f88\u591a\u5c5e\u6027\u4ece\u7236\u8fdb\u7a0b\u4e2d\u7ee7\u627f\u5230\u5b50\u8fdb\u7a0b\u4e2d\uff1a<\/p>\n<ul>\n<li>\u5b9e\u9645\u7528\u6237ID\u3001\u5b9e\u9645\u7ec4ID\u3001\u6709\u6548\u7528\u6237ID\u3001\u6709\u6548\u7ec4ID<\/li>\n<li>\u9644\u52a0\u7ec4ID<\/li>\n<li>\u8fdb\u7a0b\u7ec4ID<\/li>\n<li>\u4f1a\u8bddID<\/li>\n<li>\u63a7\u5236\u7ec8\u7aef<\/li>\n<li>SUID\u548cSGID<\/li>\n<li>\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55<\/li>\n<li>\u6839\u76ee\u5f55<\/li>\n<li>\u6587\u4ef6\u6a21\u5f0f\u521b\u5efa\u5c4f\u853d\u5b57<\/li>\n<li>signal mask \u548c dispositions<\/li>\n<li>\u4efb\u4f55\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684close-on-exec\u6807\u8bb0<\/li>\n<li>\u73af\u5883<\/li>\n<li>attached shared memory segments<\/li>\n<li>\u5185\u5b58\u6620\u5c04<\/li>\n<li>\u8d44\u6e90\u9650\u5236<\/li>\n<\/ul>\n<p>\u7236\u5b50\u8fdb\u7a0b\u95f4\u4e0d\u540c\u7684\u662f\uff1a<\/p>\n<ul>\n<li><span style=\"color: #993300;\">fork<\/span>\u7684\u8fd4\u56de\u503c<\/li>\n<li>\u8fdb\u7a0bID<\/li>\n<li>\u7236\u3001\u5b50\u8fdb\u7a0b\u6709\u4e0d\u540c\u7684\u7236\u8fdb\u7a0bID\u3002<\/li>\n<li>\u5b50\u8fdb\u7a0b\u7684<span style=\"color: #993300;\">tms_utime<\/span>, <span style=\"color: #993300;\">tms_stime<\/span>, <span style=\"color: #993300;\">tms_cutime<\/span>\u548c<span style=\"color: #993300;\">tms_cstime<\/span>\u503c\u8bbe\u7f6e\u62100\u3002<\/li>\n<li>\u7236\u8fdb\u7a0b\u8bbe\u7f6e\u7684\u6587\u4ef6\u9501\u4e0d\u4f1a\u7ee7\u627f\u5230\u5b50\u8fdb\u7a0b\u3002<\/li>\n<li>\u4e3a\u5b50\u8fdb\u7a0b\u6e05\u9664\u672a\u5904\u7406\u7684\u8b66\u544a<\/li>\n<li>\u4e3a\u5b50\u8fdb\u8bbe\u7f6e\u7a7a\u7684\u672a\u5904\u7406\u4fe1\u53f7\u96c6<\/li>\n<\/ul>\n<p>\u8fd8\u6709\u5f88\u591a\u4ee5\u540e\u7ae0\u8282\u518d\u8bb2\u3002<\/p>\n<p><span style=\"color: #993300;\">fork<\/span>\u5931\u8d25\u7684\u4e3b\u8981\u539f\u56e0\u6709\u4e24\u4e2a\uff1a<\/p>\n<p>\uff08a\uff09\u7cfb\u7edf\u4e2d\u6709\u592a\u591a\u7684\u8fdb\u7a0b\u3002\u8fd9\u901a\u5e38\u610f\u5473\u7740\u67d0\u4e9b\u5730\u65b9\u51fa\u95ee\u9898\u4e86\u3002<\/p>\n<p>\uff08b\uff09\u8d85\u8fc7\u5f53\u524d\u7528\u6237\u7684\u6700\u5927\u8fdb\u7a0b\u603b\u6570\u9650\u5236\u3002CHILD_MAX\u6307\u5b9a\u4e86\u5b9e\u9645\u7528\u6237ID\u53ef\u4ee5\u540c\u65f6\u62e5\u6709\u7684\u6700\u5927\u8fdb\u7a0b\u6570\u3002<\/p>\n<p><span style=\"color: #993300;\">fork<\/span>\u6709\u4e24\u79cd\u7528\u6cd5\uff1a<\/p>\n<ol>\n<li>\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u60f3\u590d\u5236\u81ea\u5df1\uff0c\u53bb\u540c\u65f6\u6267\u884c\u4e0d\u540c\u7684\u4ee3\u7801\u6bb5\u3002\u8fd9\u901a\u5e38\u7528\u4e8e\u7f51\u7edc\u670d\u52a1\uff0c\u7236\u8fdb\u7a0b\u505a\u4e3a\u670d\u52a1\u7aef\u7b49\u5f85\uff0c\u5b50\u8fdb\u7a0b\u5904\u7406\u5ba2\u6237\u7aef\u53d1\u8d77\u7684\u8bf7\u6c42\u3002\u5f53\u8bf7\u6c42\u5230\u8fbe\u65f6\uff0c\u7236\u8fdb\u7a0b\u8c03\u7528fork\uff0c\u7136\u540e\u8ba9\u5b50\u8fdb\u7a0b\u5904\u7406\u8bf7\u6c42\u3002\u7136\u540e\u7236\u8fdb\u7a0b\u518d\u6b21\u56de\u5230\u7b49\u5f85\u72b6\u6001\u3002<\/li>\n<li>\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u60f3\u6267\u884c\u4e00\u4e2a\u4e0d\u540c\u7684\u7a0b\u5e8f\u65f6\u3002\u8fd9\u5e38\u7528\u4e8eshell\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5b50\u8fdb\u7a0b\u4ecefork\u8fd4\u56de\u540e\u7acb\u5373\u6267\u884c\u4e00\u4e2a<span style=\"color: #993300;\">exec<span style=\"color: #000000;\">\u3002\u4e00\u4e9b\u7cfb\u7edf\u6346\u7ed1\u4e86fork\u540e\u8ddf\u4e00\u4e2aexec\u5230\u4e00\u4e2a\u5355\u72ec\u64cd\u4f5c\uff0c\u88ab\u79f0\u4f5c\uff1a<span style=\"color: #993300;\">spawn<\/span>\u3002\u800cunix\u7cfb\u7edf\u5206\u5f00\u4e86\u8fd9\u4e24\u6b65\uff0c\u56e0\u4e3a\u5f88\u591a\u60c5\u51b5\u8981\u5355\u72ec\u4f7f\u7528<span style=\"color: #993300;\">fork<\/span>\u3002\u5206\u5f00\u64cd\u4f5c\u5141\u8bb8\u5b50\u8fdb\u7a0b\u5728fork\u548cexec\u4e4b\u95f4\u6539\u53d8\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u5c5e\u6027\u3002\u5982\uff1aI\/O\u91cd\u5b9a\u5411\uff0c\u7528\u6237ID\uff0csignal disposition\u7b49\u7b49\u3002<\/span><\/span><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u5b58\u5728\u7684\u8fdb\u7a0b\u53ef\u4ee5\u901a\u8fc7fork\u51fd\u6570\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u3002 #include &lt;unistd.h&gt; pid_t fork(void); Returns: &#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=368\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-apue"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=368"}],"version-history":[{"count":12,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions"}],"predecessor-version":[{"id":380,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions\/380"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}