{"id":106690,"date":"2026-09-18T01:08:36","date_gmt":"2026-09-17T17:08:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/106690.html"},"modified":"2026-09-18T01:08:36","modified_gmt":"2026-09-17T17:08:36","slug":"%e3%80%90linux%e7%b3%bb%e7%bb%9f%e3%80%91%e3%80%90linux%e8%bf%9b%e7%a8%8b%e7%bb%88%e6%ad%a2%e7%ad%89%e5%be%85%e8%af%a6%e8%a7%a3%e4%b8%8e%e7%a8%8b%e5%ba%8f%e6%9b%bf%e6%8d%a2%e6%9c%ba%e5%88%b6%e5%88%9d","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/106690.html","title":{"rendered":"\u3010Linux\u7cfb\u7edf\u3011\u3010Linux\u8fdb\u7a0b\u7ec8\u6b62\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u3011\u6d41\u98df\u822c\u6295\u5582"},"content":{"rendered":"<h2>Linux\u8fdb\u7a0b\u63a7\u5236\u4e09\u90e8\u66f2&#xff1a;\u7ec8\u6b62\u3001\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c<\/h2>\n<p>\u6587\u7ae0\u5b9a\u4f4d&#xff1a;\u8fdb\u7a0b\u63a7\u5236\u662f\u7406\u89e3\u64cd\u4f5c\u7cfb\u7edf&#034;\u5982\u4f55\u7ba1\u7406\u8fd0\u884c\u4e2d\u7684\u7a0b\u5e8f&#034;\u7684\u6838\u5fc3\u7ae0\u8282\u3002\u672c\u6587\u4f9d\u636e\u8bfe\u5802\u5b9e\u5f55\u6574\u7406&#xff0c;\u8986\u76d6\u8fdb\u7a0b\u7ec8\u6b62\u7684\u9000\u51fa\u7801\u8bed\u4e49\u3001wait\/waitpid\u50f5\u5c38\u8fdb\u7a0b\u56de\u6536\u3001status\u4f4d\u56fe\u89e3\u6790\u3001\u963b\u585e\/\u975e\u963b\u585e\u7b49\u5f85\u7684\u672c\u8d28\u533a\u522b&#xff0c;\u4ee5\u53caexec\u7a0b\u5e8f\u66ff\u6362\u7684\u521d\u6b65\u539f\u7406\u3002<\/p>\n<p>\u672c\u7ae0\u91cd\u70b9&#xff1a;\u8fdb\u7a0b\u7b49\u5f85\u3002\u7406\u89e3&#034;\u4e3a\u4ec0\u4e48\u8981\u7b49&#034;\u3001\u201c\u600e\u4e48\u7b49\u201d\u3001\u4ee5\u53ca&#034;\u7b49\u5f85\u65f6\u7236\u8fdb\u7a0b\u8be5\u5e72\u4ec0\u4e48&#034;&#xff0c;\u662f\u5199\u51fa\u5065\u58ee\u591a\u8fdb\u7a0b\u4ee3\u7801\u7684\u5173\u952e\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u8fdb\u7a0b\u7ec8\u6b62&#xff1a;\u7ed9\u7236\u8fdb\u7a0b\u4e00\u4e2a&#034;\u4ea4\u4ee3&#034;<\/h3>\n<h4>1.1 \u8fdb\u7a0b\u9000\u51fa\u7684\u4e09\u79cd\u573a\u666f<\/h4>\n<p>\u8001\u5e08\u53cd\u590d\u5f3a\u8c03&#xff1a;\u4e00\u4e2a\u8fdb\u7a0b\u9000\u51fa&#xff0c;\u4e16\u95f4\u53ea\u6709\u4e09\u79cd\u60c5\u51b5&#xff0c;\u518d\u65e0\u5176\u4ed6\u3002<\/p>\n<table>\n<tr>\u573a\u666f\u5224\u5b9a\u65b9\u5f0f\u9000\u51fa\u7801\u542b\u4e49<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u4ee3\u7801\u8dd1\u5b8c&#xff0c;\u7ed3\u679c\u6b63\u786e<\/td>\n<td align=\"left\">\u6b63\u5e38\u6267\u884c\u5230 main \u672b\u5c3e\u6216 exit(0)<\/td>\n<td align=\"left\">\u8fd4\u56de 0&#xff0c;\u8868\u793a\u4f7f\u547d\u8fbe\u6210<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u4ee3\u7801\u8dd1\u5b8c&#xff0c;\u7ed3\u679c\u4e0d\u6b63\u786e<\/td>\n<td align=\"left\">\u903b\u8f91\u9519\u8bef&#xff0c;\u5982\u6253\u5f00\u6587\u4ef6\u5931\u8d25\u3001\u6392\u5e8f\u7ed3\u679c\u9519\u8bef<\/td>\n<td align=\"left\">\u8fd4\u56de \u975e0&#xff0c;\u7528\u4e0d\u540c\u6570\u5b57\u8868\u793a\u4e0d\u540c\u9519\u8bef\u539f\u56e0<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u4ee3\u7801\u5f02\u5e38\u7ec8\u6b62<\/td>\n<td align=\"left\">\u9664\u96f6\u3001\u91ce\u6307\u9488\u3001\u6536\u5230\u7ec8\u6b62\u4fe1\u53f7<\/td>\n<td align=\"left\">\u9000\u51fa\u7801\u65e0\u610f\u4e49&#xff0c;\u8fdb\u7a0b\u88ab\u4fe1\u53f7\u4e2d\u65ad&#xff0c;\u6839\u672c\u6ca1\u8d70\u5230 return<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8bfe\u5802\u5b9e\u4f8b&#xff08;\u6587\u4ef6\u6253\u5f00\u5931\u8d25&#xff09;&#xff1a;<\/p>\n<p>FILE <span class=\"token operator\">*<\/span>fp <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">fopen<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;log.txt&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;r&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u5f53\u524d\u76ee\u5f55\u65e0\u6b64\u6587\u4ef6<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>fp <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> errno<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6253\u5f00\u5931\u8d25&#xff0c;\u8fd4\u56de errno<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token function\">fclose<\/span><span class=\"token punctuation\">(<\/span>fp<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/errno \u662f C \u6807\u51c6\u5e93\u5b9a\u4e49\u7684\u4e00\u4e2a\u5168\u5c40\u6574\u578b\u53d8\u91cf&#xff08;\u5b9e\u9645\u662f\u7ebf\u7a0b\u5c40\u90e8\u5b58\u50a8&#xff0c;int errno&#xff09;&#xff0c;<\/span><br \/>\n<span class=\"token comment\">\/\/\u7528\u4e8e\u8bb0\u5f55\u6700\u8fd1\u4e00\u6b21\u7cfb\u7edf\u8c03\u7528\u6216\u5e93\u51fd\u6570\u8c03\u7528\u5931\u8d25\u65f6\u7684\u9519\u8bef\u7801\u3002<\/span><\/p>\n<p>\u7f16\u8bd1\u8fd0\u884c\u540e&#xff0c;\u547d\u4ee4\u884c\u8f93\u5165echo $? \u8f93\u51fa 2\u3002\u4e3a\u4ec0\u4e48\u662f 2&#xff1f;\u56e0\u4e3a C \u6807\u51c6\u5e93\u4e2d\u9519\u8bef\u7801 ENOENT \u7684\u503c\u5c31\u662f 2&#xff0c;\u7528 strerror(2) \u8f6c\u6362\u540e\u6b63\u662f \u201c\u6ca1\u6709\u90a3\u4e2a\u6587\u4ef6\u6216\u76ee\u5f55\u201d\u3002&#xff08;strerror \u662f C \u5e93\u51fd\u6570&#xff0c;\u58f0\u660e\u5728 &lt;string.h&gt; \u5934\u6587\u4ef6\u4e2d&#xff0c;\u5b83\u7684\u4f5c\u7528\u662f\u628a\u9519\u8bef\u7801&#xff08;\u5982 errno \u7684\u503c&#xff09;\u8f6c\u6362\u6210\u5bf9\u5e94\u7684\u4eba\u7c7b\u53ef\u8bfb\u7684\u9519\u8bef\u63cf\u8ff0\u5b57\u7b26\u4e32\u3002&#xff09;<\/p>\n<p>\u8bfe\u5802\u5b9e\u4f8b&#xff08;ls \u547d\u4ee4\u7684\u9000\u51fa\u7801&#xff09;&#xff1a;<br \/>\n\u5728 Shell \u4e2d\u6267\u884c&#xff1a;<\/p>\n<p>$ <span class=\"token function\">ls<\/span> hello.txt  <span class=\"token comment\"># \u6587\u4ef6\u4e0d\u5b58\u5728&#xff0c;\u62a5\u9519<\/span><br \/>\n$ <span class=\"token builtin class-name\">echo<\/span> <span class=\"token variable\">$?<\/span>       <span class=\"token comment\"># \u8f93\u51fa 2<\/span><br \/>\n$ <span class=\"token function\">ls<\/span>            <span class=\"token comment\"># \u6b63\u5e38\u6267\u884c<\/span><br \/>\n$ <span class=\"token builtin class-name\">echo<\/span> <span class=\"token variable\">$?<\/span>       <span class=\"token comment\"># \u8f93\u51fa 0<\/span><\/p>\n<p>\u8001\u5e08\u501f\u6b64\u70b9\u660e&#xff1a;ls \u4e5f\u662f C \u8bed\u8a00\u5199\u7684\u8fdb\u7a0b&#xff0c;\u5b83\u9075\u5b88\u540c\u6837\u7684\u89c4\u8303\u2014\u20140 \u8868\u793a\u6210\u529f&#xff0c;\u975e 0 \u8868\u793a\u5931\u8d25\u3002<\/p>\n<p>\u8bfe\u5802\u5b9e\u4f8b&#xff08;\u81ea\u5b9a\u4e49\u9000\u51fa\u7801&#xff09;&#xff1a;<br \/>\n\u4f60\u53ef\u4ee5\u5b8c\u5168\u4e0d\u9075\u5b88\u7cfb\u7edf\u9ed8\u8ba4\u7684\u9519\u8bef\u7801&#xff0c;\u81ea\u5df1\u5b9a\u4e49\u4e00\u5957\u89c4\u5219\u3002\u6bd4\u5982\u5728\u4ee3\u7801\u91cc\u6545\u610f return 13;&#xff0c;echo $? \u5c31\u4f1a\u5f97\u5230 13\u3002\u201c\u6ca1\u4eba\u62e6\u7740\u4f60&#xff0c;\u4f60\u53ef\u4ee5\u6309\u7167\u81ea\u5df1\u7684\u8981\u6c42\u5b9a\u5236\u9000\u51fa\u7ed3\u679c\u3002\u201d<\/p>\n<h4>1.2 \u9000\u51fa\u7801\u7684\u672c\u8d28&#xff1a;main \u51fd\u6570\u8fd4\u56de\u503c\u5199\u7ed9\u8c01&#xff1f;<\/h4>\n<p>\u6211\u4eec\u5199\u7684 main \u51fd\u6570\u8fd4\u56de\u7684\u6574\u6570&#xff0c;\u4e0d\u662f\u8fd4\u56de\u7ed9\u7a0b\u5e8f\u5458\u770b\u7684&#xff0c;\u800c\u662f\u8fd4\u56de\u7ed9\u7236\u8fdb\u7a0b\u7684\u3002<\/p>\n<ul>\n<li>\u5728 Linux \u4e0b&#xff0c;main \u51fd\u6570\u6267\u884c return \u65f6&#xff0c;\u8be5\u503c\u88ab\u7f16\u8bd1\u5668\/\u8fd0\u884c\u65f6\u914d\u5408\u64cd\u4f5c\u7cfb\u7edf&#xff0c;\u5199\u5165\u5f53\u524d\u8fdb\u7a0b PCB&#xff08;task_struct&#xff09;\u4e2d\u7684 exit_code \u5b57\u6bb5\u3002<\/li>\n<li>\u8fdb\u7a0b\u53d8\u6210\u50f5\u5c38\u72b6\u6001&#xff08;Zombie&#xff09;\u540e&#xff0c;PCB \u4e0d\u91ca\u653e&#xff0c;\u6b63\u662f\u56e0\u4e3a\u91cc\u9762\u4fdd\u5b58\u7740\u9000\u51fa\u4fe1\u606f&#xff0c;\u7b49\u5f85\u7236\u8fdb\u7a0b\u6765&#034;\u8bfb\u53d6\u6848\u53d1\u73b0\u573a&#034;\u3002<\/li>\n<li>\u7236\u8fdb\u7a0b\u901a\u8fc7 wait\/waitpid \u62ff\u5230\u8fd9\u4e2a\u503c&#xff0c;Shell&#xff08;bash&#xff09;\u4f5c\u4e3a\u547d\u4ee4\u884c\u89e3\u91ca\u5668&#xff0c;\u4e5f\u662f\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u62ff\u5230\u5b50\u8fdb\u7a0b\u9000\u51fa\u7801&#xff0c;\u6700\u7ec8\u8ba9\u4f60\u80fd\u7528 echo $? \u67e5\u770b\u3002<\/li>\n<\/ul>\n<p>\u8865\u5145\u77e5\u8bc6\u70b9&#xff1a;\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u7528\u5168\u5c40\u53d8\u91cf\u4f20\u9000\u51fa\u4fe1\u606f&#xff1f;<br \/>\n\u6709\u540c\u5b66\u53ef\u80fd\u60f3&#xff1a;\u5b9a\u4e00\u4e2a\u5168\u5c40 int g_exit_code&#xff0c;\u5b50\u8fdb\u7a0b\u9000\u51fa\u524d\u6539\u5b83&#xff0c;\u7236\u8fdb\u7a0b\u76f4\u63a5\u8bfb\u4e0d\u884c\u5417&#xff1f;\u4e0d\u884c\u3002\u56e0\u4e3a\u8fdb\u7a0b\u5177\u6709\u72ec\u7acb\u6027&#xff0c;\u7236\u5b50\u8fdb\u7a0b\u5404\u81ea\u6709\u72ec\u7acb\u7684\u5730\u5740\u7a7a\u95f4\u548c\u9875\u8868&#xff08;\u5199\u65f6\u62f7\u8d1d&#xff09;\u3002\u5b50\u8fdb\u7a0b\u4fee\u6539\u81ea\u5df1\u7684\u5168\u5c40\u53d8\u91cf&#xff0c;\u7236\u8fdb\u7a0b\u6839\u672c\u770b\u4e0d\u5230&#xff08;\u4f1a\u53d1\u751f\u5199\u65f6\u62f7\u8d1d&#xff09;\u3002\u5fc5\u987b\u901a\u8fc7\u7cfb\u7edf\u8c03\u7528&#xff0c;\u8ba9\u64cd\u4f5c\u7cfb\u7edf\u4ece\u5185\u6838\u4e2d&#034;\u8f6c\u4ea4&#034;\u4fe1\u606f\u3002<\/p>\n<h4>1.3 \u5f02\u5e38\u9000\u51fa&#xff1a;\u4e00\u65e6\u5f02\u5e38&#xff0c;\u9000\u51fa\u7801\u5373\u523b&#034;\u4f5c\u5e9f&#034;<\/h4>\n<p>\u8bfe\u5802\u5b9e\u4f8b&#xff08;\u9664\u96f6\u5f02\u5e38&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> a <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">;<\/span><br \/>\na <span class=\"token operator\">\/&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u89e6\u53d1\u6d6e\u70b9\u6570\u5f02\u5e38<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token number\">89<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u8fd9\u884c\u6839\u672c\u6267\u884c\u4e0d\u5230&#xff01;<\/span><\/p>\n<p>\u8fd0\u884c\u540e echo $?&#xff0c;\u7ed3\u679c\u4e0d\u662f 89\u3002\u56e0\u4e3a\u4ee3\u7801\u5728\u9664\u96f6\u65f6\u5df2\u7ecf\u5f02\u5e38\u5d29\u6e83&#xff0c;\u8fdb\u7a0b\u6536\u5230 SIGFPE&#xff08;8\u53f7\u4fe1\u53f7&#xff09;&#xff0c;\u6839\u672c\u6ca1\u8dd1\u5230 return\u3002\u6b64\u65f6\u8c08\u8bba\u9000\u51fa\u7801\u662f\u6ca1\u6709\u610f\u4e49\u7684\u3002<\/p>\n<p>\u8001\u5e08\u7528\u4e86\u4e00\u4e2a\u7cbe\u5999\u7684\u7c7b\u6bd4&#xff1a;<\/p>\n<p>\u8003\u8bd5\u6709\u4e09\u79cd\u60c5\u51b5&#xff1a;\u8003 100 \u5206\u3001\u8003 59 \u5206\u3001\u4f5c\u5f0a\u88ab\u6293\u3002\u524d\u4e24\u79cd\u5c5e\u4e8e&#034;\u4ee3\u7801\u8dd1\u5b8c&#034;&#xff0c;\u6210\u7ee9&#xff08;\u9000\u51fa\u7801&#xff09;\u6709\u610f\u4e49&#xff1b;\u4e00\u65e6\u4f5c\u5f0a\u88ab\u6293&#xff08;\u5f02\u5e38\u7ec8\u6b62&#xff09;&#xff0c;\u8bd5\u5377\u90fd\u6ca1\u7b54\u5b8c&#xff0c;\u6210\u7ee9\u4fbf\u5931\u53bb\u610f\u4e49\u3002<\/p>\n<p>\u5176\u4ed6\u5f02\u5e38\u5b9e\u4f8b&#xff1a;<\/p>\n<ul>\n<li>\u91ce\u6307\u9488&#xff1a;*p &#061; 100;&#xff08;p \u6307\u5411\u7a7a\u5730\u5740&#xff09;&#xff0c;\u89e6\u53d1\u6bb5\u9519\u8bef SIGSEGV&#xff08;11\u53f7\u4fe1\u53f7&#xff09;\u3002<\/li>\n<li>\u88ab kill -9 \u6740\u6b7b&#xff1a;\u5b50\u8fdb\u7a0b\u6536\u5230 9 \u53f7\u4fe1\u53f7 SIGKILL&#xff0c;\u7236\u8fdb\u7a0b waitpid \u4f1a\u8bfb\u5230\u4fe1\u53f7\u503c\u4e3a 9&#xff0c;\u9000\u51fa\u7801\u65e0\u610f\u4e49\u3002<\/li>\n<\/ul>\n<p>\u6838\u5fc3\u7ed3\u8bba&#xff1a;\u8fdb\u7a0b\u9000\u51fa\u7801\u53ea\u6709\u5728&#034;\u6b63\u5e38\u8dd1\u5b8c&#034;\u65f6\u624d\u4ee3\u8868\u903b\u8f91\u7ed3\u679c&#xff1b;\u82e5\u5f02\u5e38\u7ec8\u6b62&#xff0c;\u7531\u7ec8\u6b62\u4fe1\u53f7\u8bf4\u4e86\u7b97\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u8fdb\u7a0b\u9000\u51fa\u7684\u4e09\u79cd\u5177\u4f53\u65b9\u5f0f<\/h3>\n<h4>2.1 return<\/h4>\n<ul>\n<li>\u53ea\u6709\u5728 main \u51fd\u6570\u91cc return \u624d\u7b49\u4ef7\u4e8e\u8fdb\u7a0b\u9000\u51fa&#xff1b;\u5176\u4ed6\u51fd\u6570\u7684 return \u53ea\u662f\u51fd\u6570\u8fd4\u56de\u3002<\/li>\n<\/ul>\n<h4>2.2 exit() \u2014\u2014 C \u5e93\u51fd\u6570<\/h4>\n<ul>\n<li>\u5728\u4ee3\u7801\u4efb\u610f\u4f4d\u7f6e\u8c03\u7528 exit(status)&#xff0c;\u90fd\u8868\u793a\u8fdb\u7a0b\u7acb\u5373\u7ec8\u6b62&#xff0c;\u540e\u7eed\u4ee3\u7801\u4e0d\u518d\u6267\u884c\u3002<\/li>\n<li>\u8c03\u7528\u540e\u4f1a\u6267\u884c\u6e05\u7406\u5de5\u4f5c&#xff1a;\u8c03\u7528\u901a\u8fc7 atexit \u6ce8\u518c\u7684\u51fd\u6570\u3001\u5237\u65b0\u7528\u6237\u6001\u7f13\u51b2\u533a\u3001\u5173\u95ed\u6d41&#xff08;FILE*&#xff09;\u3002<\/li>\n<li>\u5e95\u5c42\u5c01\u88c5\u4e86\u7cfb\u7edf\u8c03\u7528 _exit&#xff0c;\u4f46\u591a\u4e86\u4e00\u5c42 C \u8bed\u8a00\u8fd0\u884c\u65f6\u7684\u6536\u5c3e\u3002<\/li>\n<\/ul>\n<h4>2.3 _exit() \u2014\u2014 \u7cfb\u7edf\u8c03\u7528<\/h4>\n<ul>\n<li>\u76f4\u63a5\u7ec8\u6b62\u8fdb\u7a0b&#xff0c;\u4e0d\u5237\u65b0\u7528\u6237\u6001\u7f13\u51b2\u533a&#xff0c;\u4e0d\u505a\u4efb\u4f55\u6e05\u7406\u3002<\/li>\n<li>\u8fd9\u662f\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684&#034;\u539f\u59cb&#034;\u63a5\u53e3\u3002<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260917170835-6aac1e938d393.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><br \/>\n\u8bfe\u5802\u5b9e\u9a8c&#xff08;exit vs _exit \u4e0e\u7f13\u51b2\u533a\u4f4d\u7f6e&#xff09;&#xff1a;<\/li>\n<\/ul>\n<p><span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;hello world&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6ce8\u610f&#xff1a;\u6ca1\u6709 \\\\n<\/span><br \/>\n<span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">23<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>               <span class=\"token comment\">\/\/ \u6216\u6362\u6210 _exit(23);<\/span><\/p>\n<ul>\n<li>\u4f7f\u7528 exit(23)&#xff1a;2 \u79d2\u540e\u80fd\u770b\u5230 \u201chello world\u201d \u8f93\u51fa&#xff0c;\u56e0\u4e3a\u8fdb\u7a0b\u9000\u51fa\u524d C \u5e93\u7f13\u51b2\u533a\u88ab\u5237\u65b0\u3002<\/li>\n<li>\u4f7f\u7528 _exit(23)&#xff1a;2 \u79d2\u540e\u770b\u4e0d\u5230 \u201chello world\u201d&#xff0c;\u56e0\u4e3a C \u5e93\u7528\u6237\u5c42\u7f13\u51b2\u533a\u6ca1\u88ab\u5237\u65b0&#xff0c;\u76f4\u63a5\u7ec8\u6b62\u4e86\u3002<\/li>\n<\/ul>\n<p>\u8001\u5e08\u501f\u6b64\u5f15\u51fa\u91cd\u8981\u4f0f\u7b14&#xff1a;<\/p>\n<p>\u201c\u7f13\u51b2\u533a\u5728\u54ea\u91cc&#xff1f;\u5982\u679c\u7f13\u51b2\u533a\u5728\u64cd\u4f5c\u7cfb\u7edf\u5185\u90e8&#xff0c;\u90a3 exit \u548c _exit \u90fd\u5e94\u8be5\u5237\u65b0\u3002\u4f46\u5b9e\u9a8c\u8bc1\u660e _exit \u4e0d\u5237\u65b0\u3002\u6240\u4ee5\u2014\u2014\u7f13\u51b2\u533a\u4e0d\u5728\u5185\u6838&#xff0c;\u800c\u5728 C \u8bed\u8a00\u7684\u5e93\u7ea7\u522b&#xff08;\u7528\u6237\u5c42&#xff09;\u3002\u201d&#xff08;\u7c7b\u4f3c\u4e8e&#034;\u6211\u6709\u4f60\u6ca1\u6709&#034;\u5c31\u53ef\u4ee5\u5224\u65ad\u80af\u5b9a\u4e0d\u5728\u64cd\u4f5c\u7cfb\u7edf\u5185\u90e8&#xff09;<\/p>\n<p>\u8865\u5145\u77e5\u8bc6\u70b9&#xff1a;\u4e3a\u4ec0\u4e48 C \u8bed\u8a00\u65e7\u4ee3\u7801\u4e2d main \u53ef\u4ee5\u4e0d\u5199 return&#xff1f;<br \/>\n\u5982\u679c main \u58f0\u660e\u4e3a\u8fd4\u56de int \u4f46\u6ca1\u6709\u5199 return&#xff0c;\u7f16\u8bd1\u5668\u9ed8\u8ba4\u5728\u672b\u5c3e\u63d2\u5165 return 0\u3002\u8fd9\u662f\u8bed\u8a00\u5c42\u9762\u7684\u7ea6\u5b9a\u3002\u66f4\u5e95\u5c42\u7684\u539f\u7406\u662f&#xff1a;\u51fd\u6570\u8fd4\u56de\u503c\u901a\u8fc7 \u5bc4\u5b58\u5668&#xff08;\u5982 eax&#xff09; \u4f20\u9012&#xff0c;\u5982\u679c\u4e0d\u5199 return&#xff0c;\u5bc4\u5b58\u5668\u91cc\u53ef\u80fd\u4fdd\u7559\u7740\u9ed8\u8ba4\u503c 0\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u8fdb\u7a0b\u7b49\u5f85&#xff1a;\u672c\u8282\u91cd\u4e2d\u4e4b\u91cd<\/h3>\n<h4>3.1 \u4e3a\u4ec0\u4e48\u8981\u7b49\u5f85&#xff1f;<\/h4>\n<p>\u521b\u5efa\u5b50\u8fdb\u7a0b\u662f\u4e3a\u4e86\u8ba9\u5b83\u529e\u4e8b&#xff0c;\u7236\u8fdb\u7a0b\u5fc5\u987b\u77e5\u9053\u4e24\u4ef6\u4e8b&#xff1a;<\/p>\n<li>\u56de\u6536\u8d44\u6e90&#xff1a;\u5b50\u8fdb\u7a0b\u9000\u51fa\u540e\u82e5\u7236\u8fdb\u7a0b\u4e0d\u56de\u6536&#xff0c;\u4f1a\u53d8\u6210\u50f5\u5c38\u8fdb\u7a0b&#xff08;Zombie&#xff09;\u3002\u50f5\u5c38\u8fdb\u7a0b\u5df2\u7ecf\u6b7b\u4ea1&#xff0c;\u8fde kill -9 \u90fd\u6740\u4e0d\u6389&#xff0c;\u53ea\u80fd\u901a\u8fc7 wait\/waitpid \u56de\u6536&#xff0c;\u5426\u5219\u9020\u6210\u5185\u5b58\u6cc4\u6f0f&#xff08;PCB \u4e00\u76f4\u5360\u7740\u5185\u5b58&#xff09;\u3002<\/li>\n<li>\u83b7\u53d6\u72b6\u6001&#xff1a;\u5b50\u8fdb\u7a0b\u4efb\u52a1\u5b8c\u6210\u5f97\u5982\u4f55&#xff1f;\u7ed3\u679c\u6b63\u786e\u5417&#xff1f;\u51fa\u73b0\u5f02\u5e38\u4e86\u5417&#xff1f;<\/li>\n<p>\u201c\u5728\u751f\u6d3b\u4e2d\u4f60\u53ef\u80fd\u662f\u4e2a\u5185\u5411\u7684\u4eba&#xff0c;\u4f46\u5728\u6280\u672f\u8ba8\u8bba\u4e2d&#xff0c;\u7236\u8fdb\u7a0b\u5fc5\u987b\u4e3b\u52a8\u2019\u95ee\u2019\u5b50\u8fdb\u7a0b&#xff1a;\u2018\u4f60\u4e8b\u513f\u529e\u5f97\u600e\u4e48\u6837\u4e86&#xff1f;\u2019\u201d<\/p>\n<h4>3.2 \u7b49\u5f85\u63a5\u53e3&#xff1a;wait \u4e0e waitpid<\/h4>\n<p><span class=\"token class-name\">pid_t<\/span> <span class=\"token function\">wait<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> <span class=\"token operator\">*<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token class-name\">pid_t<\/span> <span class=\"token function\">waitpid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">pid_t<\/span> pid<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token operator\">*<\/span>status<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> options<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<table>\n<tr>\u63a5\u53e3\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">wait(NULL)<\/td>\n<td align=\"left\">\u6700\u7b80\u5355\u7248\u672c\u3002\u963b\u585e\u7b49\u5f85\u4efb\u610f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u9000\u51fa&#xff0c;\u8fd4\u56de\u5b50\u8fdb\u7a0b PID\u3002\u4e0d\u5173\u5fc3\u9000\u51fa\u4fe1\u606f\u65f6\u4f20 NULL\u3002<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">waitpid(pid, &amp;status, 0)<\/td>\n<td align=\"left\">\u529f\u80fd\u66f4\u5f3a\u5927\u3002- pid &gt; 0&#xff1a;\u7b49\u5f85\u6307\u5b9a PID \u7684\u5b50\u8fdb\u7a0b\u3002- pid &#061; -1&#xff1a;\u7b49\u5f85\u4efb\u610f\u5b50\u8fdb\u7a0b&#xff0c;\u7b49\u4ef7\u4e8e wait()\u3002- status&#xff1a;\u8f93\u51fa\u578b\u53c2\u6570&#xff0c;\u5e26\u56de\u5b50\u8fdb\u7a0b\u9000\u51fa\u72b6\u6001\u3002- options&#xff1a; behavior \u63a7\u5236&#xff0c;\u9ed8\u8ba4 0 \u4ee3\u8868\u963b\u585e\u7b49\u5f85\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8bfe\u5802\u5b9e\u4f8b&#xff08;wait \u56de\u6536\u50f5\u5c38\u8fdb\u7a0b&#xff09;&#xff1a;<\/p>\n<p><span class=\"token class-name\">pid_t<\/span> id <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">fork<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>id <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5b50\u8fdb\u7a0b&#xff1a;\u8dd1 5 \u79d2\u540e\u9000\u51fa<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> cnt <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span>cnt<span class=\"token operator\">&#8212;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5b50\u8fdb\u7a0b: %d, PID: %d, PPID: %d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> cnt<span class=\"token punctuation\">,<\/span> <span class=\"token function\">getpid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">getppid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u7236\u8fdb\u7a0b<\/span><br \/>\n    <span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u5148\u4e0d\u56de\u6536&#xff0c;\u8ba9\u5b50\u8fdb\u7a0b\u53d8\u50f5\u5c38<\/span><br \/>\n    <span class=\"token class-name\">pid_t<\/span> ret <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">wait<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>ret <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u7b49\u5f85\u6210\u529f, \u56de\u6536\u7684\u5b50\u8fdb\u7a0bPID: %d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> ret<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7528\u76d1\u63a7\u811a\u672c ps ajx | grep proc \u89c2\u5bdf&#xff1a;<\/p>\n<li>\u524d 5 \u79d2&#xff1a;\u7236\u5b50\u8fdb\u7a0b\u90fd\u5728\u8fd0\u884c&#xff08;S&#043; \u72b6\u6001&#xff09;\u3002<\/li>\n<li>\u5b50\u8fdb\u7a0b\u9000\u51fa\u540e&#xff1a;\u53d8\u6210 Z&#043;&#xff08;\u50f5\u5c38\u72b6\u6001&#xff09;\u3002<\/li>\n<li>\u7236\u8fdb\u7a0b wait \u6210\u529f\u540e&#xff1a;\u50f5\u5c38\u8fdb\u7a0b\u77ac\u95f4\u6d88\u5931\u3002<\/li>\n<li>\u82e5\u5b50\u8fdb\u7a0b\u6ca1\u9000\u51fa&#xff0c;\u7236\u8fdb\u7a0b\u4f1a\u963b\u585e\u5728 wait \u5904&#xff0c;\u7c7b\u6bd4 scanf \u7b49\u5f85\u952e\u76d8\u8f93\u5165\u3002<\/li>\n<h4>3.3 \u9000\u51fa\u72b6\u6001 status \u7684\u4f4d\u56fe\u89e3\u6790&#xff08;\u6838\u5fc3\u96be\u70b9&#xff09;<\/h4>\n<p>status \u662f\u4e00\u4e2a int&#xff08;32 \u4f4d&#xff09;&#xff0c;\u4f46\u5e76\u975e\u76f4\u63a5\u5b58\u50a8\u9000\u51fa\u7801\u3002\u5b83\u7684\u4f4e 16 \u4f4d\u662f\u4e00\u5f20\u4f4d\u56fe&#xff1a;<\/p>\n<p>\u9ad816\u4f4d           \u4f4e16\u4f4d<br \/>\n&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n| \u672a\u4f7f\u7528 | \u9000\u51fa\u7801 | core | \u4fe1\u53f7\u503c  |<br \/>\n| (16bit)| (8bit) | flag | (7bit) |<br \/>\n&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<\/p>\n<ul>\n<li>\u6b21\u4f4e 8 \u4f4d&#xff08;Bit 8-15&#xff09;&#xff1a;\u5b58\u50a8\u6b63\u5e38\u9000\u51fa\u7801&#xff08;Exit Code&#xff09;\u3002<\/li>\n<li>\u4f4e 7 \u4f4d&#xff08;Bit 0-6&#xff09;&#xff1a;\u5b58\u50a8\u5bfc\u81f4\u8fdb\u7a0b\u7ec8\u6b62\u7684\u4fe1\u53f7\u503c&#xff08;Signal&#xff09;\u3002\u82e5\u4e3a 0&#xff0c;\u8868\u793a\u6b63\u5e38\u9000\u51fa&#xff1b;\u82e5\u975e 0&#xff0c;\u8868\u793a\u5f02\u5e38\u7ec8\u6b62\u3002<\/li>\n<li>\u8001\u5e08\u7279\u522b\u5f3a\u8c03&#xff1a;\u7cfb\u7edf\u6ca1\u6709 0 \u53f7\u4fe1\u53f7&#xff0c;\u6240\u4ee5\u4fe1\u53f7\u4f4d\u4e3a 0 \u5929\u7136\u5c31\u8868\u793a&#034;\u6ca1\u6709\u6536\u5230\u4fe1\u53f7&#034;&#xff0c;\u8fd9\u662f\u7cfb\u7edf\u8bbe\u8ba1\u4e0a\u7684\u4f18\u96c5\u3002<\/li>\n<\/ul>\n<p>\u8bfe\u5802\u5b9e\u4f8b&#xff08;\u624b\u52a8\u4f4d\u64cd\u4f5c\u63d0\u53d6&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span> status<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">waitpid<\/span><span class=\"token punctuation\">(<\/span>id<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>status<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> exit_code <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span>status <span class=\"token operator\">&gt;&gt;<\/span> <span class=\"token number\">8<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&amp;<\/span> <span class=\"token number\">0xFF<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u63d0\u53d6\u9000\u51fa\u7801<\/span><br \/>\n<span class=\"token keyword\">int<\/span> signal   <span class=\"token operator\">&#061;<\/span> status <span class=\"token operator\">&amp;<\/span> <span class=\"token number\">0x7F<\/span><span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u63d0\u53d6\u4fe1\u53f7<\/span><\/p>\n<p>\u4e3a\u4ec0\u4e48\u7528 (status &gt;&gt; 8) &amp; 0xFF&#xff1f;\u56e0\u4e3a\u5f53\u5b50\u8fdb\u7a0b exit(1) \u65f6&#xff0c;status \u91cc 1 \u88ab\u653e\u5728\u4e86\u7b2c 8-15 \u4f4d&#xff0c;\u76f4\u63a5\u6253\u5370 status \u4f1a\u5f97\u5230 256&#xff08;\u5373 1 &lt;&lt; 8&#xff09;&#xff0c;\u8fd9\u5c31\u662f\u5f88\u591a\u540c\u5b66\u56f0\u60d1&#034;\u4e3a\u4ec0\u4e48\u4e0d\u662f 1&#034;\u7684\u539f\u56e0\u3002<\/p>\n<p>\u63a8\u8350\u4f7f\u7528\u5b8f&#xff08;\u4e0d\u6613\u51fa\u9519&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">WIFEXITED<\/span><span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6b63\u5e38\u9000\u51fa&#xff0c;\u9000\u51fa\u7801: %d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">WEXITSTATUS<\/span><span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">WIFSIGNALED<\/span><span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5f02\u5e38\u7ec8\u6b62&#xff0c;\u4fe1\u53f7\u503c: %d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">WTERMSIG<\/span><span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<ul>\n<li>WIFEXITED&#xff1a;\u5224\u65ad\u662f\u5426\u6b63\u5e38\u9000\u51fa&#xff08;\u4fe1\u53f7\u4f4d\u4e3a 0&#xff09;\u3002<\/li>\n<li>WEXITSTATUS&#xff1a;\u63d0\u53d6\u6b21\u4f4e 8 \u4f4d\u7684\u9000\u51fa\u7801\u3002<\/li>\n<li>WIFSIGNALED&#xff1a;\u5224\u65ad\u662f\u5426\u56e0\u4fe1\u53f7\u5f02\u5e38\u7ec8\u6b62\u3002<\/li>\n<li>WTERMSIG&#xff1a;\u63d0\u53d6\u7ec8\u6b62\u4fe1\u53f7\u503c\u3002<\/li>\n<\/ul>\n<p>\u8865\u5145\u77e5\u8bc6\u70b9&#xff1a;wait\/waitpid \u4f55\u65f6\u5931\u8d25&#xff1f;<\/p>\n<ul>\n<li>wait \u5931\u8d25&#xff1a;\u8c03\u7528\u8fdb\u7a0b\u6ca1\u6709\u5b50\u8fdb\u7a0b\u65f6\u8fd4\u56de -1\u3002<\/li>\n<li>waitpid \u5931\u8d25&#xff1a;\u4f20\u5165\u7684 pid \u4e0d\u5b58\u5728&#xff08;\u6bd4\u5982\u968f\u4fbf\u4f20\u4e00\u4e2a 1&#xff09;&#xff0c;\u6216\u6ca1\u6709\u6743\u9650\u7b49\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u56db\u3001\u963b\u585e\u7b49\u5f85 vs \u975e\u963b\u585e\u7b49\u5f85<\/h3>\n<p>\u7406\u89e3\u8fd9\u4e24\u79cd\u6a21\u5f0f&#xff0c;\u662f\u7406\u89e3&#034;\u9ad8\u6027\u80fd\u5e76\u53d1\u63a7\u5236&#034;\u7684\u7b2c\u4e00\u6b65\u3002<\/p>\n<h4>4.1 \u963b\u585e\u7b49\u5f85&#xff08;Blocking&#xff09;<\/h4>\n<p>\u9ed8\u8ba4\u884c\u4e3a&#xff08;options &#061; 0&#xff09;\u3002\u5982\u679c\u5b50\u8fdb\u7a0b\u672a\u9000\u51fa&#xff0c;\u7236\u8fdb\u7a0b\u5728 wait\/waitpid \u5904\u6302\u8d77&#xff0c;\u76f4\u5230\u5b50\u8fdb\u7a0b\u7ed3\u675f\u624d\u8fd4\u56de\u3002<\/p>\n<p>\u8bfe\u5802\u7c7b\u6bd4&#xff08;\u963b\u585e\u5f0f\u7535\u8bdd&#xff09;&#xff1a;<\/p>\n<p>\u5f20\u4e09\u627e\u5b66\u9738\u674e\u56db\u590d\u4e60\u3002\u674e\u56db\u8bf4&#xff1a;\u201c\u6211\u5728\u697c\u4e0a\u590d\u4e60\u7f51\u7edc&#xff0c;\u8fd8\u5f97\u7b49 10 \u5206\u949f\u3002\u201d \u5f20\u4e09\u8bf4&#xff1a;\u201c\u6ca1\u5173\u7cfb&#xff0c;\u6211\u4e0d\u6302\u7535\u8bdd&#xff0c;\u6211\u5c31\u62ff\u7740\u624b\u673a\u7b49&#xff0c;\u4f60\u597d\u4e86\u76f4\u63a5\u4e0b\u697c\u3002\u201d<br \/>\n\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u5f20\u4e09\u4ec0\u4e48\u4e8b\u90fd\u5e72\u4e0d\u4e86&#xff0c;\u5361\u5728&#034;\u7b49\u5f85&#034;\u8fd9\u4e2a\u52a8\u4f5c\u4e0a\u2014\u2014\u8fd9\u5c31\u662f\u963b\u585e\u3002\u6211\u4eec\u4e4b\u524d\u7528\u7684 scanf\u3001sleep&#xff0c;\u4ee5\u53ca\u9ed8\u8ba4\u7684 waitpid&#xff0c;\u90fd\u662f\u963b\u585e\u8c03\u7528\u3002<\/p>\n<h4>4.2 \u975e\u963b\u585e\u7b49\u5f85&#xff08;Non-blocking&#xff09;<\/h4>\n<p>\u8bbe\u7f6e\u9009\u9879 WNOHANG&#xff08;Wait No Hang&#xff0c;\u610f\u4e3a&#034;\u7b49\u5f85\u4f46\u4e0d\u8981\u8ba9\u7cfb\u7edf\u592f\u4f4f&#034;&#xff09;\u3002\u5982\u679c\u5b50\u8fdb\u7a0b\u672a\u9000\u51fa&#xff0c;waitpid \u7acb\u5373\u8fd4\u56de 0&#xff0c;\u7236\u8fdb\u7a0b\u4e0d\u4f1a\u88ab\u6302\u8d77&#xff0c;\u53ef\u4ee5\u53bb\u505a\u522b\u7684\u4e8b\u3002<\/p>\n<p>\u8bfe\u5802\u7c7b\u6bd4&#xff08;\u975e\u963b\u585e\u8f6e\u8be2\u7535\u8bdd&#xff09;&#xff1a;<\/p>\n<p>\u5f20\u4e09\u7ed9\u674e\u56db\u6253\u7535\u8bdd&#xff1a;\u201c\u4f60\u597d\u4e86\u5417&#xff1f;\u201d \u674e\u56db&#xff1a;\u201c\u8fd8\u6ca1\u3002\u201d \u5f20\u4e09\u6302\u65ad\u7535\u8bdd\u3002<br \/>\n\u8fc7\u4e00\u4f1a\u513f&#xff0c;\u5f20\u4e09\u518d\u6253&#xff1a;\u201c\u597d\u4e86\u5417&#xff1f;\u201d \u674e\u56db&#xff1a;\u201c\u9a6c\u4e0a\u3002\u201d \u5f20\u4e09\u518d\u6302\u65ad\u3002<br \/>\n\u53cd\u590d\u51e0\u6b21\u540e\u674e\u56db\u4e0b\u697c\u4e86\u3002\u5728\u7b49\u5f85\u95f4\u9699&#xff0c;\u5f20\u4e09\u53ef\u4ee5\u770b\u4e66\u3001\u73a9\u624b\u673a\u3001\u53d1\u5446\u2014\u2014\u8fd9\u5c31\u89e3\u653e\u4e86\u7236\u8fdb\u7a0b\u7684\u751f\u4ea7\u529b\u3002<\/p>\n<h4>4.3 \u975e\u963b\u585e\u8f6e\u8be2\u4ee3\u7801\u5b9e\u73b0<\/h4>\n<p><span class=\"token comment\">\/\/ \u975e\u963b\u585e\u8f6e\u8be2&#xff1a;\u7236\u8fdb\u7a0b\u7b49\u5f85\u5b50\u8fdb\u7a0b\u671f\u95f4&#xff0c;\u53ef\u4ee5\u6267\u884c\u5176\u4ed6\u4efb\u52a1<\/span><br \/>\n<span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">pid_t<\/span> ret <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">waitpid<\/span><span class=\"token punctuation\">(<\/span>id<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>status<span class=\"token punctuation\">,<\/span> WNOHANG<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>ret <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5b50\u8fdb\u7a0b\u7ed3\u675f&#xff0c;\u56de\u6536\u6210\u529f<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u7b49\u5f85\u6210\u529f, \u9000\u51fa\u7801: %d\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">WEXITSTATUS<\/span><span class=\"token punctuation\">(<\/span>status<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">break<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>ret <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u672c\u8f6e\u8c03\u7528\u7ed3\u675f&#xff0c;\u4f46\u5b50\u8fdb\u7a0b\u8fd8\u6ca1\u9000\u51fa<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u672c\u8f6e\u8c03\u7528\u7ed3\u675f&#xff0c;\u5b50\u8fdb\u7a0b\u672a\u9000\u51fa&#xff0c;\u7236\u8fdb\u7a0b\u53ef\u4ee5\u505a\u5176\u4ed6\u4e8b&#8230;\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6162\u4e00\u70b9\u8f6e\u8be2&#xff0c;\u4e0d\u8981 CPU \u7a7a\u8f6c<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ ret &lt; 0&#xff0c;\u7b49\u5f85\u5931\u8d25<\/span><br \/>\n        <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u7b49\u5f85\u5931\u8d25\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">break<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd4\u56de\u503c\u542b\u4e49\u56de\u987e&#xff1a;<\/p>\n<ul>\n<li>ret &gt; 0&#xff1a;\u6210\u529f\u56de\u6536\u5b50\u8fdb\u7a0b&#xff0c;ret \u5373\u5b50\u8fdb\u7a0b PID\u3002<\/li>\n<li>ret &#061;&#061; 0&#xff1a;\u975e\u963b\u585e\u6a21\u5f0f\u4e0b&#xff0c;\u5b50\u8fdb\u7a0b\u5c1a\u672a\u9000\u51fa&#xff0c;\u9700\u8981\u4e0b\u6b21\u518d\u8f6e\u8be2\u3002<\/li>\n<li>ret &lt; 0&#xff1a;\u7b49\u5f85\u5931\u8d25&#xff08;\u5982\u4f20\u9519 PID&#xff09;\u3002<\/li>\n<\/ul>\n<h4>4.4 \u975e\u963b\u585e\u7684\u5b9e\u9645\u5e94\u7528&#xff1a;\u56de\u8c03\u4e0e\u4efb\u52a1\u6ce8\u518c<\/h4>\n<p>\u8001\u5e08\u73b0\u573a\u5199\u4e86\u4e00\u4e2a\u7cbe\u5999\u7684\u4ee3\u7801\u6846\u67b6&#xff0c;\u5c55\u793a\u975e\u963b\u585e\u7b49\u5f85\u5982\u4f55\u8ba9\u7236\u8fdb\u7a0b&#034;\u5fd9\u91cc\u5077\u95f2&#034;&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name\">NUM<\/span> <span class=\"token expression\"><span class=\"token number\">5<\/span><\/span><\/span><\/p>\n<p><span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span><span class=\"token class-name\">func_t<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u51fd\u6570\u6307\u9488\u7c7b\u578b<\/span><br \/>\n<span class=\"token comment\">\/\/ \u7b2c\u4e00\u6b65&#xff1a;\u5148\u6b63\u5e38\u58f0\u660e\u4e00\u4e2a\u51fd\u6570\u6307\u9488<\/span><br \/>\n<span class=\"token comment\">\/\/ void (*func_ptr)();   <\/span><br \/>\n<span class=\"token comment\">\/\/ func_ptr \u662f&#034;\u6307\u5411\u8fd4\u56devoid\u3001\u65e0\u53c2\u51fd\u6570\u7684\u6307\u9488&#034;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u7b2c\u4e8c\u6b65&#xff1a;\u5728\u524d\u9762\u52a0 typedef<\/span><br \/>\n<span class=\"token comment\">\/\/ typedef void (*func_t)();   <\/span><br \/>\n<span class=\"token comment\">\/\/ func_t \u5c31\u53d8\u6210\u4e86&#034;\u51fd\u6570\u6307\u9488\u7c7b\u578b&#034;\u7684\u540d\u5b57<\/span><\/p>\n<p><span class=\"token class-name\">func_t<\/span> handlers<span class=\"token punctuation\">[<\/span>NUM<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u4efb\u52a1\u8868<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u6ce8\u518c\u4efb\u52a1&#xff1a;\u4e0b\u8f7d\u3001\u5237\u65b0\u3001\u65e5\u5fd7\u8bb0\u5f55&#8230;<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">regist_handler<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">func_t<\/span> f<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> NUM<span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>handlers<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            handlers<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> f<span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token keyword\">return<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">download<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token punctuation\">{<\/span> <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6267\u884c\u4e0b\u8f7d\u4efb\u52a1&#8230;\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">flush<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>     <span class=\"token punctuation\">{<\/span> <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6267\u884c\u5237\u65b0\u4efb\u52a1&#8230;\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">log_task<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token punctuation\">{<\/span> <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6267\u884c\u65e5\u5fd7\u8bb0\u5f55&#8230;\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5728\u7236\u8fdb\u7a0b\u7684\u975e\u963b\u585e\u8f6e\u8be2\u95f4\u9699\u6267\u884c&#xff1a;<\/span><br \/>\n<span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> handlers<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">!&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    handlers<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6838\u5fc3\u601d\u60f3&#xff1a;WNOHANG \u8ba9\u7236\u8fdb\u7a0b\u4ece&#034;\u5e72\u7b49&#034;\u53d8\u4e3a&#034;\u5468\u671f\u6027\u5730\u770b\u4e00\u773c&#034;&#xff0c;\u5728\u7b49\u5f85\u95f4\u9699\u6267\u884c\u5fc3\u8df3\u68c0\u6d4b\u3001\u65e5\u5fd7\u843d\u76d8\u3001\u6570\u636e\u5237\u65b0\u7b49\u4e1a\u52a1&#xff0c;\u63d0\u9ad8 CPU \u5229\u7528\u7387\u548c\u7cfb\u7edf\u5e76\u53d1\u5904\u7406\u80fd\u529b\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u8fdb\u7a0b\u7a0b\u5e8f\u66ff\u6362&#xff08;exec \u521d\u63a2&#xff09;<\/h3>\n<h4>5.1 \u4ec0\u4e48\u662f\u7a0b\u5e8f\u66ff\u6362&#xff1f;<\/h4>\n<p>\u7a0b\u5e8f\u66ff\u6362\u662f\u6307&#xff1a;\u7528\u65b0\u7a0b\u5e8f\u7684\u4ee3\u7801\u6bb5\u548c\u6570\u636e\u6bb5&#xff0c;\u66ff\u6362\u5f53\u524d\u8fdb\u7a0b\u7684\u4ee3\u7801\u6bb5\u548c\u6570\u636e\u6bb5\u3002\u4f46\u539f\u6709\u7684\u5185\u6838\u6570\u636e\u7ed3\u6784&#xff08;PCB&#xff09;\u3001\u5730\u5740\u7a7a\u95f4\u6846\u67b6\u3001PID \u7b49\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<p>\u8fdb\u7a0b &#061; \u5185\u6838\u6570\u636e\u7ed3\u6784&#xff08;PCB&#xff09;&#043; \u4ee3\u7801\u548c\u6570\u636e\u3002\u7a0b\u5e8f\u66ff\u6362\u53ea\u52a8&#034;\u4ee3\u7801\u548c\u6570\u636e&#034;&#xff0c;\u4e0d\u52a8 PCB\u3002<\/p>\n<p>\u8fd9\u6b63\u662f Shell&#xff08;bash&#xff09;\u80fd\u6267\u884c\u5404\u79cd\u547d\u4ee4\u7684\u5e95\u5c42\u539f\u7406&#xff1a;<\/p>\n<li>bash fork \u521b\u5efa\u5b50\u8fdb\u7a0b&#xff1b;<\/li>\n<li>\u5b50\u8fdb\u7a0b\u8c03\u7528 exec \u7cfb\u5217\u51fd\u6570&#xff0c;\u52a0\u8f7d ls\u3001top \u7b49\u547d\u4ee4\u7a0b\u5e8f&#xff1b;<\/li>\n<li>bash waitpid \u7b49\u5f85\u5b50\u8fdb\u7a0b\u7ed3\u675f&#xff0c;\u83b7\u53d6\u9000\u51fa\u7801&#xff1b;<\/li>\n<li>\u5b50\u8fdb\u7a0b\u6267\u884c\u5b8c&#xff0c;ls \u7684\u4ee3\u7801\u66ff\u6362\u6389\u5b50\u8fdb\u7a0b\u539f\u6765\u7684\u4ee3\u7801&#xff0c;bash \u672c\u8eab\u4e0d\u53d7\u5f71\u54cd\u3002<\/li>\n<h4>5.2 execl \u51fd\u6570\u521d\u4f53\u9a8c<\/h4>\n<p>\u7cfb\u7edf\u63d0\u4f9b\u4e86 7 \u4e2a exec \u65cf\u51fd\u6570&#xff0c;\u8bfe\u5802\u6311\u9009 execl \u5feb\u901f\u89c1\u6548&#xff1a;<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6211\u7684\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c\u4e86\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u7b2c\u4e00\u4e2a\u53c2\u6570&#xff1a;\u7edd\u5bf9\u8def\u5f84&#xff1b;\u540e\u7eed&#xff1a;\u547d\u4ee4\u884c\u53c2\u6570\u5217\u8868&#xff1b;\u6700\u540e\u5fc5\u987b\u4ee5 NULL \u7ed3\u5c3e<\/span><br \/>\n    <span class=\"token function\">execl<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/usr\/bin\/ls&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;ls&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;-a&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;-l&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6211\u7684\u7a0b\u5e8f\u8fd0\u884c\u5b8c\u6bd5\u4e86\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u5982\u679c\u66ff\u6362\u6210\u529f&#xff0c;\u8fd9\u884c**\u4e0d\u4f1a\u6267\u884c**<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd0\u884c\u73b0\u8c61&#xff1a;\u7ec8\u7aef\u6253\u5370\u51fa\u4e86 ls -a -l \u7684\u7ed3\u679c&#xff0c;\u4f46\u6ca1\u6709\u770b\u5230 \u201c\u6211\u7684\u7a0b\u5e8f\u8fd0\u884c\u5b8c\u6bd5\u4e86\u201d\u3002<\/p>\n<p>execl \u7684\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\u6210\u529f\u4e0d\u8fd4\u56de&#xff1a;\u4e00\u65e6\u66ff\u6362\u6210\u529f&#xff0c;\u539f\u8fdb\u7a0b\u540e\u7eed\u4ee3\u7801\u88ab\u65b0\u7a0b\u5e8f\u8986\u76d6&#xff0c;\u539f main \u540e\u7eed\u7684 printf \u4e0d\u53ef\u80fd\u518d\u6267\u884c\u3002<\/li>\n<li>\u5931\u8d25\u8fd4\u56de -1&#xff1a;\u5982\u679c\u8def\u5f84\u9519\u8bef\u6216\u6743\u9650\u4e0d\u591f&#xff0c;\u539f\u8fdb\u7a0b\u7ee7\u7eed\u6267\u884c\u540e\u7eed\u4ee3\u7801\u3002<\/li>\n<li>\u4e0d\u521b\u5efa\u65b0\u8fdb\u7a0b&#xff1a;PID \u6ca1\u6709\u6539\u53d8&#xff0c;\u53ea\u662f&#034;\u7075\u9b42&#034;&#xff08;\u4ee3\u7801\u6570\u636e&#xff09;\u6362\u4e86&#xff0c;\u201c\u8eaf\u58f3\u201d&#xff08;PCB\u3001PID&#xff09;\u8fd8\u5728\u3002<\/li>\n<\/ul>\n<p>\u8bfe\u5802\u5b9e\u4f8b&#xff08;\u6267\u884c top&#xff09;&#xff1a;<br \/>\n\u628a execl \u7684\u53c2\u6570\u6362\u6210 \/usr\/bin\/top&#xff0c;\u8fd0\u884c\u540e\u5f53\u524d\u8fdb\u7a0b\u53d8\u6210\u4e86 top \u547d\u4ee4&#xff0c;\u6309 q \u9000\u51fa\u540e\u8fdb\u7a0b\u624d\u7ed3\u675f\u3002<\/p>\n<hr \/>\n<h3>\u516d\u3001\u8bfe\u7a0b\u603b\u7ed3\u4e0e\u77e5\u8bc6\u56fe\u8c31<\/h3>\n<h4>6.1 \u6838\u5fc3\u77e5\u8bc6\u70b9\u56de\u987e<\/h4>\n<li>\u8fdb\u7a0b\u7ec8\u6b62&#xff1a;\u4e09\u79cd\u573a\u666f&#xff08;\u7ed3\u679c\u5bf9\/\u7ed3\u679c\u9519\/\u5f02\u5e38&#xff09;\u3002\u9000\u51fa\u7801 0 \u4ee3\u8868\u6210\u529f&#xff0c;\u975e 0 \u4ee3\u8868\u4e0d\u540c\u9519\u8bef\u539f\u56e0&#xff0c;\u5f02\u5e38\u65f6\u9000\u51fa\u7801\u65e0\u610f\u4e49\u3002<\/li>\n<li>\u50f5\u5c38\u8fdb\u7a0b&#xff1a;\u5b50\u8fdb\u7a0b\u9000\u51fa\u800c\u7236\u8fdb\u7a0b\u672a wait&#xff0c;PCB \u6ede\u7559\u3002\u65e0\u6cd5 kill -9&#xff0c;\u5fc5\u987b\u901a\u8fc7\u7b49\u5f85\u56de\u6536\u3002<\/li>\n<li>status \u4f4d\u56fe&#xff1a;\u4f4e 16 \u4f4d\u4e2d&#xff0c;\u6b21\u4f4e 8 \u4f4d\u5b58\u9000\u51fa\u7801&#xff0c;\u4f4e 7 \u4f4d\u5b58\u4fe1\u53f7\u503c\u3002\u63a8\u8350\u7528 WIFEXITED\u3001WEXITSTATUS \u7b49\u5b8f\u89e3\u6790\u3002<\/li>\n<li>\u963b\u585e vs \u975e\u963b\u585e&#xff1a;\u963b\u585e\u8ba9\u7236\u8fdb\u7a0b\u6302\u8d77&#xff1b;WNOHANG \u8ba9\u7236\u8fdb\u7a0b\u8f6e\u8be2&#xff0c;\u53ef\u517c\u987e\u5176\u4ed6\u4e1a\u52a1\u3002<\/li>\n<li>\u7a0b\u5e8f\u66ff\u6362&#xff1a;exec \u7cfb\u5217\u66ff\u6362\u8fdb\u7a0b\u7684\u4ee3\u7801\u548c\u6570\u636e&#xff08;\u4e0d\u521b\u5efa\u65b0\u8fdb\u7a0b&#xff09;&#xff0c;\u662f Shell \u6267\u884c\u547d\u4ee4\u7684\u57fa\u77f3\u30025. \u7a0b\u5e8f\u66ff\u6362&#xff1a;exec \u7cfb\u5217\u66ff\u6362\u8fdb\u7a0b\u7684\u4ee3\u7801\u548c\u6570\u636e&#xff08;\u4e0d\u521b\u5efa\u65b0\u8fdb\u7a0b&#xff09;&#xff0c;\u662f Shell \u6267\u884c\u547d\u4ee4\u7684\u57fa\u77f3\u3002<\/li>\n<h4>6.2 \u8fdb\u7a0b\u7b49\u5f85\u5c0f\u7ed3<\/h4>\n<p>\u628a\u8fdb\u7a0b\u7b49\u5f85\u8fd9\u4e00\u6574\u5757\u5185\u5bb9\u4e32\u8d77\u6765&#xff0c;\u5176\u5b9e\u5c31\u56de\u7b54\u4e86\u4e09\u4ef6\u4e8b&#xff1a;\u4e3a\u4ec0\u4e48\u8981\u7b49\u3001\u600e\u4e48\u7b49\u3001\u7b49\u5230\u4e86\u4ec0\u4e48\u3002<\/p>\n<p>1. \u4e3a\u4ec0\u4e48\u8981\u7b49&#xff1f;<\/p>\n<ul>\n<li>\u56de\u6536\u8d44\u6e90&#xff1a;\u5b50\u8fdb\u7a0b\u9000\u51fa\u540e\u4e0d\u56de\u6536\u4f1a\u53d8\u6210\u50f5\u5c38\u8fdb\u7a0b&#xff0c;PCB \u4e00\u76f4\u5360\u7740\u5185\u5b58&#xff0c;\u8fde kill -9 \u90fd\u6740\u4e0d\u6389\u3002<\/li>\n<li>\u83b7\u53d6\u72b6\u6001&#xff1a;\u7236\u8fdb\u7a0b\u9700\u8981\u77e5\u9053\u5b50\u8fdb\u7a0b\u4efb\u52a1\u529e\u5f97\u600e\u4e48\u6837\u2014\u2014\u7ed3\u679c\u6b63\u786e\u5417&#xff1f;\u5f02\u5e38\u4e86\u5417&#xff1f;<\/li>\n<\/ul>\n<p>2. \u600e\u4e48\u7b49&#xff1f;\u4e24\u4e2a\u63a5\u53e3\u3001\u4e24\u79cd\u6a21\u5f0f<\/p>\n<ul>\n<li>\u63a5\u53e3&#xff1a;wait&#xff08;\u7b49\u4efb\u610f\u4e00\u4e2a\u5b50\u8fdb\u7a0b&#xff09;\u4e0e waitpid&#xff08;\u53ef\u6307\u5b9a PID\u3001\u53ef\u4f20 options&#xff09;\u3002<\/li>\n<li>\u6a21\u5f0f&#xff1a;options &#061; 0 \u662f\u963b\u585e\u7b49\u5f85&#xff0c;\u7236\u8fdb\u7a0b\u6302\u8d77\u5e72\u7b49&#xff1b;options &#061; WNOHANG \u662f\u975e\u963b\u585e\u7b49\u5f85&#xff0c;\u5b50\u8fdb\u7a0b\u6ca1\u9000\u51fa\u5c31\u7acb\u5373\u8fd4\u56de 0&#xff0c;\u7236\u8fdb\u7a0b\u53ef\u4ee5\u8f6e\u8be2\u3001\u5fd9\u91cc\u5077\u95f2\u3002<\/li>\n<\/ul>\n<p>3. \u7b49\u5230\u4e86\u4ec0\u4e48&#xff1f;status \u4f4d\u56fe<\/p>\n<ul>\n<li>status \u4e0d\u662f\u76f4\u63a5\u5b58\u9000\u51fa\u7801&#xff0c;\u4f4e 16 \u4f4d\u662f\u4e00\u5f20\u4f4d\u56fe&#xff1a;\u6b21\u4f4e 8 \u4f4d\u5b58\u9000\u51fa\u7801&#xff0c;\u4f4e 7 \u4f4d\u5b58\u4fe1\u53f7\u503c\u3002<\/li>\n<li>\u624b\u52a8\u89e3\u6790\u7528 (status &gt;&gt; 8) &amp; 0xFF \u53d6\u9000\u51fa\u7801\u3001status &amp; 0x7F \u53d6\u4fe1\u53f7&#xff1b;\u66f4\u63a8\u8350\u7528 WIFEXITED\u3001WEXITSTATUS\u3001WIFSIGNALED\u3001WTERMSIG \u8fd9\u4e9b\u5b8f&#xff0c;\u4e0d\u6613\u51fa\u9519\u3002<\/li>\n<\/ul>\n<p>\u4e00\u53e5\u8bdd\u603b\u7ed3&#xff1a;\u8fdb\u7a0b\u7b49\u5f85 &#061; \u7236\u8fdb\u7a0b\u901a\u8fc7 wait\/waitpid \u56de\u6536\u5b50\u8fdb\u7a0b\u8d44\u6e90\u3001\u8bfb\u53d6\u5176\u9000\u51fa\u72b6\u6001&#xff1b;\u963b\u585e\u8ba9\u7236\u8fdb\u7a0b\u6302\u8d77&#xff0c;WNOHANG \u8ba9\u7236\u8fdb\u7a0b\u8f6e\u8be2&#xff0c;\u4ece\u800c\u5728\u7b49\u5f85\u95f4\u9699\u517c\u987e\u5176\u4ed6\u4e1a\u52a1\u3002\u8fd9\u6b63\u662f Shell \u80fd\u7a33\u5b9a\u6267\u884c\u547d\u4ee4\u3001\u7cfb\u7edf\u80fd\u9ad8\u6548\u56de\u6536\u8d44\u6e90\u7684\u5e95\u5c42\u4fdd\u969c\u3002<\/p>\n<hr \/>\n<p>\u601d\u8003\u9898&#xff1a;\u65e2\u7136\u5b50\u8fdb\u7a0b\u9000\u51fa\u7684\u4fe1\u606f\u5199\u5728 PCB \u91cc&#xff0c;\u800c PCB \u662f\u5185\u6838\u6570\u636e\u7ed3\u6784&#xff0c;\u80fd\u5426\u4e0d\u901a\u8fc7 waitpid&#xff0c;\u76f4\u63a5\u7528\u6307\u9488\u8bbf\u95ee\u5185\u6838\u5185\u5b58\u62ff\u5230 exit_code&#xff1f;\u4e3a\u4ec0\u4e48&#xff1f;<br \/>\n&#xff08;\u63d0\u793a&#xff1a;\u4ece&#034;\u64cd\u4f5c\u7cfb\u7edf\u662f\u8d44\u6e90\u7ba1\u7406\u8005&#034;\u3001\u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\u9694\u79bb\u7684\u89d2\u5ea6\u601d\u8003\u3002&#xff09;<\/p>\n<p>\u601d\u8003\u9898\u89e3\u7b54&#xff1a;<\/p>\n<p>\u4e0d\u80fd\u3002 \u6838\u5fc3\u539f\u56e0\u5728\u4e8e\u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\u7684\u9694\u79bb&#xff0c;\u4ee5\u53ca\u64cd\u4f5c\u7cfb\u7edf\u4f5c\u4e3a\u8d44\u6e90\u7ba1\u7406\u8005\u7684\u7edd\u5bf9\u6743\u5a01\u3002<\/p>\n<p>1. \u5730\u5740\u7a7a\u95f4\u9694\u79bb&#xff08;\u865a\u62df\u5185\u5b58\u673a\u5236&#xff09;<\/p>\n<ul>\n<li>\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u62e5\u6709\u72ec\u7acb\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4&#xff0c;\u901a\u8fc7\u9875\u8868\u6620\u5c04\u5230\u7269\u7406\u5185\u5b58\u3002<\/li>\n<li>\u7528\u6237\u6001\u7a0b\u5e8f\u80fd\u8bbf\u95ee\u7684\u5730\u5740\u8303\u56f4&#xff0c;\u88ab\u9650\u5236\u5728\u7528\u6237\u7a7a\u95f4&#xff08;\u5982 0x00000000 ~ 0x7FFFFFFF \u9644\u8fd1&#xff09;\u3002<\/li>\n<li>\u5185\u6838\u6240\u5728\u7684\u5185\u6838\u7a7a\u95f4&#xff08;\u9ad8\u5730\u5740\u533a\u57df&#xff09;\u5728\u9875\u8868\u4e2d\u88ab\u6807\u8bb0\u4e3a\u7279\u6743\u7ea7\u8bbf\u95ee&#xff0c;\u7528\u6237\u6001\u4ee3\u7801\u4e00\u65e6\u8bbf\u95ee&#xff0c;CPU \u4f1a\u89e6\u53d1\u7f3a\u9875\u5f02\u5e38\/\u6bb5\u9519\u8bef&#xff0c;\u8fdb\u7a0b\u76f4\u63a5\u88ab\u6740\u6b7b\u3002<\/li>\n<\/ul>\n<p>2. \u7279\u6743\u7ea7\u4fdd\u62a4&#xff08;CPU \u7684 ring 0 \/ ring 3&#xff09;<\/p>\n<ul>\n<li>\u5185\u6838\u8fd0\u884c\u5728 CPU \u7684\u6700\u9ad8\u7279\u6743\u7ea7&#xff08;ring 0&#xff09;&#xff0c;\u7528\u6237\u8fdb\u7a0b\u8fd0\u884c\u5728\u6700\u4f4e\u7279\u6743\u7ea7&#xff08;ring 3&#xff09;\u3002<\/li>\n<li>\u5373\u4fbf\u4f60\u62ff\u5230\u4e86\u5185\u6838\u7a7a\u95f4\u7684\u5730\u5740&#xff0c;CPU \u786c\u4ef6\u4e5f\u4f1a\u5728\u6307\u4ee4\u5c42\u9762\u62e6\u622a\u8fd9\u6b21\u8bbf\u95ee&#xff0c;\u6839\u672c\u8f6e\u4e0d\u5230&#034;\u8bfb\u6570\u636e&#034;\u8fd9\u4e00\u6b65\u3002<\/li>\n<\/ul>\n<p>3. \u64cd\u4f5c\u7cfb\u7edf\u662f\u8d44\u6e90\u7ba1\u7406\u8005<\/p>\n<ul>\n<li>PCB&#xff08;task_struct&#xff09;\u662f\u5185\u6838\u6570\u636e\u7ed3\u6784&#xff0c;\u5c5e\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684&#034;\u79c1\u6709\u8d22\u4ea7&#034;&#xff0c;\u4e0d\u5411\u7528\u6237\u8fdb\u7a0b\u5f00\u653e\u3002<\/li>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b wait\/waitpid \u8fd9\u7c7b\u7cfb\u7edf\u8c03\u7528\u4f5c\u4e3a\u552f\u4e00\u5408\u6cd5\u7684&#034;\u7a97\u53e3&#034;&#xff0c;\u8ba9\u7236\u8fdb\u7a0b\u901a\u8fc7\u5185\u6838\u4e3b\u52a8\u8f6c\u4ea4\u5b50\u8fdb\u7a0b\u7684\u9000\u51fa\u4fe1\u606f\u3002<\/li>\n<li>\u8fd9\u5c31\u50cf\u94f6\u884c\u7684\u91d1\u5e93&#xff1a;\u4f60\u53ef\u4ee5\u901a\u8fc7\u67dc\u53f0&#xff08;\u7cfb\u7edf\u8c03\u7528&#xff09;\u67e5\u8be2\u4f59\u989d&#xff0c;\u4f46\u7edd\u4e0d\u80fd\u81ea\u5df1\u7ffb\u5899\u8fdb\u53bb\u6570\u94b1\u3002<\/li>\n<\/ul>\n<p>4. \u5373\u4fbf\u7ed5\u8fc7&#xff0c;\u4e5f\u62ff\u4e0d\u5230\u6b63\u786e\u6570\u636e<\/p>\n<ul>\n<li>\u5c31\u7b97\u4f60\u901a\u8fc7\u67d0\u79cd\u6f0f\u6d1e\u8bfb\u5230\u4e86\u67d0\u4e2a\u5730\u5740&#xff0c;\u7531\u4e8e\u5730\u5740\u7a7a\u95f4\u968f\u673a\u5316&#xff08;ASLR&#xff09;\u3001\u9875\u8868\u6620\u5c04\u7684\u4e0d\u786e\u5b9a\u6027&#xff0c;\u4f60\u6839\u672c\u65e0\u6cd5\u786e\u5b9a PCB \u5230\u5e95\u5728\u7269\u7406\u5185\u5b58\u7684\u54ea\u4e2a\u4f4d\u7f6e\u3002<\/li>\n<li>\u800c\u4e14\u5185\u6838\u53ef\u80fd\u968f\u65f6\u8c03\u5ea6\u3001\u8fc1\u79fb\u8fdb\u7a0b&#xff0c;\u4f60\u8bfb\u5230\u7684&#034;PCB&#034;\u5f88\u53ef\u80fd\u65e9\u5df2\u4e0d\u662f\u76ee\u6807\u8fdb\u7a0b\u7684\u4e86\u3002<\/li>\n<\/ul>\n<p>\u4e00\u53e5\u8bdd\u603b\u7ed3&#xff1a;\u7528\u6237\u6001\u8fdb\u7a0b\u65e0\u6cd5\u76f4\u63a5\u8bbf\u95ee\u5185\u6838\u5185\u5b58&#xff0c;\u8fd9\u662f CPU \u786c\u4ef6\u3001\u64cd\u4f5c\u7cfb\u7edf\u8bbe\u8ba1\u5171\u540c\u4fdd\u8bc1\u7684\u5b89\u5168\u8fb9\u754c\u3002wait\/waitpid \u7cfb\u7edf\u8c03\u7528&#xff0c;\u5c31\u662f\u64cd\u4f5c\u7cfb\u7edf\u4e3a\u7236\u8fdb\u7a0b&#034;\u4ee3\u6536&#034;\u5b50\u8fdb\u7a0b\u9000\u51fa\u4fe1\u606f\u7684\u552f\u4e00\u5408\u6cd5\u901a\u9053\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u8fdb\u7a0b\u63a7\u5236\u4e09\u90e8\u66f2&#xff1a;\u7ec8\u6b62\u3001\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u6587\u7ae0\u5b9a\u4f4d&#xff1a;\u8fdb\u7a0b\u63a7\u5236\u662f\u7406\u89e3\u64cd\u4f5c\u7cfb\u7edf\\&#8221;\u5982\u4f55\u7ba1\u7406\u8fd0\u884c\u4e2d\u7684\u7a0b\u5e8f\\&#8221;\u7684\u6838\u5fc3\u7ae0\u8282\u3002\u672c\u6587\u4f9d\u636e\u8bfe\u5802\u5b9e\u5f55\u6574\u7406&#xff0c;\u8986\u76d6\u8fdb\u7a0b\u7ec8\u6b62\u7684\u9000\u51fa\u7801\u8bed\u4e49\u3001wait\/waitpid\u50f5\u5c38\u8fdb\u7a0b\u56de\u6536\u3001status\u4f4d\u56fe\u89e3\u6790\u3001\u963b\u585e\/\u975e\u963b\u585e\u7b49\u5f85\u7684\u672c\u8d28\u533a\u522b&#xff0c;\u4ee5\u53caexec\u7a0b\u5e8f\u66ff\u6362\u7684\u521d\u6b65\u539f\u7406\u3002<br \/>\n\u672c\u7ae0\u91cd\u70b9&#xff1a;\u8fdb\u7a0b\u7b49\u5f85\u3002\u7406\u89e3\\&#8221;\u4e3a\u4ec0\u4e48\u8981\u7b49\\&#8221;\u3001\u201c\u600e\u4e48\u7b49\u201d\u3001\u4ee5\u53ca\\&#8221;\u7b49\u5f85\u65f6\u7236\u8fdb\u7a0b\u8be5\u5e72\u4ec0\u4e48\\&#8221;&#xff0c;\u662f\u5199\u51fa\u5065\u58ee\u591a\u8fdb\u7a0b<\/p>\n","protected":false},"author":2,"featured_media":106689,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11653,58,259,305,442,44],"topic":[],"class_list":["post-106690","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-11653","tag-linux","tag-unix","tag-305","tag-442","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Linux\u7cfb\u7edf\u3011\u3010Linux\u8fdb\u7a0b\u7ec8\u6b62\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/106690.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Linux\u7cfb\u7edf\u3011\u3010Linux\u8fdb\u7a0b\u7ec8\u6b62\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Linux\u8fdb\u7a0b\u63a7\u5236\u4e09\u90e8\u66f2&#xff1a;\u7ec8\u6b62\u3001\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u6587\u7ae0\u5b9a\u4f4d&#xff1a;\u8fdb\u7a0b\u63a7\u5236\u662f\u7406\u89e3\u64cd\u4f5c\u7cfb\u7edf&quot;\u5982\u4f55\u7ba1\u7406\u8fd0\u884c\u4e2d\u7684\u7a0b\u5e8f&quot;\u7684\u6838\u5fc3\u7ae0\u8282\u3002\u672c\u6587\u4f9d\u636e\u8bfe\u5802\u5b9e\u5f55\u6574\u7406&#xff0c;\u8986\u76d6\u8fdb\u7a0b\u7ec8\u6b62\u7684\u9000\u51fa\u7801\u8bed\u4e49\u3001wait\/waitpid\u50f5\u5c38\u8fdb\u7a0b\u56de\u6536\u3001status\u4f4d\u56fe\u89e3\u6790\u3001\u963b\u585e\/\u975e\u963b\u585e\u7b49\u5f85\u7684\u672c\u8d28\u533a\u522b&#xff0c;\u4ee5\u53caexec\u7a0b\u5e8f\u66ff\u6362\u7684\u521d\u6b65\u539f\u7406\u3002 \u672c\u7ae0\u91cd\u70b9&#xff1a;\u8fdb\u7a0b\u7b49\u5f85\u3002\u7406\u89e3&quot;\u4e3a\u4ec0\u4e48\u8981\u7b49&quot;\u3001\u201c\u600e\u4e48\u7b49\u201d\u3001\u4ee5\u53ca&quot;\u7b49\u5f85\u65f6\u7236\u8fdb\u7a0b\u8be5\u5e72\u4ec0\u4e48&quot;&#xff0c;\u662f\u5199\u51fa\u5065\u58ee\u591a\u8fdb\u7a0b\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/106690.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-17T17:08:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260917170835-6aac1e938d393.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/106690.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/106690.html\",\"name\":\"\u3010Linux\u7cfb\u7edf\u3011\u3010Linux\u8fdb\u7a0b\u7ec8\u6b62\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-17T17:08:36+00:00\",\"dateModified\":\"2026-09-17T17:08:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/106690.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/106690.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/106690.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Linux\u7cfb\u7edf\u3011\u3010Linux\u8fdb\u7a0b\u7ec8\u6b62\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u3011\u6d41\u98df\u822c\u6295\u5582\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010Linux\u7cfb\u7edf\u3011\u3010Linux\u8fdb\u7a0b\u7ec8\u6b62\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/106690.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Linux\u7cfb\u7edf\u3011\u3010Linux\u8fdb\u7a0b\u7ec8\u6b62\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Linux\u8fdb\u7a0b\u63a7\u5236\u4e09\u90e8\u66f2&#xff1a;\u7ec8\u6b62\u3001\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u6587\u7ae0\u5b9a\u4f4d&#xff1a;\u8fdb\u7a0b\u63a7\u5236\u662f\u7406\u89e3\u64cd\u4f5c\u7cfb\u7edf\"\u5982\u4f55\u7ba1\u7406\u8fd0\u884c\u4e2d\u7684\u7a0b\u5e8f\"\u7684\u6838\u5fc3\u7ae0\u8282\u3002\u672c\u6587\u4f9d\u636e\u8bfe\u5802\u5b9e\u5f55\u6574\u7406&#xff0c;\u8986\u76d6\u8fdb\u7a0b\u7ec8\u6b62\u7684\u9000\u51fa\u7801\u8bed\u4e49\u3001wait\/waitpid\u50f5\u5c38\u8fdb\u7a0b\u56de\u6536\u3001status\u4f4d\u56fe\u89e3\u6790\u3001\u963b\u585e\/\u975e\u963b\u585e\u7b49\u5f85\u7684\u672c\u8d28\u533a\u522b&#xff0c;\u4ee5\u53caexec\u7a0b\u5e8f\u66ff\u6362\u7684\u521d\u6b65\u539f\u7406\u3002 \u672c\u7ae0\u91cd\u70b9&#xff1a;\u8fdb\u7a0b\u7b49\u5f85\u3002\u7406\u89e3\"\u4e3a\u4ec0\u4e48\u8981\u7b49\"\u3001\u201c\u600e\u4e48\u7b49\u201d\u3001\u4ee5\u53ca\"\u7b49\u5f85\u65f6\u7236\u8fdb\u7a0b\u8be5\u5e72\u4ec0\u4e48\"&#xff0c;\u662f\u5199\u51fa\u5065\u58ee\u591a\u8fdb\u7a0b","og_url":"https:\/\/www.wsisp.com\/helps\/106690.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-17T17:08:36+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260917170835-6aac1e938d393.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/106690.html","url":"https:\/\/www.wsisp.com\/helps\/106690.html","name":"\u3010Linux\u7cfb\u7edf\u3011\u3010Linux\u8fdb\u7a0b\u7ec8\u6b62\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-17T17:08:36+00:00","dateModified":"2026-09-17T17:08:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/106690.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/106690.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/106690.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Linux\u7cfb\u7edf\u3011\u3010Linux\u8fdb\u7a0b\u7ec8\u6b62\u7b49\u5f85\u8be6\u89e3\u4e0e\u7a0b\u5e8f\u66ff\u6362\u673a\u5236\u521d\u4f53\u9a8c\u3011\u6d41\u98df\u822c\u6295\u5582"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/106690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=106690"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/106690\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/106689"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=106690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=106690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=106690"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=106690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}