{"id":156180,"date":"2019-08-28T11:30:46","date_gmt":"2019-08-28T03:30:46","guid":{"rendered":"https:\/\/gulass.cn\/?p=156180"},"modified":"2019-08-27T14:21:23","modified_gmt":"2019-08-27T06:21:23","slug":"linux-system-programming","status":"publish","type":"post","link":"https:\/\/gulass.cn\/linux-system-programming.html","title":{"rendered":"Linux\u7cfb\u7edf\u7f16\u7a0b\u4e4b\u8fdb\u7a0b\u4ecb\u7ecd"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6211\u4eec\u5e73\u65f6\u5199\u7684 C \u8bed\u8a00\u4ee3\u7801\uff0c\u901a\u8fc7\u7f16\u8bd1\u5668\u7f16\u8bd1\uff0c\u6700\u7ec8\u5b83\u4f1a\u6210\u4e3a\u4e00\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\uff0c\u5f53\u8fd9\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\u8fd0\u884c\u8d77\u6765\u540e\uff08\u6ca1\u6709\u7ed3\u675f\u4e4b\u524d\uff09\uff0c\u5b83\u5c31\u6210\u4e3a\u4e86\u4e00\u4e2a\u8fdb\u7a0b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u4e00\u3001\u8fdb\u7a0b\u6982\u8ff0<\/strong><\/div>\n

\u6211\u4eec\u5e73\u65f6\u5199\u7684 C \u8bed\u8a00\u4ee3\u7801\uff0c\u901a\u8fc7\u7f16\u8bd1\u5668\u7f16\u8bd1\uff0c\u6700\u7ec8\u5b83\u4f1a\u6210\u4e3a\u4e00\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\uff0c\u5f53\u8fd9\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\u8fd0\u884c\u8d77\u6765\u540e\uff08\u6ca1\u6709\u7ed3\u675f\u4e4b\u524d\uff09\uff0c\u5b83\u5c31\u6210\u4e3a\u4e86\u4e00\u4e2a\u8fdb\u7a0b\u3002
\n\u7a0b\u5e8f\u662f\u5b58\u653e\u5728\u5b58\u50a8\u4ecb\u8d28\u4e0a\u7684\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u800c\u8fdb\u7a0b\u662f\u7a0b\u5e8f\u6267\u884c\u7684\u8fc7\u7a0b\u3002\u8fdb\u7a0b\u7684\u72b6\u6001\u662f\u53d8\u5316\u7684\uff0c\u5176\u5305\u62ec\u8fdb\u7a0b\u7684\u521b\u5efa\u3001\u8c03\u5ea6\u548c\u6d88\u4ea1\u3002\u7a0b\u5e8f\u662f\u9759\u6001\u7684\uff0c\u8fdb\u7a0b\u662f\u52a8\u6001\u7684\u3002
\n\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u64cd\u4f5c\u7cfb\u7edf\u662f\u901a\u8fc7\u8fdb\u7a0b\u53bb\u5b8c\u6210\u4e00\u4e2a\u4e00\u4e2a\u7684\u4efb\u52a1\uff0c\u8fdb\u7a0b\u662f\u7ba1\u7406\u4e8b\u52a1\u7684\u57fa\u672c\u5355\u5143\u3002\u8fdb\u7a0b\u62e5\u6709\u81ea\u5df1\u72ec\u7acb\u7684\u5904\u7406\u73af\u5883\uff08\u5982\uff1a\u5f53\u524d\u9700\u8981\u7528\u5230\u54ea\u4e9b\u73af\u5883\u53d8\u91cf\uff0c\u7a0b\u5e8f\u8fd0\u884c\u7684\u76ee\u5f55\u5728\u54ea\uff0c\u5f53\u524d\u662f\u54ea\u4e2a\u7528\u6237\u5728\u8fd0\u884c\u6b64\u7a0b\u5e8f\u7b49\uff09\u548c\u7cfb\u7edf\u8d44\u6e90\uff08\u5982\uff1a\u5904\u7406\u5668 CPU \u5360\u7528\u7387\u3001\u5b58\u50a8\u5668\u3001I\/O\u8bbe\u5907\u3001\u6570\u636e\u3001\u7a0b\u5e8f\uff09\u3002\u6211\u4eec\u53ef\u4ee5\u8fd9\u4e48\u7406\u89e3\uff0c\u516c\u53f8\u76f8\u5f53\u4e8e\u64cd\u4f5c\u7cfb\u7edf\uff0c\u90e8\u95e8\u76f8\u5f53\u4e8e\u8fdb\u7a0b\uff0c\u516c\u53f8\u901a\u8fc7\u90e8\u95e8\u6765\u7ba1\u7406\uff08\u7cfb\u7edf\u901a\u8fc7\u8fdb\u7a0b\u7ba1\u7406\uff09\uff0c\u5bf9\u4e8e\u5404\u4e2a\u90e8\u95e8\uff0c\u6bcf\u4e2a\u90e8\u95e8\u6709\u5404\u81ea\u7684\u8d44\u6e90\uff0c\u5982\u4eba\u5458\u3001\u7535\u8111\u8bbe\u5907\u3001\u6253\u5370\u673a\u7b49\u3002<\/p>\n

\u4e8c\u3001\u8fdb\u7a0b\u72b6\u6001<\/strong><\/div>\n

\u6211\u4eec\u73b0\u5728\u7684\u7535\u8111\u57fa\u672c\u4e0a\u90fd\u662f\u591a\u4efb\u52a1\uff0c\u6211\u4eec\u804a\u7740 QQ \u7684\u65f6\u5019\uff0c\u540c\u65f6\u53ef\u4ee5\u770b\u7740\u89c6\u9891\uff0c\u8fd9\u91cc\u76f8\u5f53\u4e8e QQ \u548c\u89c6\u9891\u4e24\u4e2a\u7a0b\u5e8f\u540c\u65f6\u8fd0\u884c\u7740\uff08\u4e24\u4e2a\u8fdb\u7a0b\uff09\u3002\u65e9\u671f\u7684\u65f6\u5019\uff0c\u7535\u8111\u7684 CPU \u662f\u5355\u6838\u7684\uff08\u5355\u6838\u7406\u8bba\u4e0a\u53ea\u8fd0\u884c\u64cd\u4f5c\u4e00\u4e2a\u4efb\u52a1\uff09\uff0c\u90a3\u5b83\u662f\u5982\u4f55\u505a\u5230\u591a\u4efb\u52a1\u7684\u5462\uff1f\u8fd9\u5c31\u6d89\u53ca\u5230\u8fdb\u7a0b\u7684\u8c03\u5ea6\u7b56\u7565\u3002\u73b0\u5728\u7ed9\u5927\u5bb6\u4e3e\u8fd9\u4e48\u4e00\u4e2a\u4f8b\u5b50\uff0c\u6709 A\uff0cB\uff0cC \u4e09\u4e2a\u8fdb\u7a0b\uff0c\u5728\u6211\u4eec\u5355 CPU \u7684\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e00\u4e2a\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u8fdb\u7a0b\u5728\u8fd0\u884c\uff0c\u5982\u679c A \u8fd0\u884c\u5b8c\uff0cB \u8fd0\u884c\uff0cB \u8fd0\u884c\u5b8c\uff0cC \u8fd0\u884c\uff0cC \u8fd0\u884c\u5b8c\uff0cA \u8fd0\u884c\uff0c\u800c CPU \u7684\u8fd0\u7b97\u901f\u5ea6\u8db3\u591f\u5feb\uff0cA \u4e24\u6b21\u8fd0\u884c\u65f6\u95f4\u95f4\u9694\u8db3\u591f\u77ed\uff0c\u4ece\u5b8f\u89c2\u4e0a\u5c31\u6211\u4eec\u5c31\u770b\u5230 A\uff0cB\uff0cC \u597d\u50cf\u540c\u65f6\u8fd0\u884c\uff0c\u8fd9\u5c31\u662f\u5b9e\u73b0\u5355 CPU \u8fd0\u884c\u591a\u4e2a\u4efb\u52a1\u7684\u6838\u5fc3\u539f\u7406\uff0c\u901a\u8fc7\u65f6\u95f4\u7247\u8f6e\u8be2\u8c03\u5ea6\u7b56\u7565\u5b9e\u73b0\u591a\u4efb\u52a1\uff08\u66f4\u591a\u8be6\u60c5\uff0c\u8bf7\u770b\u300aLinux \u8fdb\u7a0b\u8c03\u5ea6\u6d45\u6790\u300b\uff09\u3002
\n\u4ece\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u77e5\uff0c\u5bf9\u4e8e A \u8fdb\u7a0b\u800c\u8a00\uff0c\u6709\u65f6\u5019\u5728\u8fd0\u884c\uff0c\u6709\u65f6\u5019\u6ca1\u6709\u8fd0\u884c\uff0c\u4e24\u4e2a\u72b6\u6001\u4e0d\u4e00\u6837\uff0c\u6240\u4ee5\uff0c\u8fdb\u7a0b\u662f\u6709\u72b6\u6001\u7684\uff0c\u540c\u65f6\uff0c\u72b6\u6001\u662f\u53ef\u4ee5\u76f8\u4e92\u8fdb\u884c\u8f6c\u6362\u7684\uff0c\u4ece\u6267\u884c\u7684\u72b6\u6001\u8f6c\u6362\u4e3a\u4e0d\u6267\u884c\u7684\u72b6\u6001\uff0c\u8fd9\u91cc\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u8fdb\u7a0b\u8fd0\u884c\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f\u7b80\u5355\u5212\u5206\u4e3a\u4e09\u79cd\u72b6\u6001\uff08\u5b9e\u9645\u4e0a\u4e0d\u6307\u8fd9\u4e09\u79cd\u72b6\u6001\uff09\uff1a\u5c31\u7eea\u6001\u3001\u6267\u884c\u6001\u3001\u7b49\u5f85\u6001\u3002<\/p>\n

\u5c31\u7eea\u6001\uff1a<\/strong><\/span><\/div>\n

\u8fdb\u7a0b\u5df2\u7ecf\u5177\u5907\u6267\u884c\u7684\u4e00\u5207\u6761\u4ef6\uff0c\u6b63\u5728\u7b49\u5f85\u5206\u914d CPU \u7684\u5904\u7406\u65f6\u95f4\u3002<\/p>\n

\u6267\u884c\u6001\uff1a<\/strong><\/span><\/div>\n

\u8be5\u8fdb\u7a0b\u6b63\u5728\u5360\u7528 CPU \u8fd0\u884c\u3002<\/p>\n

\u7b49\u5f85\u6001\uff1a<\/strong><\/span><\/div>\n

\u8fdb\u7a0b\u56e0\u4e0d\u5177\u5907\u67d0\u4e9b\u6267\u884c\u6761\u4ef6\u800c\u6682\u65f6\u65e0\u6cd5\u7ee7\u7eed\u6267\u884c\u7684\u72b6\u6001\u3002
\n\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\uff0c\u5c31\u7eea\u6001\u548c\u7b49\u5f85\u6001\u90fd\u662f\u4e0d\u6267\u884c\uff0c\u4f46\u5b83\u4eec\u662f\u6709\u533a\u522b\u7684\uff0c\u5c31\u7eea\u6001\u662f\u6307\u6ee1\u8db3\u6761\u4ef6\uff0c\u65f6\u95f4\u6ca1\u5230\uff0c\u7b49\u5f85\u6001\u662f\u4e0d\u6ee1\u8db3\u6761\u4ef6\u3002
\n\u540c\u6837\u7684\uff0c\u8fdb\u7a0b\u7684\u8fd9\u4e09\u79cd\u72b6\u6001\u53ef\u4ee5\u76f8\u4e92\u8f6c\u6362\uff1a
\n\"\"<\/p>\n

\u6267\u884c\u6001-->\u7b49\u5f85\u6001\uff1a<\/strong><\/span><\/div>\n

\u6b63\u5728\u6267\u884c\u7684\u8fdb\u7a0b\u56e0\u7b49\u5f85\u67d0\u79cd\u4e8b\u4ef6\u53d1\u751f\u800c\u65e0\u6cd5\u7ee7\u7eed\u6267\u884c\u65f6\uff0c\u4fbf\u4ece\u6267\u884c\u72b6\u6001\u53d8\u6210\u7b49\u5f85\u72b6\u6001<\/p>\n

\u7b49\u5f85\u6001-->\u5c31\u7eea\u6001\uff1a<\/strong><\/span><\/div>\n

\u5904\u4e8e\u7b49\u5f85\u6001\u7684\u8fdb\u7a0b\uff0c\u82e5\u5176\u7b49\u5f85\u7684\u4e8b\u4ef6\u53d1\u751f\uff0c\u4e8e\u662f\u8fdb\u7a0b\u7531\u7b49\u5f85\u72b6\u6001\u53d8\u6210\u5c31\u7eea\u6001<\/p>\n

\u5c31\u7eea\u6001-->\u6267\u884c\u6001\uff1a<\/strong><\/span><\/div>\n

\u5f53\u5c31\u7eea\u6001\u7684\u8fdb\u7a0b\u6240\u7b49\u5f85\u7684cpu\u65f6\u95f4\u7247\u4e00\u5230\u6765\uff0c\u8fdb\u7a0b\u5c31\u4f1a\u4ece\u5c31\u7eea\u6001\u53d8\u6210\u6267\u884c\u6001<\/p>\n

\u6267\u884c\u6001-->\u5c31\u7eea\u6001\uff1a<\/strong><\/span><\/div>\n

\u5904\u4e8e\u6267\u884c\u72b6\u6001\u7684\u8fdb\u7a0b\u5728\u5176\u6267\u884c\u8fc7\u7a0b\u4e2d\uff0c\u56e0\u5206\u914d\u7ed9\u5b83\u7684\u4e00\u4e2a\u65f6\u95f4\u7247\u5df2\u7528\u5b8c\u800c\u4e0d\u5f97\u4e0d\u8ba9\u51facpu\uff0c\u4e8e\u662f\u8fdb\u7a0b\u4ece\u6267\u884c\u72b6\u6001\u8f6c\u53d8\u6210\u5c31\u7eea\u72b6\u6001
\n\u4e3a\u4e86\u8ba9\u5927\u5bb6\u66f4\u52a0\u6e05\u6670\u5730\u4e86\u89e3\u4e09\u79cd\u72b6\u6001\u7684\u8f6c\u6362\uff0c\u7ed9\u5927\u5bb6\u4e3e\u4e00\u4e2alh\u4e70\u706b\u8f66\u7968\u7684\u4f8b\u5b50\u3002
\nlh\u5306\u5fd9\u5730\u8d76\u53bb\u706b\u8f66\u7ad9\u4e70\u706b\u8f66\u7968\uff0c\u592a\u7740\u6025\u4e86\uff0c\u5230\u4e86\u552e\u7968\u5385\u624d\u53d1\u73b0\u5fd8\u8bb0\u5e26\u8eab\u4efd\u8bc1\uff0c\u8fd9\u65f6\u5019\uff0c\u5c31\u7b97 lh\u6392\u961f\u4e5f\u6ca1\u7528\uff0c\u56e0\u4e3a lh\u4e0d\u5177\u5907\u4e70\u7968\u7684\u6761\u4ef6\uff08\u6ca1\u5e26\u8eab\u4efd\u8bc1\uff09\uff0c\u8fd9\u65f6\u5019\u7684 lh\u5c5e\u4e8e\u7b49\u5f85\u6001\u3002
\nlh\u7ed9\u5b83\u5bf9\u8c61\u6253\u7535\u8bdd\uff0c\u8ba9\u5979\u628a\u8eab\u4efd\u8bc1\u5e26\u8fc7\u6765\uff0c\u7b49\u4f1a\uff0c\u8eab\u4efd\u8bc1\u9001\u5230\u4e86\uff0c\u8fd9\u65f6\u5019\uff0clh\u53ef\u4ee5\u53bb\u6392\u961f\u4e70\u7968\u4e86\uff0c\u53ea\u662f\u65f6\u95f4\u5230\uff0clh\u5c31\u53ef\u4ee5\u4e70\u7968\u4e86\uff0c\u8fd9\u65f6\uff0clh\u5c5e\u4e8e\u5c31\u7eea\u6001\u3002\u800c\u8fd9\u8fc7\u7a0b\u662f\u7531\u7b49\u5f85\u6001\u8f6c\u6362\u5230\u5c31\u7eea\u6001\u3002
\n\u7b49\u4e86 10 \u5206\u949f\uff0c\u7ec8\u4e8e\u5230 lh\u4e86\uff0clh\u5f00\u59cb\u4e70\u7968\uff0c\u8fd9\u65f6\u5019\uff0c lh\u5c5e\u4e8e\u6267\u884c\u6001\u3002\u800c\u8fd9\u8fc7\u7a0b\u662f\u7531\u5c31\u7eea\u6001\u8f6c\u6362\u4e3a\u6267\u884c\u6001\u3002
\n\u800c\u5728\u4e70\u7968\u7684\u8fc7\u7a0b\u4e2d\uff0clh\u7684\u5bf9\u8c61\u6253\u7535\u8bdd\u7ed9\u4ed6\uff0c\u8ba9 lh\u4e5f\u5e2e\u5979\u4e70\u4e00\u5f20\u706b\u8f66\u7968\uff0c\u4f46\u662f\uff0c lh\u6ca1\u6709\u5979\u5bf9\u8c61\u7684\u8eab\u4efd\u8bc1\uff0c\u63a5\u7740\uff0clh\u7ee7\u7eed\u7b49\u4ed6\u5bf9\u8c61\u9001\u8eab\u4efd\u8bc1\uff0c\u8fd9\u65f6\u5019\uff0clh\u7531\u6267\u884c\u6001\u8f6c\u6362\u4e3a\u7b49\u5f85\u6001\u3002
\n\u5047\u5982\u662f\u8fd9\u4e48\u4e00\u79cd\u60c5\u51b5\uff0clh\u4e70\u706b\u8f66\u7968\u662f\u7ed9\u516c\u53f8\u7684\u540c\u4e8b\u4e70\u7684\uff08\u9700\u8981\u4e70 100 \u591a\u5f20\u7968\uff09\uff0c\u5728\u4e70\u7740\u7968\u7684\u8fc7\u7a0b\u4e2d\uff08\u6267\u884c\u6001\uff09\uff0c\u540e\u9762\u8fd8\u6709\u5f88\u591a\u4eba\u5728\u6392\u961f\uff0c\u540e\u9762\u6392\u961f\u7684\u4eba\u80af\u5b9a\u4e0d\u723d\uff0c\u8fd9\u65f6\u552e\u7968\u5458\u5c31\u8bf4\uff0c20\u5206\u949f\u540e\uff0c\u5982\u679c\u4f60\u8fd8\u6ca1\u5904\u7406\u5b8c\uff0c\u8bf7\u4f60\u5230\u540e\u9762\u6392\u961f\u3002\u7ed3\u679c\uff0clh\u82b1\u4e86 20 \u5206\u949f\u8fd8\u662f\u6ca1\u6709\u5904\u7406\u5b8c\uff0c\u4e8e\u662f\uff0c\u4e56\u4e56\u5730\u5230\u540e\u9762\u91cd\u65b0\u6392\u961f\uff0c\u8fd9\u65f6\u5019\uff0clh\u7531\u6267\u884c\u6001\u8f6c\u6362\u4e3a\u5c31\u7eea\u6001\u3002<\/p>\n

\u4e09\u3001\u8fdb\u7a0b\u63a7\u5236\u5757<\/strong><\/div>\n

\u5bf9\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u800c\u8a00\uff0c\u5b83\u9700\u8981\u63a7\u5236\u5f88\u591a\u8fdb\u7a0b\uff0c\u540c\u65f6\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u6709\u4e0d\u540c\u7684\u72b6\u6001\uff0c\u7cfb\u7edf\u5982\u4f55\u77e5\u9053 A \u6267\u884c\u5b8c\u5230 B \u6267\u884c\u800c\u4e0d\u662f C\uff1f\u7cfb\u7edf\u5982\u4f55\u534f\u8c03\u63a7\u5236\u8fdb\u7a0b\u5462\uff1f
\n\u5f53\u6211\u4eec\u8fd0\u884c\u4e00\u4e2a\u7a0b\u5e8f\u4f7f\u5b83\u6210\u4e3a\u4e00\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5f00\u8f9f\u4e00\u6bb5\u5185\u5b58\u7a7a\u95f4\u5b58\u653e\u4e0e\u6b64\u8fdb\u7a0b\u76f8\u5173\u7684\u6570\u636e\u4fe1\u606f\uff0c\u800c\u8fd9\u4e2a\u6570\u636e\u4fe1\u606f\u662f\u901a\u8fc7\u7ed3\u6784\u4f53\uff08 task_struct\uff0cubuntu12.04\u4e2d\u6253\u5f00 \/usr\/src\/linux-headers-3.2.0-23\/include\/linux\/sched.h \u53ef\u4ee5\u627e\u5230 task_struct \u7684\u5b9a\u4e49 \uff09\u6765\u5b58\u653e\uff0c\u6211\u4eec\u628a\u8fd9\u4e2a\u5b58\u653e\u8fdb\u7a0b\u76f8\u5173\u6570\u636e\u4fe1\u606f\u7684\u7ed3\u6784\u4f53\u79f0\u4e3a\u8fdb\u7a0b\u63a7\u5236\u5757\u3002
\n\u64cd\u4f5c\u7cfb\u7edf\u5c31\u662f\u901a\u8fc7\u8fd9\u4e2a\u8fdb\u7a0b\u63a7\u5236\u5757\u6765\u64cd\u4f5c\u63a7\u5236\u8fdb\u7a0b\u3002\u66f4\u591a\u8be6\u60c5\uff0c\u8bf7\u770b\u300a Linux \u8fdb\u7a0b\u7ba1\u7406\u300b\u3002
\n\u8fdb\u7a0b\u63a7\u5236\u5757\u662f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u6700\u91cd\u8981\u7684\u8bb0\u5f55\u578b\u6570\u636e\u7ed3\u6784\u3002\u8fdb\u7a0b\u63a7\u5236\u5757\u8bb0\u5f55\u4e86\u7528\u4e8e\u63cf\u8ff0\u8fdb\u7a0b\u8fdb\u5c55\u60c5\u51b5\u53ca\u63a7\u5236\u8fdb\u7a0b\u8fd0\u884c\u6240\u9700\u7684\u5168\u90e8\u4fe1\u606f\uff0c\u5b83\u662f\u8fdb\u7a0b\u5b58\u5728\u7684\u552f\u4e00\u6807\u5fd7\u3002\u8fdb\u7a0b\u63a7\u5236\u5757\u91cc\u6709\u5f88\u591a\u4fe1\u606f\uff0c\u5176\u4e2d\u6bd4\u8f83\u91cd\u8981\u7684\u662f\u8fdb\u7a0b\u53f7\uff0c\u81f3\u4e8e\u5176\u4ed6\u7684\u4e00\u4e9b\u4fe1\u606f\u6211\u4eec\u4e0d\u5728\u8fd9\u8be6\u7ec6\u8ba8\u8bba\u3002<\/p>\n

\u56db\u3001\u8fdb\u7a0b\u53f7<\/strong><\/div>\n

\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u7531\u4e00\u4e2a\u8fdb\u7a0b\u53f7\u6765\u6807\u8bc6\uff0c\u5176\u7c7b\u578b\u4e3a pid_t\uff08\u65e0\u7b26\u53f7\u6574\u578b\uff09\uff0c\u8fdb\u7a0b\u53f7\u7684\u8303\u56f4\uff1a0\uff5e32767\u3002\u8fdb\u7a0b\u53f7\u603b\u662f\u552f\u4e00\u7684\uff0c\u4f46\u8fdb\u7a0b\u53f7\u53ef\u4ee5\u91cd\u7528\u3002\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u7ec8\u6b62\u540e\uff0c\u5176\u8fdb\u7a0b\u53f7\u5c31\u53ef\u4ee5\u518d\u6b21\u4f7f\u7528\u3002
\n\"\"
\n\u6240\u4ee5\uff0c\u5728 Linux \u4e0b\u9762\u6240\u6709\u7684\u8fdb\u7a0b\u90fd\u7531 init \u8fdb\u7a0b\u76f4\u63a5\u6216\u8005\u95f4\u63a5\u521b\u5efa\u3002
\n\u63a5\u4e0b\u6765\uff0c\u518d\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e09\u4e2a\u4e0d\u540c\u7684\u8fdb\u7a0b\u53f7\u3002
\n\u8fdb\u7a0b\u53f7\uff08PID\uff09\uff1a
\n\u6807\u8bc6\u8fdb\u7a0b\u7684\u4e00\u4e2a\u975e\u8d1f\u6574\u578b\u6570\u3002
\n\u7236\u8fdb\u7a0b\u53f7\uff08PPID\uff09\uff1a
\n\u4efb\u4f55\u8fdb\u7a0b\uff08 \u9664 init \u8fdb\u7a0b\uff09\u90fd\u662f\u7531\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u521b\u5efa\uff0c\u8be5\u8fdb\u7a0b\u79f0\u4e3a\u88ab\u521b\u5efa\u8fdb\u7a0b\u7684\u7236\u8fdb\u7a0b\uff0c\u5bf9\u5e94\u7684\u8fdb\u7a0b\u53f7\u79f0\u4e3a\u7236\u8fdb\u7a0b\u53f7\uff08PPID\uff09\u3002\u5982\uff0cA \u8fdb\u7a0b\u521b\u5efa\u4e86 B \u8fdb\u7a0b\uff0cA \u7684\u8fdb\u7a0b\u53f7\u5c31\u662f B \u8fdb\u7a0b\u7684\u7236\u8fdb\u7a0b\u53f7\u3002
\n\u8fdb\u7a0b\u7ec4\u53f7\uff08PGID\uff09\uff1a
\n\u8fdb\u7a0b\u7ec4\u662f\u4e00\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u7684\u96c6\u5408\u3002\u4ed6\u4eec\u4e4b\u95f4\u76f8\u4e92\u5173\u8054\uff0c\u8fdb\u7a0b\u7ec4\u53ef\u4ee5\u63a5\u6536\u540c\u4e00\u7ec8\u7aef\u7684\u5404\u79cd\u4fe1\u53f7\uff0c\u5173\u8054\u7684\u8fdb\u7a0b\u6709\u4e00\u4e2a\u8fdb\u7a0b\u7ec4\u53f7\uff08PGID\uff09 \u3002\u8fd9\u4e2a\u8fc7\u7a0b\u6709\u70b9\u7c7b\u4f3c\u4e8e QQ \u7fa4\uff0c\u7ec4\u76f8\u5f53\u4e8e QQ \u7fa4\uff0c\u5404\u4e2a\u8fdb\u7a0b\u76f8\u5f53\u4e8e\u5404\u4e2a\u597d\u53cb\uff0c\u628a\u5404\u4e2a\u597d\u53cb\u90fd\u62c9\u5165\u8fd9\u4e2a QQ \u7fa4\u91cc\uff0c\u4e3b\u8981\u662f\u65b9\u4fbf\u7ba1\u7406\uff0c\u7279\u522b\u662f\u901a\u77e5\u67d0\u4e9b\u4e8b\u65f6\uff0c\u53ea\u8981\u5728\u7fa4\u91cc\u543c\u4e00\u58f0\uff0c\u6240\u6709\u4eba\u90fd\u6536\u5230\uff0c\u7b80\u5355\u7c97\u66b4\u3002\u4f46\u662f\uff0c\u8fd9\u4e2a\u8fdb\u7a0b\u7ec4\u53f7\u548c QQ \u7fa4\u53f7\u662f\u6709\u70b9\u533a\u522b\u7684\uff0c\u9ed8\u8ba4\u7684\u60c5\u51b5\u4e0b\uff0c\u5f53\u524d\u7684\u8fdb\u7a0b\u53f7\u4f1a\u5f53\u505a\u5f53\u524d\u7684\u8fdb\u7a0b\u7ec4\u53f7\u3002<\/p>\n

\u4e94\u3001\u8fdb\u7a0b\u53f7\u64cd\u4f5c\u51fd\u6570<\/strong><\/div>\n

Linux \u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u4e86\u4e09\u4e2a\u83b7\u5f97\u8fdb\u7a0b\u53f7\u7684\u51fd\u6570 getpid()\u3001getppid()\u3001getpgid()<\/code>\u3002
\n\u6240\u9700\u5934\u6587\u4ef6\uff1a<\/p>\n

include\r\ninclude\r\npid_t getpid(void);<\/pre>\n

\u529f\u80fd\uff1a
\n\u83b7\u53d6\u672c\u8fdb\u7a0b\u53f7\uff08PID\uff09
\n\u53c2\u6570\uff1a\u65e0
\n\u8fd4\u56de\u503c\uff1a\u672c\u8fdb\u7a0b\u53f7<\/p>\n

pid_t getppid(void);<\/pre>\n

\u529f\u80fd\uff1a\u83b7\u53d6\u8c03\u7528\u6b64\u51fd\u6570\u7684\u8fdb\u7a0b\u7684\u7236\u8fdb\u7a0b\u53f7\uff08PPID\uff09
\n\u53c2\u6570\uff1a\u65e0
\n\u8fd4\u56de\u503c\uff1a<\/p>\n

pid_t getpgid(pid_tpid);<\/pre>\n

\u529f\u80fd\uff1a\u83b7\u53d6\u8fdb\u7a0b\u7ec4\u53f7\uff08PGID\uff09
\n\u53c2\u6570\uff1apid\uff1a\u8fdb\u7a0b\u53f7
\n\u8fd4\u56de\u503c\uff1a\u53c2\u6570\u4e3a 0 \u65f6\u8fd4\u56de\u5f53\u524d\u8fdb\u7a0b\u7ec4\u53f7\uff0c\u5426\u5219\u8fd4\u56de\u53c2\u6570\u6307\u5b9a\u7684\u8fdb\u7a0b\u7684\u8fdb\u7a0b\u7ec4\u53f7
\n\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

\r\ninclude\r\ninclude\r\ninclude\r\nint main(int argc, char *argv[])\r\n{\r\npid_t pid, ppid, pgid;\r\npid = getpid();\r\nprintf(\"pid = %d \", pid);\r\nppid = getppid();\r\nprintf(\"ppid = %d \", ppid);\r\npgid = getpgid(pid);\r\nprintf(\"pgid = %d \", pgid);\r\nreturn 0;\r\n}\r\n<\/pre>\n

\u8fd0\u884c\u7ed3\u679c\uff1a
\n\"\"<\/p>\n","protected":false},"excerpt":{"rendered":"

\u6211\u4eec\u5e73\u65f6\u5199\u7684 C \u8bed\u8a00\u4ee3\u7801\uff0c\u901a\u8fc7\u7f16\u8bd1\u5668\u7f16\u8bd1\uff0c\u6700\u7ec8\u5b83\u4f1a\u6210\u4e3a\u4e00\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\uff0c\u5f53\u8fd9\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\u8fd0\u884c\u8d77\u6765\u540e\uff08\u6ca1\u6709\u7ed3\u675f\u4e4b […]<\/p>\n","protected":false},"author":1893,"featured_media":156181,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-156180","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/156180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1893"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=156180"}],"version-history":[{"count":1,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/156180\/revisions"}],"predecessor-version":[{"id":156184,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/156180\/revisions\/156184"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/156181"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=156180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=156180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=156180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}