{"id":503,"date":"2016-09-21T15:21:45","date_gmt":"2016-09-21T07:21:45","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=503"},"modified":"2016-12-01T15:27:19","modified_gmt":"2016-12-01T07:27:19","slug":"%e8%bf%9b%e7%a8%8b%e7%bb%84","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=503","title":{"rendered":"\u8fdb\u7a0b\u7ec4"},"content":{"rendered":"<p>\u8fdb\u7a0b\u7ec4\u662f\u4e00\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u7684\u96c6\u5408\uff0c\u901a\u5e38\u5b83\u4eec\u4e0e\u540c\u4e00\u4efb\u52a1\u76f8\u5173\u8054\uff0c\u5b83\u80fd\u4ece\u540c\u4e00\u7ec8\u7aef\u63a5\u6536\u4fe1\u53f7\u3002\u6bcf\u4e2a\u8fdb\u7a0b\u7ec4\u6709\u552f\u4e00\u7684\u8fdb\u7a0b\u7ec4ID\u3002\u8fdb\u7a0b\u7ec4ID\u548c\u8fdb\u7a0bID\u5f88\u76f8\u4f3c\uff1a\u5b83\u4eec\u90fd\u662f\u6b63\u6574\u6570\u5e76\u4e14\u80fd\u88ab\u5b58\u5230<span style=\"color: #993300;\">pid_t<\/span>\u7c7b\u578b\u4e2d\u3002\u51fd\u6570<span style=\"color: #993300;\">getpgrp<\/span>\u53ef\u4ee5\u8fd4\u56de\u8c03\u7528\u8fdb\u7a0b\u7684\u8fdb\u7a0b\u7ec4ID\uff1a<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<table class=\"allBorders\" style=\"height: 216px;\" border=\"1\" width=\"430\" 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 getpgrp(void);\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">Returns: process group ID of calling process<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u65e7\u7684BSD\u884d\u751f\u7cfb\u7edf\uff0c<span style=\"color: #993300;\">getpgrp<\/span>\u51fd\u6570\u9700\u8981\u4e00\u4e2a<em>pid<\/em>\u53c2\u6570\uff0c\u4e4b\u540e\u624d\u80fd\u8fd4\u56de\u8be5\u8fdb\u7a0b\u7684\u7ec4ID\u3002Single UNIX Specification\u5b9a\u4e49\u7684<span style=\"color: #993300;\">getpgid<\/span>\u51fd\u6570\u505a\u4e3aXSI\u6269\u5c55\uff0c\u6a21\u4eff\u4e86\u8fd9\u4e2a\u884c\u4e3a\u3002<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<table class=\"allBorders\" style=\"height: 194px;\" border=\"1\" width=\"439\" 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 getpgid(pid_t <span class=\"docEmphItalicAlt\">pid<\/span>);\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">Returns: process group ID if OK, 1 on error<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5982\u679cpid\u662f0(\u96f6)\u8c03\u7528\u8fdb\u7a0b\u7684\u7ec4ID\u88ab\u8fd4\u56de\u3002\u56e0\u6b64\uff0c<\/p>\n<p><span style=\"color: #993300;\">getpgid(0);<\/span><\/p>\n<p>\u7b49\u4e8e<\/p>\n<p><span style=\"color: #993300;\">getpgrp();<\/span><\/p>\n<p>\u6bcf\u4e2a\u8fdb\u7a0b\u7ec4\u53ef\u4ee5\u6709\u4e00\u4e2a\u8fdb\u7a0b\u7ec4\u957f\uff08process group leader\uff09\uff0c\u5728\u7ec4\u4e2d\u5efa\u7acb\u8fdb\u7a0b\u548c\u7ed3\u675f\u8fdb\u7a0b\u3002\u8fdb\u7a0b\u7ec4\u957f\u7684\u8868\u6807\u662f\uff0c\u5176\u8fdb\u7a0b\u7ec4ID\u7b49\u4e8e\u5176\u8fdb\u7a0bID\u3002\u53ea\u8981\u8fdb\u7a0b\u7ec4\u4e2d\u8fd8\u6709\u4e00\u4e2a\u8fdb\u7a0b\u5b58\u5728\uff0c\u65e0\u8bba\u5b83\u662f\u5426\u662f\u8fdb\u7a0b\u7ec4\u957f\uff0c\u8fdb\u7a0b\u7ec4\u90fd\u4f1a\u5b58\u5728\u3002\u8fdb\u7a0b\u7ec4\u7684\u751f\u547d\u5468\u671f\u8d77\u59cb\u4e8e\u8fdb\u7a0b\u7ec4\u7684\u5efa\u7acb\uff0c\u7ed3\u675f\u4e8e\u8fdb\u7a0b\u7ec4\u4e2d\u6700\u540e\u4e00\u4e2a\u8fdb\u7a0b\u79bb\u5f00\u8fdb\u7a0b\u7ec4\u3002\u6700\u540e\u4e00\u4e2a\u8fdb\u7a0b\u7684\u79bb\u5f00\uff0c\u53ef\u4ee5\u662f\u8fdb\u7a0b\u7ed3\u675f\uff0c\u4e5f\u53ef\u4ee5\u662f\u52a0\u5165\u5230\u5176\u5b83\u8fdb\u7a0b\u7ec4\u4e2d\u3002<\/p>\n<p>\u4e00\u4e2a\u8fdb\u7a0b\u52a0\u5230\u4e00\u4e2a\u5b58\u5728\u7684\u8fdb\u7a0b\u7ec4\u4e2d\u6216\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u7ec4\uff0c\u53ef\u80fd\u901a\u8fc7\u8c03\u7528<span style=\"color: #993300;\">setpgid<\/span>\u51fd\u6570\u3002\uff08\u4e4b\u540e\u8fd8\u4f1a\u4ecb\u7ecd<span style=\"color: #993300;\">setsid<\/span>\uff0c\u5b83\u4e5f\u53ef\u4ee5\u521b\u5efa\u8fdb\u7a0b\u7ec4\uff09<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<table class=\"allBorders\" style=\"height: 209px;\" border=\"1\" width=\"438\" 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\nint setpgid(pid_t <span class=\"docEmphItalicAlt\">pid<\/span>, pid_t <span class=\"docEmphItalicAlt\">pgid<\/span>);\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">Returns: 0 if OK, 1 on error<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u4e2a\u51fd\u6570\u8bbe\u7f6e\u8fdb\u7a0bID\u4e3a<em>pid<\/em>\u7684\u8fdb\u7a0b\u7ec4ID\u4e3a<em>pgid<\/em>\u3002\u5982\u679c\u4e24\u4e2a\u53c2\u6570\u76f8\u7b49\uff0c\u90a3\u4e48pid\u4f1a\u6210\u4e3a\u8fdb\u7a0b\u7ec4\u5934\uff08process group leader\uff09\u3002\u5982\u679c<em>pid<\/em>\u662f0(\u96f6)\uff0c\u90a3\u4e48\u4f7f\u7528\u8c03\u7528\u8005\u7684pid\u3002\u540c\u6837\uff0c\u5982\u679cpgid\u662f0\uff08\u96f6\uff09\uff0c<em>pid<\/em>\u505a\u4e3a\u8fdb\u7a0b\u7ec4ID\u3002<\/p>\n<p>\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u8bbe\u7f6e\u5b83\u7684\u8fdb\u7a0b\u7ec4ID\u662f\u5b83\u81ea\u5df1\u7684PID\u6216\u8005\u662f\u5b83\u5b50\u8fdb\u7a0b\u7684PID\u3002\u53e6\u5916\uff0c\u5728\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u8c03\u7528\u8fc7<span style=\"color: #993300;\">exec<\/span>\u51fd\u6570\u67d0\u4e2a\u7248\u672c\u540e\uff0c\u5b83\u4e0d\u80fd\u6539\u53d8\u8be5\u5b50\u8fdb\u7a0b\u7684\u8fdb\u7a0b\u7ec4ID\u3002\uff08Further more, it can&#8217;t change the process group ID of one of its children after that child has called one of the exec functions.\uff09<\/p>\n<p>\u5728\u591a\u6570\u7684\u4efb\u52a1\u63a7\u5236shell\u4e2d\uff0c\u8fd9\u4e2a\u51fd\u6570\u5728fork\u540e\u8c03\u7528\uff0c\u5728\u7236\u8fdb\u7a0b\u4e2d\u4e3a\u5b50\u8fdb\u7a0b\u8bbe\u7f6e\u8fdb\u7a0b\u7ec4ID\uff0c\u5728\u5b50\u8fdb\u7a0b\u4e2d\u4e3a\u81ea\u5df1\u8bbe\u7f6e\u8fdb\u7a0b\u7ec4ID\u3002\u8fd9\u4e24\u4e2a\u8c03\u7528\u5176\u4e2d\u4e4b\u4e00\u662f\u5197\u4f59\u7684\uff0c\u4f46\u662f\u901a\u8fc7\u8fd9\u79cd\u53cc\u4fdd\u9669\uff0c\u6211\u4eec\u53ef\u4ee5\u4fdd\u8bc1\u5728\u7236\u8fdb\u7a0b\u6216\u5b50\u8fdb\u7a0b\u8ba4\u4e3a\u5df2\u7ecf\u628a\u5b50\u8fdb\u7a0b\u653e\u5165\u81ea\u5df1\u7684\u8fdb\u7a0b\u7ec4\u4e4b\u524d\uff0c\u5df2\u7ecf\u628a\u5b50\u8fdb\u7a0b\u88ab\u653e\u5230\u81ea\u5df1\u7684\u8fdb\u7a0b\u7ec4\u4e2d\uff08One of these calls is redundant, but by doing both, we are guaranteed that the child is placed into its own process group before either process assumes that this has happened\uff09\u3002\u5982\u679c\u4e0d\u8fd9\u4e48\u505a\uff0c\u5c06\u4f1a\u4ea7\u751f\u7ade\u4e89\u6761\u4ef6\uff0c\u56e0\u4e3a\u5b50\u8fdb\u7a0b\u7684\u8fdb\u7a0b\u7ec4\u6210\u5458\u5c06\u4f9d\u8d56\u4e8e\u54ea\u4e2a\u8fdb\u7a0b\u5148\u6267\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fdb\u7a0b\u7ec4\u662f\u4e00\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u7684\u96c6\u5408\uff0c\u901a\u5e38\u5b83\u4eec\u4e0e\u540c\u4e00\u4efb\u52a1\u76f8\u5173\u8054\uff0c\u5b83\u80fd\u4ece\u540c\u4e00\u7ec8\u7aef\u63a5\u6536\u4fe1\u53f7\u3002\u6bcf\u4e2a\u8fdb\u7a0b\u7ec4\u6709\u552f\u4e00\u7684\u8fdb\u7a0b\u7ec4ID\u3002\u8fdb\u7a0b\u7ec4ID\u548c\u8fdb\u7a0bID\u5f88\u76f8\u4f3c\uff1a\u5b83\u4eec\u90fd\u662f\u6b63\u6574\u6570\u5e76\u4e14\u80fd\u88ab&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=503\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-503","post","type-post","status-publish","format-standard","hentry","category-apue"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/503","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=503"}],"version-history":[{"count":8,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/503\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/503\/revisions\/511"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}