{"id":87571,"date":"2026-07-30T14:58:31","date_gmt":"2026-07-30T06:58:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/87571.html"},"modified":"2026-07-30T14:58:31","modified_gmt":"2026-07-30T06:58:31","slug":"%e3%80%90linux%e7%af%87%e3%80%91%e6%95%b0%e5%ad%97%e4%b8%96%e7%95%8c%e7%9a%84%e6%80%bb%e6%8c%87%e6%8c%a5-%e8%bf%9b%e7%a8%8b%e6%8e%a7%e5%88%b6%e4%b8%8e%e8%b0%83","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/87571.html","title":{"rendered":"\u3010Linux\u7bc7\u3011\u6570\u5b57\u4e16\u754c\u7684\u201c\u603b\u6307\u6325\u201d\u2014\u2014\u8fdb\u7a0b\u63a7\u5236\u4e0e\u8c03\u5ea6\u673a\u5236\u8be6\u89e3"},"content":{"rendered":"<p style=\"text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"100\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065819-6a6af60be11ae.jpg\" width=\"100\" \/><\/p>\n<p style=\"text-align:center\">\u4f5c\u8005\u4e3b\u9875<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>\u73b0\u6709\u4e13\u680f<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u7b97\u6cd5\u7bc7<\/td>\n<td>Linux\u7bc7<\/td>\n<\/tr>\n<tr>\n<td>QT\u767e\u65e5\u7b51\u57fa\u7bc7<\/td>\n<td>\u6570\u636e\u7ed3\u6784\u7bc7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E5%88%9B%E5%BB%BA\" style=\"background-color:transparent;text-align:center\">\u8fdb\u7a0b\u7684\u63a7\u5236<\/h2>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065820-6a6af60c0effb.gif\" \/><\/p>\n<hr \/>\n<h2><span style=\"color:#fe2c24\">\u76ee\u5f55\/\u7d22\u5f15:<\/span><\/h2>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E5%88%9B%E5%BB%BA-toc\" style=\"margin-left:0px\">\u8fdb\u7a0b\u7684\u521b\u5efa<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E5%88%9B%E5%BB%BA-toc\" style=\"margin-left:0px\">\u8fdb\u7a0b\u7684\u521b\u5efa<\/p>\n<p id=\"%E6%B7%B1%E5%BA%A6%E4%BA%86%E8%A7%A3%22fork%22-toc\" style=\"margin-left:40px\">\u6df1\u5ea6\u4e86\u89e3&#034;fork&#034;<\/p>\n<p id=\"fork%E7%9A%84%E8%BF%94%E5%9B%9E%E5%80%BC%EF%BC%9A-toc\" style=\"margin-left:40px\">fork\u7684\u8fd4\u56de\u503c&#xff1a;<\/p>\n<p id=\"fork%E7%9A%84%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8-toc\" style=\"margin-left:40px\">fork\u7684\u7b80\u5355\u4f7f\u7528<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E5%9C%A8%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9A%84%E4%BD%9C%E7%94%A8%EF%BC%9A-toc\" style=\"margin-left:40px\">\u8fdb\u7a0b\u5728\u865a\u62df\u673a\u7684\u4f5c\u7528&#xff1a;<\/p>\n<p id=\"%E5%86%99%E6%97%B6%E6%8B%B7%E8%B4%9D%EF%BC%9A-toc\" style=\"margin-left:40px\">\u5199\u65f6\u62f7\u8d1d&#xff1a;<\/p>\n<p id=\"fork%E7%9A%84%E5%B8%B8%E8%A7%84%E7%94%A8%E6%B3%95%EF%BC%9A-toc\" style=\"margin-left:40px\">fork\u7684\u5e38\u89c4\u7528\u6cd5&#xff1a;<\/p>\n<p id=\"fork%E8%B0%83%E7%94%A8%E5%A4%B1%E8%B4%A5%E7%9A%84%E5%B8%B8%E8%A7%81%E5%8E%9F%E5%9B%A0%EF%BC%9A-toc\" style=\"margin-left:40px\">fork\u8c03\u7528\u5931\u8d25\u7684\u5e38\u89c1\u539f\u56e0&#xff1a;<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E7%BB%88%E6%AD%A2%EF%BC%9A-toc\" style=\"margin-left:0px\">\u8fdb\u7a0b\u7684\u7ec8\u6b62&#xff1a;<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E9%80%80%E5%87%BA%E7%9A%84%E5%9C%BA%E6%99%AF%EF%BC%9A-toc\" style=\"margin-left:40px\">\u8fdb\u7a0b\u9000\u51fa\u7684\u573a\u666f&#xff1a;<\/p>\n<p id=\"%E9%80%80%E5%87%BA%E7%A0%81%E7%9A%84%E8%AF%A6%E8%A7%A3%EF%BC%9A-toc\" style=\"margin-left:40px\">\u9000\u51fa\u7801\u7684\u8be6\u89e3&#xff1a;<\/p>\n<p id=\"%E6%AD%A3%E5%B8%B8%E7%BB%88%E6%AD%A2%EF%BC%88%E6%9F%A5%E7%9C%8B%E8%BF%9B%E7%A8%8B%E7%9A%84%E9%80%80%E5%87%BA%E7%A0%81%EF%BC%89%E6%8C%87%E4%BB%A4%EF%BC%9A%20echo%20%24%3F%C2%A0%20%C2%A0-toc\" style=\"margin-left:80px\">\u6b63\u5e38\u7ec8\u6b62&#xff08;\u67e5\u770b\u8fdb\u7a0b\u7684\u9000\u51fa\u7801&#xff09;\u6307\u4ee4&#xff1a; echo $?\u00a0 \u00a0<\/p>\n<p id=\"%E5%9F%BA%E7%A1%80%E9%80%80%E5%87%BA%E7%A0%81%EF%BC%9A-toc\" style=\"margin-left:80px\">\u57fa\u7840\u9000\u51fa\u7801&#xff1a;<\/p>\n<p id=\"1-133%E9%80%80%E5%87%BA%E7%A0%81%E5%A4%A7%E5%85%A8%EF%BC%9A-toc\" style=\"margin-left:80px\">1-133\u9000\u51fa\u7801\u5927\u5168&#xff1a;<\/p>\n<p id=\"Linux%20Shell%E4%B8%BB%E8%A6%81%E7%9A%84%E9%80%80%E5%87%BA%E7%A0%81%3A-toc\" style=\"margin-left:80px\">Linux Shell\u4e3b\u8981\u7684\u9000\u51fa\u7801:<\/p>\n<p id=\"errno%EF%BC%9A%E8%8E%B7%E5%8F%96%E8%BF%9B%E7%A8%8B%E7%BB%93%E6%9D%9F%E7%9A%84%E9%94%99%E8%AF%AF%E7%A0%81-toc\" style=\"margin-left:80px\">errno&#xff1a;\u83b7\u53d6\u8fdb\u7a0b\u7ed3\u675f\u7684\u9519\u8bef\u7801<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E9%80%80%E5%87%BA%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%EF%BC%9A-toc\" style=\"margin-left:40px\">\u8fdb\u7a0b\u9000\u51fa\u7684\u5e38\u89c1\u65b9\u6cd5&#xff1a;<\/p>\n<p id=\"1.main%E5%87%BD%E6%95%B0%E8%BF%9B%E8%A1%8C%E8%BF%94%E5%9B%9E-toc\" style=\"margin-left:80px\">1.main\u51fd\u6570\u8fdb\u884c\u8fd4\u56de<\/p>\n<p id=\"2.%20%E8%B0%83%E7%94%A8exit%EF%BC%88%E6%98%AFC%E8%AF%AD%E8%A8%80%E6%96%B9%E5%90%91%E7%9A%84%E6%8E%A5%E5%8F%A3%EF%BC%89-toc\" style=\"margin-left:80px\">2. \u8c03\u7528exit&#xff08;\u662fC\u8bed\u8a00\u65b9\u5411\u7684\u63a5\u53e3&#xff09;<\/p>\n<p id=\"3.%20_exit%EF%BC%88%E7%B3%BB%E7%BB%9F%E7%BA%A7%E5%88%AB%E7%9A%84%E6%8E%A5%E5%8F%A3%EF%BC%89-toc\" style=\"margin-left:80px\">3. _exit&#xff08;\u7cfb\u7edf\u7ea7\u522b\u7684\u63a5\u53e3&#xff09;<\/p>\n<p id=\"_exit%20vs%20exit%3A-toc\" style=\"margin-left:80px\">_exit vs exit:<\/p>\n<p id=\"%E8%BF%9B%E9%98%B6%E4%BA%86%E8%A7%A3exit%20and%20_exit(1)-toc\" style=\"margin-left:80px\">\u8fdb\u9636\u4e86\u89e3exit and _exit(1)<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E7%AD%89%E5%BE%85%EF%BC%9A-toc\" style=\"margin-left:0px\">\u8fdb\u7a0b\u7684\u7b49\u5f85&#xff1a;<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E7%AD%89%E5%BE%85%E5%BF%85%E8%A6%81%E6%80%A7-toc\" style=\"margin-left:40px\">\u8fdb\u7a0b\u7b49\u5f85\u5fc5\u8981\u6027<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E7%AD%89%E5%BE%85%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%9A-toc\" style=\"margin-left:40px\">\u8fdb\u7a0b\u7b49\u5f85\u7684\u65b9\u6cd5&#xff1a;<\/p>\n<p id=\"wait%EF%BC%88%EF%BC%89-toc\" style=\"margin-left:120px\">wait&#xff08;&#xff09;<\/p>\n<p id=\"waitpid()-toc\" style=\"margin-left:120px\">waitpid()<\/p>\n<p id=\"%E8%8E%B7%E5%8F%96%E5%AD%90%E8%BF%9B%E7%A8%8B%E7%9A%84status%EF%BC%88%E8%AF%A6%E7%BB%86%EF%BC%8C%E7%AE%80%E5%8D%95%E6%98%93%E6%87%82%EF%BC%89-toc\" style=\"margin-left:40px\">\u83b7\u53d6\u5b50\u8fdb\u7a0b\u7684status&#xff08;\u8be6\u7ec6&#xff0c;\u7b80\u5355\u6613\u61c2&#xff09;<\/p>\n<p id=\"%E9%98%BB%E5%A1%9E%E7%AD%89%E5%BE%85%E5%92%8C%E9%9D%9E%E9%98%BB%E5%A1%9E%E7%AD%89%E5%BE%85%EF%BC%9A-toc\" style=\"margin-left:40px\">\u963b\u585e\u7b49\u5f85\u548c\u975e\u963b\u585e\u7b49\u5f85&#xff1a;<\/p>\n<p id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E6%9B%BF%E6%8D%A2-toc\" style=\"margin-left:0px\">\u8fdb\u7a0b\u7684\u66ff\u6362<\/p>\n<p id=\"%E6%9B%BF%E6%8D%A2%E5%8E%9F%E7%90%86%EF%BC%9A-toc\" style=\"margin-left:40px\">\u66ff\u6362\u539f\u7406&#xff1a;<\/p>\n<p id=\"%E6%9B%BF%E6%8D%A2%E7%9A%84%E6%93%8D%E4%BD%9C%EF%BC%9A-toc\" style=\"margin-left:40px\">\u66ff\u6362\u7684\u64cd\u4f5c&#xff1a;<\/p>\n<p id=\"%E7%A8%8B%E5%BA%8F%E7%9A%84%E8%BF%94%E5%9B%9E%EF%BC%9A-toc\" style=\"margin-left:40px\">\u7a0b\u5e8f\u7684\u8fd4\u56de&#xff1a;<\/p>\n<p id=\"%E5%88%9B%E5%BB%BA%E5%AD%90%E8%BF%9B%E7%A8%8B%E5%AE%8C%E6%88%90%E6%9B%BF%E6%8D%A2%EF%BC%9A-toc\" style=\"margin-left:40px\">\u521b\u5efa\u5b50\u8fdb\u7a0b\u5b8c\u6210\u66ff\u6362&#xff1a;<\/p>\n<p id=\"exec%E5%AE%B6%E6%97%8F%EF%BC%9A-toc\" style=\"margin-left:40px\">exec\u5bb6\u65cf&#xff1a;<\/p>\n<p id=\"execl-toc\" style=\"margin-left:80px\">execl<\/p>\n<p id=\"exclp-toc\" style=\"margin-left:80px\">exclp<\/p>\n<p id=\"%E2%80%8B%E7%BC%96%E8%BE%91execv-toc\" style=\"margin-left:80px\">\u200b\u7f16\u8f91execv<\/p>\n<p id=\"execvp-toc\" style=\"margin-left:80px\">execvp<\/p>\n<p id=\"execle-toc\" style=\"margin-left:80px\">execle<\/p>\n<p id=\"execvpe-toc\" style=\"margin-left:80px\">execvpe<\/p>\n<p id=\"execve(%E7%B3%BB%E7%BB%9F%E6%8E%A5%E5%8F%A3)-toc\" style=\"margin-left:80px\">execve(\u7cfb\u7edf\u63a5\u53e3)<\/p>\n<hr id=\"hr-toc\" \/>\n<h2 id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E5%88%9B%E5%BB%BA\" style=\"background-color:transparent\">\u8fdb\u7a0b\u7684\u521b\u5efa<\/h2>\n<h3 id=\"%E6%B7%B1%E5%BA%A6%E4%BA%86%E8%A7%A3%22fork%22\"><span style=\"color:#fe2c24\">\u6df1\u5ea6\u4e86\u89e3&#034;fork&#034;<\/span><\/h3>\n<p>for\u5728\u6211\u4eec\u7684\u8fdb\u7a0b\u4e2d\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u51fd\u6570&#xff0c;\u5b83\u53ef\u4ee5\u8fdb\u884c\u521b\u5efa\u5b50\u8fdb\u7a0b&#xff0c;\u6709\u5229\u4e8e\u6211\u4eec\u540e\u7eed\u7684\u4ee3\u7801\u7684\u4e66\u5199\u3002<\/p>\n<p>\u5148\u770b\u4e00\u4e0bfork\u7684\u6587\u6863<\/p>\n<p>man fork <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"264\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065820-6a6af60c3f756.png\" width=\"732\" \/><\/p>\n<h3 id=\"fork%E7%9A%84%E8%BF%94%E5%9B%9E%E5%80%BC%EF%BC%9A\"><span style=\"color:#fe2c24\">fork\u7684\u8fd4\u56de\u503c&#xff1a;<\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"102\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065820-6a6af60c540cd.png\" width=\"2493\" \/><\/p>\n<p>\u6210\u529f\u4f1a\u5c06\u81ea\u5df1\u7684\u8fdb\u7a0b\u8fd4\u56de\u7ed9\u7236\u8fdb\u7a0b&#xff08;\u524d\u9762\u8bf4\u8fc7\u4e3b\u8981\u7528\u4e8e\u7236\u8fdb\u7a0b\u5bf9\u8be5\u8fdb\u7a0b\u7684\u56de\u6536&#xff09;&#xff0c;\u5e76\u4e14\u6210\u529f\u5b50\u8fdb\u7a0b\u8fd4\u56de0&#xff0c; \u7236\u8fdb\u7a0b\u8fd4\u56de\u975e0&#xff08;\u5b50\u8fdb\u7a0b\u7684pid&#xff09; &#xff0c; &lt;0\u5219\u4ee3\u8868\u521b\u5efa\u5931\u8d25\u3002\u90fd\u5931\u8d25\u4e86\u6211\u8fd8\u73a9\u4ec0\u4e48\u73a9\u76f4\u63a5return\u3002<\/p>\n<h3 id=\"fork%E7%9A%84%E7%AE%80%E5%8D%95%E4%BD%BF%E7%94%A8\"><span style=\"color:#fe2c24\">fork\u7684\u7b80\u5355\u4f7f\u7528<\/span><\/h3>\n<p>  1 #include&lt;stdio.h&gt;<br \/>\n  2 #include&lt;sys\/types.h&gt;<br \/>\n  3 #include&lt;unistd.h&gt;<br \/>\n  4<br \/>\n  5 int main()<br \/>\n  6 {<br \/>\n  7     pid_t pi&#061;fork();<br \/>\n  8     while(1)<br \/>\n  9     {<br \/>\n 10        if(pi&#061;&#061;0)\/\/\u5b50\u8fdb\u7a0b<br \/>\n 11        {<br \/>\n 12            printf(&#034;\u8fd9\u662f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\\\\n&#034;);<br \/>\n 13            sleep(5);<br \/>\n 14        }<br \/>\n 15<br \/>\n 16        else if(pi&gt;0)<br \/>\n 17        {<br \/>\n 18            printf(&#034;\u8fd9\u662f\u4e00\u4e2a\u7236\u8fdb\u7a0b\\\\n&#034;);<br \/>\n 19            sleep(5);<br \/>\n 20        }<br \/>\n 21        else<br \/>\n 22        {<br \/>\n 23            printf(&#034;\u521b\u5efa\u9519\u8bef\\\\n&#034;);<br \/>\n 24            \/\/\u9519\u8bef\u4e86\u6211\u8fd8\u73a9\u5565\u73a9<br \/>\n 25            return 1;<br \/>\n 26        }<br \/>\n 27      }<br \/>\n 28     return 0;<br \/>\n 29 }<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c\u5c55\u793a&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"258\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065820-6a6af60c7c035.png\" width=\"873\" \/><\/p>\n<p>\u8fd9\u5c31\u662f\u6211\u4eecfork\u7684\u7b80\u5355\u7684\u4f7f\u7528\u3002<\/p>\n<p>\u8c03\u7528\u65f6\u8fdb\u7a0b\u4f1a\u7ed9\u65b0\u7684\u5b50\u8fdb\u7a0b\u5206\u914d\u65b0\u7684\u5185\u5b58\u5757\u548c\u5185\u6838\u6570\u636e\u7ed3\u6784\u7ed9\u5b50\u8fdb\u7a0b\u3002<\/p>\n<p>\u5c06\u7236\u8fdb\u7a0b\u5bf9\u5e94\u7684\u6570\u636e\u62f7\u8d1d\u7ed9\u5b50\u8fdb\u7a0b\u4e00\u4efd&#xff0c;&#xff08;\u50cf\u6211\u4eec\u524d\u9762\u6240\u8bf4\u7684\u73af\u5883\u53d8\u91cf&#xff09;\u3002<\/p>\n<p>\u6dfb\u52a0\u5b50\u8fdb\u7a0b\u5230\u7cfb\u7edf\u8fdb\u7a0b\u5217\u8868\u5f53\u4e2d&#xff0c; fork\u8fd4\u56de\u8c03\u5ea6\u5668\u8fdb\u884c\u8c03\u5ea6\u3002<\/p>\n<h3 id=\"%E8%BF%9B%E7%A8%8B%E5%9C%A8%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9A%84%E4%BD%9C%E7%94%A8%EF%BC%9A\"><span style=\"color:#fe2c24\">\u8fdb\u7a0b\u5728\u865a\u62df\u673a\u7684\u4f5c\u7528&#xff1a;<\/span><\/h3>\n<p>\u5982\u679c\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u7684\u4ee3\u7801\u662fOS&#xff08;\u53e6\u4e00\u53f0\u64cd\u4f5c\u7cfb\u7edf\u7684\u4ee3\u7801&#xff09;\u7684\u4ee3\u7801\u90a3\u4e48\u5c31\u76f8\u5f53\u4e8e\u6211\u4eec\u8dd1\u4e862\u53f0\u64cd\u4f5c\u7cfb\u7edf&#xff0c; \u8fd9\u4e5f\u5c31\u662f\u865a\u62df\u673a\u7684\u539f\u7406\u3002<\/p>\n<h3 id=\"%E5%86%99%E6%97%B6%E6%8B%B7%E8%B4%9D%EF%BC%9A\"><span style=\"color:#fe2c24\">\u5199\u65f6\u62f7\u8d1d&#xff1a;<\/span><\/h3>\n<p>\u5728\u8fdb\u884cfork\u64cd\u4f5c\u7684\u65f6\u5019\u6211\u4eec\u521a\u5f00\u59cb\u7684\u6570\u636e\u6bb5\u662f<span style=\"color:#be191c\">\u53ef\u4ee5\u8fdb\u884c\u5199\u7684<\/span>&#xff0c; \u4f46\u662ffork\u4e4b\u540e\u6211\u4eec\u7684\u6570\u636e\u6bb5\u7684<span style=\"color:#ff9900\">\u6743\u9650\u4f1a\u53d8\u6210\u53ea\u8bfb\u7684<\/span>\u3002&#xff08;fork\u4e4b\u540e&#xff0c;\u7236\u5b50\u4ee3\u7801\u5171\u4eab&#xff0c; \u7236\u5b50\u5c06\u4e0d\u518d\u8fdb\u884c\u5199\u5165&#xff0c; \u6570\u636e\u4e5f\u662f\u5171\u4eab\u7684&#xff09;\u3002\u5f53\u4e00\u65b9\u8fdb\u884c\u5199\u5165&#xff0c;\u56e0\u4e3a\u6743\u9650\u7684\u53ea\u8bfb\u7684&#xff0c;<span style=\"color:#ff9900\">\u4f1a\u53d1\u751f\u9519\u8bef<\/span>&#xff0c;\u90a3\u4e48\u5c31\u4f1a<span style=\"color:#ff9900\">\u89e6\u53d1\u5199\u65f6\u62f7\u8d1d<\/span>&#xff0c; \u4ed6\u4f1a\u5728\u5c06\u6211\u4eec\u7684\u4ee3\u7801\u548c\u6570\u636e\u5728\u7269\u7406\u5185\u5b58\u4e2d\u8fdb\u884c<span style=\"color:#ffd900\">\u62f7\u8d1d\u4e00\u4efd<\/span>&#xff0c; \u8fd9\u6837\u6211\u4eec\u7236\u4e0e\u5b50\u5c31\u80fd\u6709<span style=\"color:#fe2c24\">\u5404\u81ea\u7684\u7269\u7406\u5185\u5b58<\/span>\u4e86\u3002<\/p>\n<p><span style=\"color:#fe2c24\">\u4e00\u53e5\u8bdd\u603b\u7ed3&#xff1a;OS\u4ee5\u8fd9\u79cd\u9519\u8bef\u7684\u65b9\u5f0f\u7ed9\u5b50\u8fdb\u7a0b\u8fdb\u884c\u5206\u914d\u7a7a\u95f4&#xff08;\u5e76\u4e0d\u662f\u771f\u6b63\u7684\u9519\u8bef&#xff09;\u3002\u8fd9\u6837\u6211\u4eec\u80fd\u66f4\u597d\u7684\u8fdb\u884c\u7a7a\u95f4\u7684\u5229\u7528&#xff0c;\u7b49\u5230\u6211\u4eec\u9700\u8981\u5206\u522b\u64cd\u4f5c\u7684\u65f6\u5019&#xff0c;\u5728\u8fdb\u884c\u7533\u8bf7\u7a7a\u95f4\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"417\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065820-6a6af60c98bf5.png\" width=\"1110\" \/><\/p>\n<p>\u56e0\u4e3a\u6709\u4e86\u5199\u65f6\u62f7\u8d1d\u6280\u672f\u7684\u5b58\u5728&#xff0c; \u6211\u4eec\u7684\u7236\u5b50\u8fdb\u7a0b\u624d\u80fd\u5f7b\u5e95\u7684\u8fdb\u884c\u5206\u79bb&#xff0c; \u5b8c\u6210\u4e86\u8fdb\u7a0b\u72ec\u7acb\u6027\u7684\u6280\u672f\u4fdd\u8bc1&#xff01; \u5199\u65f6\u62f7\u8d1d\u662f\u4e00\u79cd\u5ef6\u65f6\u7533\u8bf7\u6280\u672f&#xff0c;\u53ef\u4ee5\u63d0\u9ad8\u6574\u4f53\u5185\u5b58\u7684\u4f7f\u7528\u7387\u3002<\/p>\n<h3 id=\"fork%E7%9A%84%E5%B8%B8%E8%A7%84%E7%94%A8%E6%B3%95%EF%BC%9A\"><span style=\"color:#fe2c24\">fork\u7684\u5e38\u89c4\u7528\u6cd5&#xff1a;<\/span><\/h3>\n<p>\u4e00\u4e2a\u8fdb\u7a0b\u5e0c\u671b\u590d\u5236\u81ea\u5df1&#xff0c; \u4f7f\u7236\u5b50\u8fdb\u7a0b\u540c\u65f6\u6267\u884c\u4e0d\u540c\u7684\u4ee3\u7801&#xff0c;\u4f8b\u5982&#xff1a;\u7236\u8fdb\u7a0b\u7b49\u5f85\u5ba2\u6237\u7aef\u8bf7\u6c42&#xff0c;\u751f\u6210\u5b50\u8fdb\u7a0b\u6765\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<p>\u4e00\u4e2a\u8fdb\u7a0b\u8981\u6267\u884c\u4e00\u4e2a\u4e0d\u540c\u7684\u7a0b\u5e8f\u3002\u4f8b\u5982\u5b50\u8fdb\u7a0b\u4ecefork\u8fd4\u56de\u4f1a\u8c03\u7528exec\u51fd\u6570\u3002<\/p>\n<h3 id=\"fork%E8%B0%83%E7%94%A8%E5%A4%B1%E8%B4%A5%E7%9A%84%E5%B8%B8%E8%A7%81%E5%8E%9F%E5%9B%A0%EF%BC%9A\"><span style=\"color:#fe2c24\">fork\u8c03\u7528\u5931\u8d25\u7684\u5e38\u89c1\u539f\u56e0&#xff1a;<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u8fd9\u4e2a\u95ee\u9898\u4e5f\u5c31\u662f\u5b50\u8fdb\u7a0b\u521b\u5efa\u5931\u8d25\u7684\u539f\u56e0\u3002<\/span><\/p>\n<p>\u7cfb\u7edf\u4e2d\u6709\u592a\u591a\u7684\u8fdb\u7a0b\u4e86\u3002<\/p>\n<p>\u5b9e\u9645\u7528\u6237\u7684\u8fdb\u7a0b\u6570\u8d85\u51fa\u4e86\u9650\u5236\u3002<\/p>\n<p>\u521b\u5efa\u865a\u62df\u7a7a\u95f4\u548c\u9875\u8868\u5931\u8d25\u4e86\u3002<\/p>\n<h2 id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E7%BB%88%E6%AD%A2%EF%BC%9A\"><span style=\"color:#fe2c24\">\u8fdb\u7a0b\u7684\u7ec8\u6b62&#xff1a;<\/span><\/h2>\n<p>\u8fdb\u7a0b\u7684\u7ec8\u6b62\u7684\u672c\u8d28\u4f7f<span style=\"color:#fe2c24\">\u91ca\u653e\u7cfb\u7edf\u7684\u8d44\u6e90<\/span>&#xff0c; \u5c31\u662f\u91ca\u653e\u8fdb\u7a0b<span style=\"color:#fe2c24\">\u91ca\u653e\u76f8\u5173\u7684\u5185\u6838\u6570\u636e\u7ed3\u6784&#xff08;PCB&#xff09;\u548c\u5bf9\u5e94\u7684\u4ee3\u7801\u548c\u6570\u636e<\/span>\u3002<\/p>\n<h3 id=\"%E8%BF%9B%E7%A8%8B%E9%80%80%E5%87%BA%E7%9A%84%E5%9C%BA%E6%99%AF%EF%BC%9A\"><span style=\"color:#fe2c24\">\u8fdb\u7a0b\u9000\u51fa\u7684\u573a\u666f&#xff1a;<\/span><\/h3>\n<p>1. \u4ee3\u7801\u8fd0\u884c,\u7ed3\u679c\u6b63\u786e\u3002<\/p>\n<p>2. \u4ee3\u7801\u8fd0\u884c\u5b8c\u6bd5&#xff0c;\u7ed3\u679c\u4e0d\u6b63\u786e\u3002<\/p>\n<p>3. \u4ee3\u7801\u5f02\u5e38\u9000\u51fa&#xff08;\u8fdb\u7a0b\u7684\u4fe1\u53f7\u4f1a\u8fdb\u884c\u8bf4\u660e\u7684&#xff09;\u3002<\/p>\n<p>\u6211\u4eec\u7684ctrl&#043;c \u53ef\u4ee5\u5f3a\u5236\u7684\u8ba9\u4fe1\u53f7\u8fdb\u884c\u7ec8\u6b62\u3002<\/p>\n<h3 id=\"%E9%80%80%E5%87%BA%E7%A0%81%E7%9A%84%E8%AF%A6%E8%A7%A3%EF%BC%9A\"><span style=\"color:#fe2c24\">\u9000\u51fa\u7801\u7684\u8be6\u89e3&#xff1a;<\/span><\/h3>\n<h4 id=\"%E6%AD%A3%E5%B8%B8%E7%BB%88%E6%AD%A2%EF%BC%88%E6%9F%A5%E7%9C%8B%E8%BF%9B%E7%A8%8B%E7%9A%84%E9%80%80%E5%87%BA%E7%A0%81%EF%BC%89%E6%8C%87%E4%BB%A4%EF%BC%9A%20echo%20%24%3F%C2%A0%20%C2%A0\">\u6b63\u5e38\u7ec8\u6b62&#xff08;\u67e5\u770b\u8fdb\u7a0b\u7684\u9000\u51fa\u7801&#xff09; <span style=\"color:#fe2c24\">\u6307\u4ee4&#xff1a; echo $?\u00a0<\/span> \u00a0<\/h4>\n<p>\u4f5c\u7528&#xff1a;\u67e5\u770b\u8fdb\u7a0b\u7684\u9000\u51fa\u7801\u3002<\/p>\n<p>\u6211\u4eec\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e5f\u8981\u5199\u9053task_struct\u4e2d<\/p>\n<p>\u6211\u4eec\u5728main\u51fd\u6570\u8fdb\u884c\u8c03\u7528\u7684\u65f6\u5019\u4e00\u822c\u90fd\u4f1a\u8fd4\u56dereturn 0&#xff0c;\u8fd9\u91cc\u76840\u8868\u793a\u8fdb\u7a0b\u6b63\u5e38\u8fdb\u884c\u9000\u51fa\u3002<\/p>\n<p>echo $? <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"59\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065820-6a6af60cd7927.png\" width=\"780\" \/><\/p>\n<p>\u6211\u4eec\u5199\u4e00\u6bb5\u7a0b\u5e8f\u6765\u9a8c\u8bc1\u8fd9\u4e00\u529f\u80fd&#xff1a;<\/p>\n<p>\u6211\u4eec\u80fd\u770b\u5230\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684c\u8bed\u8a00\u7a0b\u5e8f\u3002\u6ca1\u6709\u4efb\u4f55\u7684\u6bdb\u75c5&#xff0c;\u6240\u4ee5\u8fd9\u91cc\u4ed6\u4f1a\u4e00\u81f4\u7684\u8fdb\u884c\u6267\u884c&#xff0c; \u5230\u6700\u540e\u8fd4\u56de\u4e00\u4e2a0\u3002<\/p>\n<p>#include&lt;stdio.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    printf(&#034;\u4f60\u597d\u9000\u51fa\u7801&#xff01;&#034;);<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"933\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065820-6a6af60ce9dd5.png\" width=\"1554\" \/><\/p>\n<p>\u50cf\u6211\u4eec\u5728shell(\u547d\u4ee4\u884c\u53c2\u6570)\u4e2d\u8fd0\u884c\u7684\u547d\u4ee4\u50cfls pwd\u4e5f\u662f\u4e00\u4e2a\u5bf9\u5e94\u7684c\u8bed\u8a00\u7a0b\u5e8f\u3002\u90a3\u6211\u4eec\u662f\u4e0d\u662f\u4e5f\u80fd\u67e5\u770b\u5bf9\u5e94\u7684\u8fdb\u7a0b\u9000\u51fa\u7801&#xff1f;\u90a3\u6211\u4eec\u5c31\u6765\u5b9e\u9a8c\u4e00\u4e0b\u3002<\/p>\n<p>\u4e0b\u56fe&#xff0c;\u53d1\u73b0\u679c\u7136\u5982\u6b64\u6211\u4eec\u7684\u6307\u4ee4\u662f\u6b63\u786e\u7684&#xff0c;\u4ed6\u4eec\u90fd\u6b63\u5e38\u7684\u8fdb\u884c\u4e86\u5bf9\u5e94\u7684\u9000\u51fa\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"203\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065821-6a6af60db36d1.png\" width=\"735\" \/><\/p>\n<p>\u90a3\u6211\u4eec\u8bd5\u8bd5\u4e0d\u6b63\u5e38\u7684\u9000\u51fa<\/p>\n<p>\u6211\u4eec\u53d1\u73b0\u6211\u4eec\u7684\u5f53\u524d\u76ee\u5f55\u4e0d\u5b58\u5728add.c\u8fd9\u4e2a\u6587\u4ef6\u3002\u7136\u540e\u6211\u4eec\u6253\u5370\u5bf9\u5e94\u7684\u9000\u51fa\u7801&#xff0c; \u8fdb\u884c\u67e5\u770b\u679c\u7136\u4e0d\u662f0\u662f2&#xff0c;\u90a3\u4e48\u8fd9\u4e2a2\u4ee3\u8868\u7684\u662f\u4ec0\u4e48\u5462&#xff1f;&#xff1f;&#xff1f;\u522b\u6025\u6211\u4eec\u5148\u770b\u4e0b\u9762\u7684\u4e00\u4e2a\u60c5\u51b5&#xff0c;\u5728\u8fdb\u884c\u8bf4\u660e&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"147\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065821-6a6af60dceaf2.png\" width=\"699\" \/><\/p>\n<p>\u90a3\u5982\u679c\u6211\u4eec\u518d\u6b21\u4f7f\u7528echo $?\u8fd8\u662f2\u5417&#xff1f;&#xff1f;&#xff1f;<\/p>\n<p>\u6211\u4eec\u53d1\u73b0\u662f0\u4e3a\u5565\u4e0d\u662f2&#xff1f;&#xff1f;&#xff1f;\u6ce8\u610f\u6211\u4eec\u4e0a\u6b21\u4f7f\u7528\u7684\u662fecho $?\u662f\u6b63\u5e38\u8fdb\u884c\u7ed3\u675f\u7684&#xff0c; \u6240\u4ee5\u6211\u4eec\u7684\u8fd9\u6b21\u8fd4\u56de\u503c\u662f\u8fd4\u56de\u4e0a\u4e00\u6b21\u7684\u989d\u7ed3\u679c\u3002 \u6240\u4ee5\u6211\u4eec\u80fd\u5f97\u51fa\u4ee5\u4e0b\u7684\u7ed3\u8bba&#xff1a;<\/p>\n<p>\u6211\u4eec\u7684\u6307\u4ee4echo $?\u662f\u8fd4\u56de\u4e0a\u4e00\u4e2a\u8fdb\u7a0b\u7684\u9000\u51fa\u7801\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"195\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065821-6a6af60de3573.png\" width=\"795\" \/><\/p>\n<p>\u6211\u4eec\u8bb0\u5f97\u4e0a\u4e00\u6b21\u6253\u5370\u51fa\u6765\u4e86\u4e00\u4e2a2\u8fd9\u4e2a2\u662f\u5565\u6211\u4eec\u73b0\u5728\u5c31\u6765\u770b\u4e00\u770b\u3002<\/p>\n<h4 id=\"%E5%9F%BA%E7%A1%80%E9%80%80%E5%87%BA%E7%A0%81%EF%BC%9A\"><span style=\"color:#fe2c24\">\u57fa\u7840\u9000\u51fa\u7801&#xff1a;<\/span><\/h4>\n<p>\u6211\u4eec\u9700\u8981\u7528\u5230\u4e00\u4e2a\u51fd\u6570\u3002<\/p>\n<p><span style=\"color:#fe2c24\">strerror&#xff08;&#xff09;<\/span><\/p>\n<p>\u770b\u4e00\u4e0b\u6587\u6863&#xff1a;<\/p>\n<p>man 3 strerror <\/p>\n<p>\u4f5c\u7528&#xff1a; \u8fd9\u4e2a\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6307\u9488\u6307\u5411\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u4e3b\u8981\u8fdb\u884c\u63cf\u8ff0\u8fd9\u4e2a\u9519\u8bef\u7684\u8fc7\u7a0b\u3002<\/p>\n<p><span style=\"color:#fe2c24\">\u8bf4\u4eba\u8bdd\u5c31\u662f\u6211\u4eec\u7ed9\u4ed6\u4e00\u4e2a\u9519\u8bef\u7801&#xff0c; \u4ed6\u4f1a\u8fdb\u884c\u5bf9\u5e94\u7684\u89e3\u91ca&#xff0c;\u5c06\u9519\u8bef\u7801\u8f6c\u5316\u4e3a\u9519\u8bef\u63cf\u8ff0<\/span>\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1223\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065822-6a6af60e095be.png\" width=\"2559\" \/><\/p>\n<p>\u6211\u4eec\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u6765\u6253\u5370\u8fd9\u4e9b\u9000\u51fa\u7801&#xff1a;<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;string.h&gt;<\/p>\n<p>int main() {<br \/>\n    for (int i &#061; 0; i &lt; 200; i&#043;&#043;)\/\/\u6211\u4eec\u4e0d\u77e5\u9053\u6709\u591a\u5c11\u4e2a\u9000\u51fa\u7801&#xff0c;\u5148\u8bbe\u7f6e200\u4e2a<br \/>\n    {<br \/>\n        printf(&#034;\u9000\u51fa\u7801&#xff1a;%d \u5bf9\u5e94\u7684\u89e3\u91ca\u662f%s\\\\n&#034;, i , strerror(i));<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<p>\u6211\u4eec\u80fd\u53d1\u73b0&#xff1a;<\/p>\n<p>1.\u679c\u7136\u6211\u4eec\u76840\u8fd9\u4e2a\u9000\u51fa\u7801&#xff1a;\u540e\u9762\u5199\u4e86\u4e00\u4e2asuccess\u4ee3\u8868\u6210\u529f\u3002<\/p>\n<p>2.\u6211\u4eec1\u53f7\u9000\u51fa\u7801&#xff1a;\u662f\u64cd\u4f5c\u4e0d\u88ab\u5141\u8bb8\u3002<\/p>\n<p>3.\u6211\u4eec\u6700\u60f3\u77e5\u9053\u76842\u53f7\u9000\u51fa\u7801\u662f&#xff1a;\u6ca1\u6709\u627e\u5230\u8be5\u6587\u4ef6\u3002<\/p>\n<p>4.\u6211\u4eec\u53d1\u73b0\u6211\u4eec\u7684\u9000\u51fa\u7801&#xff1a;134 \u5f80\u540e\u5c31\u6253\u5370\u51faUnknown error 134\u8bf4\u660e\u6ca1\u6709\u8fd9\u4e2a\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u7684\u9000\u51fa\u7801\u662f0-133\u3002<\/p>\n<p>\u4e0b\u9762\u9644\u5e26\u4e00\u5f20\u8868\u6765\u8be6\u7ec6\u7684\u89e3\u91ca\u8fd9\u4e9b\u4fe1\u53f7\u7684\u7528\u9014\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"4126\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065823-6a6af60f47195.png\" width=\"1474\" \/><\/p>\n<h4 id=\"1-133%E9%80%80%E5%87%BA%E7%A0%81%E5%A4%A7%E5%85%A8%EF%BC%9A\"><span style=\"color:#fe2c24\">1-133\u9000\u51fa\u7801\u5927\u5168&#xff1a;<\/span><\/h4>\n<table>\n<tr>\u9000\u51fa\u7801\u6807\u51c6\u542b\u4e49\u573a\u666f\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u901a\u7528\u672a\u77e5\u9519\u8bef<\/td>\n<td>\u811a\u672c \/ \u7a0b\u5e8f\u901a\u7528\u5931\u8d25&#xff0c;\u672a\u7ec6\u5206\u9519\u8bef\u7c7b\u578b&#xff08;\u6700\u5e38\u89c1&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>shell \u5185\u7f6e\u547d\u4ee4\u8bed\u6cd5\u9519\u8bef<\/td>\n<td>bash \u811a\u672c\u53c2\u6570\u3001\u8bed\u6cd5\u5199\u9519&#xff0c;\u547d\u4ee4\u4e0d\u5b58\u5728\u53c2\u6570<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u5185\u90e8\u6570\u636e\u6821\u9a8c\u5931\u8d25<\/td>\n<td>\u7a0b\u5e8f\u6570\u636e\u6821\u9a8c\u3001\u6587\u4ef6\u683c\u5f0f\u6821\u9a8c\u51fa\u9519<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>IO \u64cd\u4f5c\u5931\u8d25<\/td>\n<td>\u8bfb \/ \u5199\u6587\u4ef6\u3001\u7ba1\u9053 IO \u5f02\u5e38<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>\u7a0b\u5e8f\u81ea\u8eab\u521d\u59cb\u5316\u5931\u8d25<\/td>\n<td>\u914d\u7f6e\u52a0\u8f7d\u3001\u8d44\u6e90\u521d\u59cb\u5316\u5d29\u6e83<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>\u65e0\u6548\u6587\u4ef6\u53e5\u67c4 \/ \u63cf\u8ff0\u7b26<\/td>\n<td>\u64cd\u4f5c\u5df2\u5173\u95ed\u3001\u4e0d\u5b58\u5728\u7684 fd<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>\u547d\u4ee4\u6267\u884c\u5931\u8d25<\/td>\n<td>system\/exec \u8c03\u7528\u5916\u90e8\u547d\u4ee4\u8fd4\u56de\u5931\u8d25<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>\u5185\u5b58\u5206\u914d\u5931\u8d25<\/td>\n<td>malloc\/mmap \u7533\u8bf7\u5185\u5b58\u4e0d\u8db3<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>\u53c2\u6570\u6570\u91cf\u4e0d\u5339\u914d<\/td>\n<td>\u7a0b\u5e8f\u4f20\u5165\u547d\u4ee4\u884c\u53c2\u6570\u4e2a\u6570\u9519\u8bef<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>\u53c2\u6570\u683c\u5f0f\u975e\u6cd5<\/td>\n<td>\u53c2\u6570\u7c7b\u578b\u3001\u6570\u503c\u8303\u56f4\u4e0d\u7b26\u5408\u8981\u6c42<\/td>\n<\/tr>\n<tr>\n<td>11<\/td>\n<td>\u6570\u7ec4 \/ \u6307\u9488\u8d8a\u754c<\/td>\n<td>\u5e95\u5c42\u7a0b\u5e8f\u5185\u5b58\u8bbf\u95ee\u8d8a\u754c&#xff08;C\/C&#043;&#043; \u5e38\u89c1&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>12<\/td>\n<td>\u5916\u90e8\u7a0b\u5e8f\u8c03\u7528\u5931\u8d25<\/td>\n<td>\u5b50\u8fdb\u7a0b\u6267\u884c\u5916\u90e8\u5de5\u5177\u8fd4\u56de\u5f02\u5e38<\/td>\n<\/tr>\n<tr>\n<td>13<\/td>\n<td>\u6587\u4ef6\u4e0d\u53ef\u5199<\/td>\n<td>\u6743\u9650\u4e0d\u8db3\u3001\u53ea\u8bfb\u6587\u4ef6\u3001\u78c1\u76d8\u6ee1<\/td>\n<\/tr>\n<tr>\n<td>14<\/td>\n<td>\u6587\u4ef6\u4e0d\u53ef\u8bfb<\/td>\n<td>\u65e0\u8bfb\u6743\u9650\u3001\u6587\u4ef6\u635f\u574f\u3001\u4e0d\u5b58\u5728<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td>\u7ba1\u9053\u901a\u4fe1\u65ad\u5f00<\/td>\n<td>\u7ba1\u9053\u4e00\u7aef\u63d0\u524d\u5173\u95ed&#xff0c;SIGPIPE \u573a\u666f<\/td>\n<\/tr>\n<tr>\n<td>16<\/td>\n<td>\u76ee\u5f55\u8bbf\u95ee\u5931\u8d25<\/td>\n<td>cd\u3001opendir \u65e0\u6743\u9650\u6216\u76ee\u5f55\u4e0d\u5b58\u5728<\/td>\n<\/tr>\n<tr>\n<td>17<\/td>\n<td>\u6587\u4ef6\u5df2\u5b58\u5728<\/td>\n<td>\u521b\u5efa\u6587\u4ef6 \/ \u76ee\u5f55\u65f6\u76ee\u6807\u5df2\u5b58\u5728<\/td>\n<\/tr>\n<tr>\n<td>18<\/td>\n<td>\u6587\u4ef6\u4e0d\u5b58\u5728<\/td>\n<td>open\/stat \u627e\u4e0d\u5230\u6307\u5b9a\u8def\u5f84<\/td>\n<\/tr>\n<tr>\n<td>19<\/td>\n<td>\u8bbe\u5907\u4e0d\u5b58\u5728<\/td>\n<td>\u64cd\u4f5c\u786c\u4ef6\u8bbe\u5907\u3001\u4e32\u53e3\u3001\u78c1\u76d8\u8bbe\u5907\u4e22\u5931<\/td>\n<\/tr>\n<tr>\n<td>20<\/td>\n<td>\u5b50\u8fdb\u7a0b\u521b\u5efa\u5931\u8d25<\/td>\n<td>fork \u8c03\u7528\u5931\u8d25&#xff0c;\u8fdb\u7a0b\u6570\u4e0a\u9650<\/td>\n<\/tr>\n<tr>\n<td>21<\/td>\n<td>\u7528\u6237 \/ \u7ec4 ID \u65e0\u6548<\/td>\n<td>setuid\/setgid \u6307\u5b9a ID \u4e0d\u5b58\u5728<\/td>\n<\/tr>\n<tr>\n<td>22<\/td>\n<td>\u53c2\u6570\u8d85\u51fa\u5408\u6cd5\u8303\u56f4<\/td>\n<td>\u6570\u5b57\u53c2\u6570\u8fc7\u5927 \/ \u8fc7\u5c0f\u3001\u8d8a\u754c<\/td>\n<\/tr>\n<tr>\n<td>23<\/td>\n<td>\u6587\u4ef6\u8fc7\u5927<\/td>\n<td>\u6587\u4ef6\u5c3a\u5bf8\u8d85\u51fa\u7a0b\u5e8f\u5904\u7406\u4e0a\u9650<\/td>\n<\/tr>\n<tr>\n<td>24<\/td>\n<td>\u6253\u5f00\u6587\u4ef6\u6570\u8d85\u9650<\/td>\n<td>\u8d85\u8fc7\u8fdb\u7a0b ulimit \u6587\u4ef6\u53e5\u67c4\u9650\u5236<\/td>\n<\/tr>\n<tr>\n<td>25<\/td>\n<td>\u78c1\u76d8\u7a7a\u95f4\u8017\u5c3d<\/td>\n<td>\u5199\u5165\u65f6\u78c1\u76d8\u6ee1<\/td>\n<\/tr>\n<tr>\n<td>26<\/td>\n<td>\u6743\u9650\u4e0d\u8db3<\/td>\n<td>\u6267\u884c\u3001\u8bfb\u5199\u3001\u521b\u5efa\u6743\u9650\u5168\u90e8\u62d2\u7edd<\/td>\n<\/tr>\n<tr>\n<td>27<\/td>\n<td>\u6587\u4ef6\u7c7b\u578b\u4e0d\u5339\u914d<\/td>\n<td>\u9884\u671f\u666e\u901a\u6587\u4ef6&#xff0c;\u5b9e\u9645\u662f\u76ee\u5f55 \/ \u94fe\u63a5 \/ \u8bbe\u5907<\/td>\n<\/tr>\n<tr>\n<td>28<\/td>\n<td>\u94fe\u63a5\u6570\u91cf\u8d85\u9650<\/td>\n<td>\u6587\u4ef6\u786c\u94fe\u63a5\u8fbe\u5230\u7cfb\u7edf\u4e0a\u9650<\/td>\n<\/tr>\n<tr>\n<td>29<\/td>\n<td>\u8de8\u8bbe\u5907\u786c\u94fe\u63a5\u7981\u6b62<\/td>\n<td>\u4e0d\u80fd\u5bf9\u4e0d\u540c\u78c1\u76d8\u5206\u533a\u521b\u5efa\u786c\u94fe\u63a5<\/td>\n<\/tr>\n<tr>\n<td>30<\/td>\n<td>\u6587\u4ef6\u540d\u8fc7\u957f<\/td>\n<td>\u8def\u5f84 \/ \u6587\u4ef6\u540d\u8d85\u51fa\u7cfb\u7edf NAME_MAX \u9650\u5236<\/td>\n<\/tr>\n<tr>\n<td>31<\/td>\n<td>\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u5f02\u5e38<\/td>\n<td>signal \u6ce8\u518c\u3001\u4fe1\u53f7\u56de\u8c03\u6267\u884c\u51fa\u9519<\/td>\n<\/tr>\n<tr>\n<td>32~63<\/td>\n<td>\u7a0b\u5e8f\u81ea\u5b9a\u4e49\u4e1a\u52a1\u9519\u8bef<\/td>\n<td>\u65e0\u7edf\u4e00\u6807\u51c6&#xff0c;\u5404\u8f6f\u4ef6\u81ea\u884c\u5b9a\u4e49&#xff08;\u6570\u636e\u5e93\u3001\u4e2d\u95f4\u4ef6\u5e38\u7528&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>64<\/td>\n<td>EX_USAGE&#xff1a;\u547d\u4ee4\u53c2\u6570\u4f7f\u7528\u9519\u8bef<\/td>\n<td>POSIX \u6807\u51c6&#xff0c;\u53c2\u6570\u975e\u6cd5\u3001\u7f3a\u5931<\/td>\n<\/tr>\n<tr>\n<td>65<\/td>\n<td>EX_DATAERR&#xff1a;\u8f93\u5165\u6570\u636e\u683c\u5f0f\u9519\u8bef<\/td>\n<td>\u6587\u4ef6\u5185\u5bb9\u3001\u8f93\u5165\u6570\u636e\u635f\u574f\u3001\u683c\u5f0f\u4e0d\u5bf9<\/td>\n<\/tr>\n<tr>\n<td>66<\/td>\n<td>EX_NOINPUT&#xff1a;\u8f93\u5165\u6587\u4ef6\u65e0\u6cd5\u6253\u5f00<\/td>\n<td>\u6e90\u6587\u4ef6\u4e22\u5931\u3001\u65e0\u8bfb\u6743\u9650<\/td>\n<\/tr>\n<tr>\n<td>67<\/td>\n<td>EX_NOUSER&#xff1a;\u6307\u5b9a\u7528\u6237\u4e0d\u5b58\u5728<\/td>\n<td>\u7a0b\u5e8f\u6307\u5b9a\u8fd0\u884c\u7528\u6237 id \u65e0\u6548<\/td>\n<\/tr>\n<tr>\n<td>68<\/td>\n<td>EX_NOHOST&#xff1a;\u4e3b\u673a\u540d\u89e3\u6790\u5931\u8d25<\/td>\n<td>DNS \u89e3\u6790\u3001hostname \u627e\u4e0d\u5230<\/td>\n<\/tr>\n<tr>\n<td>69<\/td>\n<td>EX_UNAVAILABLE&#xff1a;\u670d\u52a1\u4e0d\u53ef\u7528<\/td>\n<td>\u4f9d\u8d56\u670d\u52a1\u672a\u542f\u52a8\u3001\u7aef\u53e3\u672a\u76d1\u542c<\/td>\n<\/tr>\n<tr>\n<td>70<\/td>\n<td>EX_SOFTWARE&#xff1a;\u7a0b\u5e8f\u5185\u90e8\u903b\u8f91\u9519\u8bef<\/td>\n<td>\u4ee3\u7801 bug\u3001\u65ad\u8a00\u5931\u8d25\u3001\u903b\u8f91\u5d29\u6e83<\/td>\n<\/tr>\n<tr>\n<td>71<\/td>\n<td>EX_OSERR&#xff1a;\u64cd\u4f5c\u7cfb\u7edf\u5e95\u5c42\u9519\u8bef<\/td>\n<td>\u7cfb\u7edf\u8c03\u7528\u5f02\u5e38\u3001\u5185\u6838\u8d44\u6e90\u6545\u969c<\/td>\n<\/tr>\n<tr>\n<td>72<\/td>\n<td>EX_OSFILE&#xff1a;\u7cfb\u7edf\u5173\u952e\u6587\u4ef6\u635f\u574f<\/td>\n<td>\/etc\/passwd\u3001lib \u5e93\u7f3a\u5931\u635f\u574f<\/td>\n<\/tr>\n<tr>\n<td>73<\/td>\n<td>EX_CANTCREAT&#xff1a;\u65e0\u6cd5\u521b\u5efa\u8f93\u51fa\u6587\u4ef6<\/td>\n<td>\u76ee\u5f55\u53ea\u8bfb\u3001\u6743\u9650\u3001\u78c1\u76d8\u6ee1<\/td>\n<\/tr>\n<tr>\n<td>74<\/td>\n<td>EX_IOERR&#xff1a;\u6587\u4ef6\u8bfb\u5199 IO \u786c\u4ef6\u9519\u8bef<\/td>\n<td>\u78c1\u76d8\u574f\u9053\u3001\u5b58\u50a8\u786c\u4ef6\u6545\u969c<\/td>\n<\/tr>\n<tr>\n<td>75<\/td>\n<td>EX_TEMPFAIL&#xff1a;\u4e34\u65f6\u53ef\u91cd\u8bd5\u9519\u8bef<\/td>\n<td>\u8d44\u6e90\u4e34\u65f6\u5360\u7528&#xff0c;\u7a0d\u540e\u53ef\u91cd\u8bd5<\/td>\n<\/tr>\n<tr>\n<td>76<\/td>\n<td>EX_PROTOCOL&#xff1a;\u7f51\u7edc\u534f\u8bae\u4ea4\u4e92\u9519\u8bef<\/td>\n<td>HTTP\/TCP\/ \u81ea\u5b9a\u4e49\u534f\u8bae\u63e1\u624b\u5931\u8d25<\/td>\n<\/tr>\n<tr>\n<td>77<\/td>\n<td>EX_NOPERM&#xff1a;\u6743\u9650\u4e25\u91cd\u4e0d\u8db3<\/td>\n<td>\u7cfb\u7edf\u7ea7\u64cd\u4f5c\u88ab\u5185\u6838\u62d2\u7edd<\/td>\n<\/tr>\n<tr>\n<td>78<\/td>\n<td>EX_CONFIG&#xff1a;\u7a0b\u5e8f\u914d\u7f6e\u6587\u4ef6\u9519\u8bef<\/td>\n<td>conf \u914d\u7f6e\u8bed\u6cd5\u3001\u53c2\u6570\u975e\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>79~127<\/td>\n<td>\u8f6f\u4ef6\u81ea\u5b9a\u4e49\u4e1a\u52a1\u7801<\/td>\n<td>\u5404\u7c7b\u5e94\u7528\u3001\u811a\u672c\u81ea\u5b9a\u4e49\u7ec6\u5206\u9519\u8bef<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9000\u51fa\u7801 128 ~ 133&#xff08;\u4fe1\u53f7\u6740\u6b7b\u8fdb\u7a0b&#xff1a;128 &#043; \u4fe1\u53f7\u7f16\u53f7&#xff09;<\/p>\n<table>\n<tr>\u9000\u51fa\u7801\u8ba1\u7b97\u516c\u5f0f\u5bf9\u5e94\u4fe1\u53f7\u4fe1\u53f7\u542b\u4e49 &amp; \u8fdb\u7a0b\u8868\u73b0<\/tr>\n<tbody>\n<tr>\n<td>128<\/td>\n<td>128 &#043; 0<\/td>\n<td>\u65e0<\/td>\n<td>\u6781\u5c11\u51fa\u73b0&#xff0c;\u4fe1\u53f7 0 \u4ec5\u68c0\u6d4b\u8fdb\u7a0b\u5b58\u6d3b&#xff0c;\u4e0d\u7ec8\u6b62\u7a0b\u5e8f<\/td>\n<\/tr>\n<tr>\n<td>129<\/td>\n<td>128 &#043; 1<\/td>\n<td>SIGHUP<\/td>\n<td>\u7ec8\u7aef\u65ad\u5f00\u3001\u4f1a\u8bdd\u9000\u51fa&#xff1b;\u5b88\u62a4\u8fdb\u7a0b\u6536\u5230\u5e38\u81ea\u52a8\u91cd\u542f<\/td>\n<\/tr>\n<tr>\n<td>130<\/td>\n<td>128 &#043; 2<\/td>\n<td>SIGINT<\/td>\n<td>Ctrl&#043;C \u624b\u52a8\u4e2d\u65ad\u7a0b\u5e8f&#xff0c;\u65e5\u5e38\u8c03\u8bd5\u6700\u5e38\u89c1<\/td>\n<\/tr>\n<tr>\n<td>131<\/td>\n<td>128 &#043; 3<\/td>\n<td>SIGQUIT<\/td>\n<td>Ctrl&#043;\\\\ \u9000\u51fa&#xff0c;\u7a0b\u5e8f\u4f1a\u751f\u6210 core dump \u6838\u5fc3\u8f6c\u50a8\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>132<\/td>\n<td>128 &#043; 4<\/td>\n<td>SIGILL<\/td>\n<td>\u975e\u6cd5\u6307\u4ee4&#xff0c;CPU \u65e0\u6cd5\u89e3\u6790\u4ee3\u7801&#xff0c;\u7a0b\u5e8f\u7f16\u8bd1 \/ \u5185\u5b58\u635f\u574f<\/td>\n<\/tr>\n<tr>\n<td>133<\/td>\n<td>128 &#043; 5<\/td>\n<td>SIGTRAP<\/td>\n<td>\u8c03\u8bd5\u65ad\u70b9\u89e6\u53d1&#xff08;gdb\/cgdb \u8c03\u8bd5\u5668\u65ad\u70b9\u4e2d\u65ad\u8fdb\u7a0b&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9000\u51fa\u7801&#xff1a;<\/p>\n<p>\u9000\u51fa\u7801\u662f\u544a\u8bc9\u6211\u4eec\u7a0b\u5e8f\u6700\u540e\u4e00\u6b21\u6267\u884c\u7684\u547d\u4ee4\u72b6\u6001&#xff0c; \u5728\u547d\u4ee4\u7ed3\u675f\u540e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u77e5\u9053\u547d\u4ee4\u662f\u6210\u529f\u5b8c\u6210\u8fd8\u662f\u9519\u8bef\u7684\u5f62\u5f0f\u8fdb\u884c\u7ed3\u675f&#xff0c; \u7a0b\u5e8f\u7684\u9000\u51fa\u7801\u4e3a0\u4ee3\u8868\u6210\u529f&#xff0c;\u6ca1\u6709\u4efb\u4f55\u7684\u95ee\u9898&#xff0c; \u4ee3\u7801\u4e3a1\u548c0\u4ee5\u5916\u7684\u4efb\u4f55\u9000\u51fa\u7801\u90fd\u89c6\u4e3a\u4e0d\u6210\u529f\u3002<\/p>\n<h4 id=\"Linux%20Shell%E4%B8%BB%E8%A6%81%E7%9A%84%E9%80%80%E5%87%BA%E7%A0%81%3A\"><span style=\"color:#fe2c24\">Linux Shell\u4e3b\u8981\u7684\u9000\u51fa\u7801:<\/span><\/h4>\n<p>\u57fa\u7840\u9000\u51fa\u7801&#xff1a;<\/p>\n<table>\n<tr>\u9000\u51fa\u7801\u542b\u4e49\u8bf4\u660e\u573a\u666f\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>0<\/td>\n<td>\u547d\u4ee4\u6267\u884c\u6210\u529f&#xff0c;\u65e0\u9519\u8bef<\/td>\n<td>ls\u3001cd\u3001echo \u6b63\u5e38\u8fd0\u884c<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>\u901a\u7528\u672a\u77e5\u9519\u8bef \/ \u4e00\u822c\u6027\u5931\u8d25<\/td>\n<td>\u547d\u4ee4\u8bed\u6cd5\u9519\u8bef\u3001\u666e\u901a\u8fd0\u884c\u5931\u8d25<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u5185\u7f6e\u547d\u4ee4\u53c2\u6570\u9519\u8bef\u3001\u975e\u6cd5\u53c2\u6570<\/td>\n<td>ls \u4f20\u5165\u65e0\u6548\u53c2\u6570\u3001\u811a\u672c\u4f20\u53c2\u683c\u5f0f\u9519\u8bef<\/td>\n<\/tr>\n<tr>\n<td>124<\/td>\n<td>\u547d\u4ee4\u8d85\u65f6&#xff08;timeout \u547d\u4ee4\u89e6\u53d1&#xff09;<\/td>\n<td>timeout 5 sleep 10<\/td>\n<\/tr>\n<tr>\n<td>125<\/td>\n<td>timeout \u81ea\u8eab\u6267\u884c\u5931\u8d25<\/td>\n<td>timeout \u4f20\u975e\u6cd5\u9009\u9879<\/td>\n<\/tr>\n<tr>\n<td>126<\/td>\n<td>\u627e\u5230\u6587\u4ef6&#xff0c;\u4f46\u65e0\u6267\u884c\u6743\u9650<\/td>\n<td>.\/test.sh \u4f46\u65e0 x \u6743\u9650<\/td>\n<\/tr>\n<tr>\n<td>127<\/td>\n<td>\u547d\u4ee4\u672a\u627e\u5230&#xff0c;\u4e0d\u5b58\u5728<\/td>\n<td>\u8f93\u5165\u4e0d\u5b58\u5728\u7684 abc123 \u547d\u4ee4<\/td>\n<\/tr>\n<tr>\n<td>128<\/td>\n<td>\u65e0\u6548\u9000\u51fa\u7801&#xff08;\u9000\u51fa\u53c2\u6570\u975e\u6570\u5b57&#xff09;<\/td>\n<td>exit abc<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4fe1\u53f7\u9000\u51fa\u7801<\/p>\n<p>\u8fdb\u7a0b\u88ab\u4fe1\u53f7\u7ec8\u6b62\u65f6&#xff0c;\u9000\u51fa\u7801 &#061; 128 &#043; \u4fe1\u53f7\u503c<\/p>\n<table>\n<tr>\u9000\u51fa\u7801\u5bf9\u5e94\u4fe1\u53f7\u4fe1\u53f7\u540d\u79f0\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>129<\/td>\n<td>1<\/td>\n<td>SIGHUP<\/td>\n<td>\u7ec8\u7aef\u65ad\u5f00\u3001\u4f1a\u8bdd\u6302\u65ad<\/td>\n<\/tr>\n<tr>\n<td>130<\/td>\n<td>2<\/td>\n<td>SIGINT<\/td>\n<td>Ctrl&#043;C \u4e2d\u65ad\u7a0b\u5e8f<\/td>\n<\/tr>\n<tr>\n<td>131<\/td>\n<td>3<\/td>\n<td>SIGQUIT<\/td>\n<td>Ctrl&#043;\\\\ \u9000\u51fa\u5e76\u751f\u6210 core<\/td>\n<\/tr>\n<tr>\n<td>134<\/td>\n<td>6<\/td>\n<td>SIGABRT<\/td>\n<td>\u7a0b\u5e8f\u4e3b\u52a8 abort \u5d29\u6e83<\/td>\n<\/tr>\n<tr>\n<td>137<\/td>\n<td>9<\/td>\n<td>SIGKILL<\/td>\n<td>kill -9 \u5f3a\u5236\u6740\u6b7b\u8fdb\u7a0b<\/td>\n<\/tr>\n<tr>\n<td>143<\/td>\n<td>15<\/td>\n<td>SIGTERM<\/td>\n<td>kill \u6b63\u5e38\u7ec8\u6b62\u8fdb\u7a0b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u811a\u672c\u81ea\u5b9a\u4e49\u9000\u51fa\u7801<\/p>\n<table>\n<tr>\u81ea\u5b9a\u4e49\u7801\u7ea6\u5b9a\u7528\u9014&#xff08;\u884c\u4e1a\u901a\u7528\u89c4\u8303&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>64<\/td>\n<td>\u547d\u4ee4\u884c\u53c2\u6570\u4f7f\u7528\u9519\u8bef&#xff08;\u6807\u51c6 POSIX&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>65<\/td>\n<td>\u8f93\u5165\u6587\u4ef6\u4e0d\u5b58\u5728 \/ \u8bfb\u53d6\u5931\u8d25<\/td>\n<\/tr>\n<tr>\n<td>66<\/td>\n<td>\u8f93\u51fa\u6587\u4ef6\u65e0\u6cd5\u5199\u5165\u3001\u6743\u9650\u4e0d\u8db3<\/td>\n<\/tr>\n<tr>\n<td>69<\/td>\n<td>\u670d\u52a1 \/ \u7a0b\u5e8f\u4e0d\u53ef\u7528<\/td>\n<\/tr>\n<tr>\n<td>70<\/td>\n<td>\u5185\u90e8\u811a\u672c\u5f02\u5e38<\/td>\n<\/tr>\n<tr>\n<td>77<\/td>\n<td>\u6743\u9650\u4e0d\u8db3\u65e0\u6cd5\u8bbf\u95ee\u914d\u7f6e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u4eec\u4e5f\u80fd\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u6765\u51fa\u73b0\u9519\u8bef\u7801\u201c2\u201d\u53f7&#xff1a;<\/p>\n<p>\u6211\u4eec\u80fd\u770b\u5230\u6211\u5df2\u8bfb\u7684\u5f62\u5f0f\u8fdb\u884c\u6253\u5f00&#xff0c; \u8be5\u6587\u4ef6\u4e0d\u5b58\u5728\u8fd9\u4e2a\u76ee\u5f55\u6240\u4ee5\u4f1a\u5931\u8d25\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;errno.h&gt;<\/p>\n<p>int main() {<\/p>\n<p>    FILE* fp&#061;fopen(&#034;add.txt&#034;,&#034;r&#034;);<\/p>\n<p>    if(fp&#061;&#061;NULL) return errno;<br \/>\n    \/\/\u6587\u4ef6\u6b63\u5e38<br \/>\n    \/\/&#8230;<br \/>\n    return 0;<br \/>\n} <\/p>\n<p>\u90a3\u4e48\u5c31\u4f1a\u8fd4\u56deerrno&#xff0c;\u8fd9\u4e2a\u51fd\u6570\u4e0b\u9762\u8fdb\u884c\u4e86\u5bf9\u5e94\u7684\u8bb2\u89e3\u3002\u4ed6\u5c31\u4f1a\u8fd4\u56de2\u8be5\u6587\u4ef6\u4e0d\u5b58\u5728\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"96\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065825-6a6af611c2b32.png\" width=\"1062\" \/><\/p>\n<h4 id=\"errno%EF%BC%9A%E8%8E%B7%E5%8F%96%E8%BF%9B%E7%A8%8B%E7%BB%93%E6%9D%9F%E7%9A%84%E9%94%99%E8%AF%AF%E7%A0%81\"><span style=\"color:#fe2c24\">errno&#xff1a;\u83b7\u53d6\u8fdb\u7a0b\u7ed3\u675f\u7684\u9519\u8bef\u7801<\/span><\/h4>\n<p>man 3 errno <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1209\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065825-6a6af611db50a.png\" width=\"2520\" \/><\/p>\n<h3 id=\"%E8%BF%9B%E7%A8%8B%E9%80%80%E5%87%BA%E7%9A%84%E5%B8%B8%E8%A7%81%E6%96%B9%E6%B3%95%EF%BC%9A\"><span style=\"color:#fe2c24\">\u8fdb\u7a0b\u9000\u51fa\u7684\u5e38\u89c1\u65b9\u6cd5&#xff1a;<\/span><\/h3>\n<h4 id=\"1.main%E5%87%BD%E6%95%B0%E8%BF%9B%E8%A1%8C%E8%BF%94%E5%9B%9E\"><span style=\"color:#fe2c24\">1.main\u51fd\u6570\u8fdb\u884c\u8fd4\u56de<\/span><\/h4>\n<p><span style=\"color:#ff9900\">\u7ecf\u8fc7\u4e0a\u9762\u7684\u6f14\u793a\u6211\u4eec\u77e5\u9053\u4e86\u6211\u4eec\u7684main\u51fd\u6570\u53ef\u4ee5\u901a\u8fc7return\u8fdb\u884c\u8fd4\u56de\u9000\u51fa\u7801&#xff0c;\u8fd9\u4e2a\u9000\u51fa\u7801\u53ef\u4ee5\u88ab\u6211\u4eec\u81ea\u5df1\u8bbe\u7f6e&#xff0c; \u4e5f\u53ef\u901a\u8fc7errno\u7684\u65b9\u5f0f\u6765\u8fdb\u884c\u8ba9os\u6765\u8fdb\u884c\u5bf9\u5e94\u7684\u8bbe\u7f6e\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"411\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065827-6a6af61328552.png\" width=\"1002\" \/><\/p>\n<h4 id=\"2.%20%E8%B0%83%E7%94%A8exit%EF%BC%88%E6%98%AFC%E8%AF%AD%E8%A8%80%E6%96%B9%E5%90%91%E7%9A%84%E6%8E%A5%E5%8F%A3%EF%BC%89\"><span style=\"color:#fe2c24\">2. \u8c03\u7528exit&#xff08;\u662fC\u8bed\u8a00\u65b9\u5411\u7684\u63a5\u53e3&#xff09;<\/span><\/h4>\n<p>\u6211\u4eec\u5728\u4f7f\u7528\u4e4b\u524d\u5148\u770b\u4e00\u4e0b\u5bf9\u5e94\u7684\u6587\u6863\u3002<\/p>\n<p>man exit<\/p>\n<p>\u4ed6\u7684\u4f5c\u7528\u4e3b\u8981\u662f\u8fd4\u56de\u9000\u51fa\u7801&#xff0c; \u548creturn\u7684\u64cd\u4f5c\u51e0\u4e4e\u662f\u4e00\u6837\u7684<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1191\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065827-6a6af613500ec.png\" width=\"2550\" \/><\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e00\u4e0b&#xff1a;<\/p>\n<p>\u6211\u4eec\u80fd\u53d1\u73b0\u548creturn\u7684\u64cd\u4f5c\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;errno.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<br \/>\nint main()<br \/>\n{<br \/>\n    FILE* fp &#061; fopen(&#034;add.txt&#034;,&#034;r&#034;);<br \/>\n    if(fp&#061;&#061;NULL) exit(1);<br \/>\n    \/\/&#8230;\u6587\u4ef6\u6b63\u5e38\u88ab\u6253\u5f00<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"903\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065828-6a6af614904ac.png\" width=\"1014\" \/><\/p>\n<h4 id=\"3.%20_exit%EF%BC%88%E7%B3%BB%E7%BB%9F%E7%BA%A7%E5%88%AB%E7%9A%84%E6%8E%A5%E5%8F%A3%EF%BC%89\"><span style=\"color:#fe2c24\">3. _exit&#xff08;\u7cfb\u7edf\u7ea7\u522b\u7684\u63a5\u53e3&#xff09;<\/span><\/h4>\n<p>man _exit <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1190\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065828-6a6af614cca84.png\" width=\"2541\" \/><\/p>\n<p>\u6211\u4eec\u540c\u6837\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u4ee3\u7801\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n<p>\u6211\u4eec\u53d1\u73b0\u548c\u4e0a\u9762\u7684\u64cd\u4f5c\u51e0\u4e4e\u662f\u4e00\u6a21\u4e00\u6837\u3002\u5f53\u7136\u4ed6\u4eec\u80af\u5b9a\u7531\u4e0d\u4e00\u6837\u7684\u5730\u65b9\u3002\u6211\u4eec\u4e0b\u9762\u5c31\u4ecb\u7ecd\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;errno.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<br \/>\n#include&lt;unistd.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    FILE* fp &#061; fopen(&#034;add.txt&#034;,&#034;r&#034;);<br \/>\n    if(fp&#061;&#061;NULL) _exit(1);<br \/>\n    \/\/&#8230;\u6587\u4ef6\u6b63\u5e38\u88ab\u6253\u5f00<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"957\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065829-6a6af615e71cb.png\" width=\"1359\" \/><\/p>\n<h4 id=\"_exit%20vs%20exit%3A\"><span style=\"color:#fe2c24\">_exit vs exit:<\/span><\/h4>\n<p>\u6211\u4eec\u901a\u8fc7\u4e24\u4e2a\u4ee3\u7801\u6765\u8fdb\u884c\u67e5\u770b&#xff1a;<\/p>\n<p>\u6ce8\u610f&#xff1a;\u8fd9\u91cc\u6587\u5b57\u4e0d\u4f7f\u7528\u201d\\\\n\u201c&#xff0c;\u56e0\u4e3a\\\\n\u4f1a\u5237\u65b0\u5bf9\u5e94\u7684\u7f13\u51b2\u533a\u3002<\/p>\n<p>\u6211\u4eec\u80fd\u770b\u5230exit\u662f\u5237\u65b0\u4e86\u5bf9\u5e94\u7684\u7f13\u51b2\u533a\u7684\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    printf(&#034;\u8fd9\u662f\u4e00\u4e32\u6587\u5b57&#034;);<br \/>\n    exit(1);<br \/>\n    return 0;<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"555\" src=\"2026-07-30hdom41g1dqe.png\" width=\"839\" \/><\/p>\n<p>\u6211\u4eec\u518d\u770b\u770b_exit\u5462&#xff1f;<\/p>\n<p>\u6211\u4eec\u80fd\u770b\u5230\u5bf9\u5e94\u7684\u6ca1\u6253\u5370\u51fa\u6765\u6587\u5b57\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;errno.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\nint main()<br \/>\n{<br \/>\n    printf(&#034;\u8fd9\u662f\u4e00\u4e32\u6587\u5b57&#034;);<br \/>\n    _exit(1);<br \/>\n    return 0;<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"579\" src=\"2026-07-304beqyjyagoj.png\" width=\"834\" \/><\/p>\n<p>\u7ed3\u8bba&#xff1a;\u8fd9\u91ccexit\u548c_exit\u7684\u4e3b\u8981\u533a\u522b\u662f\u4e00\u4e2a\u5237\u65b0\u4e86\u7f13\u51b2\u533a\u4e00\u4e2a\u6ca1\u6709\u8fdb\u884c\u5237\u65b0\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u77e5\u9053<span style=\"color:#fe2c24\">\u7f13\u51b2\u533a<\/span>\u662fc\u8bed\u8a00\u7684\u5e76\u4e0d\u662fOS\u7684&#xff0c; \u5982\u679c\u662fOS\u7684\u90a3\u4e48_exit\u4e5f\u4f1a\u5237\u65b0\u7684\u3002\u6240\u4ee5\u7f13\u51b2\u533a\u662fOS\u7ea7\u522b\u7684\u6982\u5ff5\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"396\" src=\"2026-07-30ecf1e3i1kjm.png\" width=\"335\" \/><\/p>\n<h4 id=\"%E8%BF%9B%E9%98%B6%E4%BA%86%E8%A7%A3exit%20and%20_exit(1)\"><span style=\"color:#fe2c24\">\u8fdb\u9636\u4e86\u89e3exit and _exit(1)<\/span><\/h4>\n<p>\u901a\u8fc7\u4e0b\u9762\u7684\u4ee3\u7801\u6211\u4eec\u53ef\u4ee5\u77e5\u9053exit\u662f\u76f4\u63a5\u6740\u6b7b\u8fdb\u7a0b\u7684\u3002\u5411\u6211\u4eec\u7684return\u5728\u51fd\u6570\u5185\u90e8\u53ea\u662f\u7ed3\u675f\u8fd9\u4e2a\u51fd\u6570\u800c\u4e0d\u662f\u7ed3\u675f\u8fd9\u4e2a\u8fdb\u7a0b\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;errno.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\nvoid add()<br \/>\n{<br \/>\n    _exit(1);<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\n    add();<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"969\" src=\"2026-07-30g3w2glyzxs3.png\" width=\"1140\" \/><\/p>\n<h2 id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E7%AD%89%E5%BE%85%EF%BC%9A\"><span style=\"color:#fe2c24\">\u8fdb\u7a0b\u7684\u7b49\u5f85&#xff1a;<\/span><\/h2>\n<h3 id=\"%E8%BF%9B%E7%A8%8B%E7%AD%89%E5%BE%85%E5%BF%85%E8%A6%81%E6%80%A7\" style=\"background-color:transparent\"><span style=\"color:#fe2c24\">\u8fdb\u7a0b\u7b49\u5f85\u5fc5\u8981\u6027<\/span><\/h3>\n<p><span style=\"color:#1c7892\">&#8211; \u4e4b\u524d\u8bb2\u8fc7&#xff0c;\u5b50\u8fdb\u7a0b\u9000\u51fa&#xff0c;\u7236\u8fdb\u7a0b\u5982\u679c\u4e0d\u7ba1\u4e0d\u987e&#xff0c;\u5c31\u53ef\u80fd\u9020\u6210\u2018\u50f5\u5c38\u8fdb\u7a0b\u2019\u7684\u95ee\u9898&#xff0c;\u8fdb\u800c\u9020\u6210\u5185\u5b58\u6cc4\u6f0f\u3002 <\/span><\/p>\n<p><span style=\"color:#1c7892\">&#8211; \u53e6\u5916&#xff0c;\u8fdb\u7a0b\u4e00\u65e6\u53d8\u6210\u50f5\u5c38\u72b6\u6001&#xff0c;\u90a3\u5c31\u5200\u67aa\u4e0d\u5165&#xff0c;\u201c\u6740\u4eba\u4e0d\u7728\u773c\u201d\u7684kill -9 \u4e5f\u65e0\u80fd\u4e3a\u529b&#xff0c;\u56e0\u4e3a\u8c01\u4e5f\u6ca1\u6709\u529e\u6cd5\u6740\u6b7b\u4e00\u4e2a\u5df2\u7ecf\u6b7b\u53bb\u7684\u8fdb\u7a0b\u3002 <\/span><\/p>\n<p><span style=\"color:#1c7892\">&#8211; \u6700\u540e&#xff0c;\u7236\u8fdb\u7a0b\u6d3e\u7ed9\u5b50\u8fdb\u7a0b\u7684\u4efb\u52a1\u5b8c\u6210\u7684\u5982\u4f55&#xff0c;\u6211\u4eec\u9700\u8981\u77e5\u9053\u3002\u5982&#xff0c;\u5b50\u8fdb\u7a0b\u8fd0\u884c\u5b8c\u6210&#xff0c;\u7ed3\u679c\u5bf9\u8fd8\u662f\u4e0d\u5bf9&#xff0c;\u6216\u8005\u662f\u5426\u6b63\u5e38\u9000\u51fa\u3002<\/span><\/p>\n<p><span style=\"color:#1c7892\">&#8211; \u7236\u8fdb\u7a0b\u901a\u8fc7\u8fdb\u7a0b\u7b49\u5f85\u7684\u65b9\u5f0f&#xff0c;\u56de\u6536\u5b50\u8fdb\u7a0b\u8d44\u6e90&#xff0c;\u83b7\u53d6\u5b50\u8fdb\u7a0b\u9000\u51fa\u4fe1\u606f<\/span><\/p>\n<h3 id=\"%E8%BF%9B%E7%A8%8B%E7%AD%89%E5%BE%85%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%9A\"><span style=\"color:#fe2c24\">\u8fdb\u7a0b\u7b49\u5f85\u7684\u65b9\u6cd5&#xff1a;<\/span><\/h3>\n<p>\u8fd9\u91cc\u63d0\u4f9b\u4e24\u4e2a\u7cfb\u7edf\u65b9\u9762\u7684\u63a5\u53e3<\/p>\n<p>\u4e00\u4e2a\u662fwait\u4e00\u4e2a\u662fwaitpid<\/p>\n<p>\u6211\u4eec\u67e5\u4e00\u4e0b\u5bf9\u5e94\u7684\u6587\u6863<\/p>\n<p>man wait <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1203\" src=\"2026-07-30ln32fvc0kvf.png\" width=\"2532\" \/><\/p>\n<p>\u4ed6\u4eec\u7684\u8fd4\u56de\u503c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"297\" src=\"2026-07-30uehyrmzdcbl.png\" width=\"2478\" \/><\/p>\n<h5 id=\"wait%EF%BC%88%EF%BC%89\"><span style=\"color:#fe2c24\">wait&#xff08;&#xff09;<\/span><\/h5>\n<p><span style=\"color:#fe2c24\">\u8fd4\u56de\u503c&#xff1a;<\/span><\/p>\n<p><span style=\"color:null\">\u6210\u529f\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684id&#xff0c; \u5931\u8d25\u8fd4\u56de-1<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"36\" src=\"2026-07-30anbznhvhu3w.png\" width=\"1563\" \/><\/p>\n<p>\u53c2\u6570\u662f\u4e00\u4e2a\u8f93\u51fa\u578b\u53c2\u6570&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"234\" src=\"2026-07-304w5c1fpi0y3.png\" width=\"2502\" \/><\/p>\n<p>\u7b2c\u4e00\u4e2aWIFEXITED&#xff08;wifexited&#xff09;&#xff1a;\u82e5\u4e3a\u6b63\u5e38\u7684\u7ed3\u675f\u72b6\u6001&#xff0c;\u5219\u4e3a\u771f(\u67e5\u770b\u8fdb\u7a0b\u662f\u5426\u6b63\u5e38\u7684\u9000\u51fa)<\/p>\n<p>WEXITSTATUS&#xff1a;\u67e5\u770b\u8fdb\u7a0b\u7684\u9000\u51fa\u7801\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528NULL&#xff1a; \u8868\u793a\u5bf9\u9000\u51fa\u7801\u4e0d\u5173\u5fc3\u3002<\/p>\n<p>\u4f7f\u7528&#xff1a;<\/p>\n<p>while :;do ps axj | head -1 &amp;&amp; ps axj |grep test; sleep 1;done <\/p>\n<p>\u6211\u4eec\u80fd\u53d1\u73b0\u4e0b\u9762\u7684\u89c4\u5f8b\u6211\u4eec\u521a\u5f00\u59cb\u5b50\u8fdb\u7a0b\u4e00\u76f4\u5728\u8dd1&#xff0c;\u6211\u4eec\u5bf9\u5e94\u7684\u7236\u8fdb\u7a0b\u6ca1\u6709\u591a\u5c11\u4ee3\u7801\u5e94\u8be5\u65e9\u5c31\u7ed3\u675f\u4e86&#xff0c;\u53ef\u662f\u6211\u4eec\u5728shell\u4e2d\u67e5\u770b\u4ed6\u4e00\u76f4\u5904\u4e8e\u6302\u8d77\u72b6\u6001\u3002\u6240\u4ee5\u5b50\u8fdb\u7a0b\u6ca1\u6709\u8fdb\u5165\u50f5\u5c38&#xff0c;\u800c\u662f\u7236\u8fdb\u7a0b\u4e00\u76f4\u7b49\u5f85\u5b50\u8fdb\u7a0b\u7ed3\u675f&#xff0c;\u5c06\u5b50\u8fdb\u7a0b\u8fdb\u884c\u56de\u6536\u3002<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if(pi &#061;&#061; 0)<br \/>\n    {<br \/>\n        \/\/\u5b50\u8fdb\u7a0b<br \/>\n        int cnt&#061;5;<br \/>\n        while(cnt&#8211;)<br \/>\n        {<br \/>\n            printf(&#034;\u6211\u662f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6211\u7684\u7236\u4eb2\u7684id:%d,\u6211\u7684id\u662f%d \\\\n&#034;,getppid(),getpid());<br \/>\n        }<br \/>\n        sleep(10);<br \/>\n    }<\/p>\n<p>    else if (pi &gt;0)<br \/>\n    {<br \/>\n        \/\/\u7236\u8fdb\u7a0b<br \/>\n        wait(NULL);<br \/>\n    }<\/p>\n<p>    else<br \/>\n    {<br \/>\n        \/\/\u51fa\u73b0\u5f02\u5e38<br \/>\n        printf(&#034;error fail!&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    return 0;<\/p>\n<p>}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1065\" src=\"2026-07-30qmn2ckq1ye1.png\" width=\"2127\" \/><\/p>\n<p>wait\u5931\u8d25\u7684\u60c5\u51b5&#xff1a;<\/p>\n<p>1.\u6ca1\u6709\u5b50\u8fdb\u7a0b\u3002<\/p>\n<p>2.id\u4e0d\u5b58\u5728\u3002<\/p>\n<p>\u6709\u53c2\u6570\u7684\u60c5\u51b5<\/p>\n<p>\u5177\u4f53\u7684status&gt;&gt;8\u5230\u540e\u9762\u5728\u8fdb\u884c\u8bb2\u89e3\u3002<\/p>\n<p>1.\u5199\u6cd5\u4e00&#xff1a;\u4f4d\u8fd0\u7b97<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if(pi &#061;&#061; 0)<br \/>\n    {<br \/>\n        \/\/\u5b50\u8fdb\u7a0b<br \/>\n        int cnt&#061;5;<br \/>\n        while(cnt&#8211;)<br \/>\n        {<br \/>\n            printf(&#034;\u6211\u662f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6211\u7684\u7236\u4eb2\u7684id:%d,\u6211\u7684id\u662f%d \\\\n&#034;,getppid(),getpid());<br \/>\n        }<br \/>\n        sleep(10);<br \/>\n    }<\/p>\n<p>    else if (pi &gt;0)<br \/>\n    {<br \/>\n        \/\/\u7236\u8fdb\u7a0b<br \/>\n        int status &#061;0 ;<br \/>\n        wait(&amp;status);<br \/>\n        printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, (status&gt;&gt;8)&amp;0XFF);<br \/>\n    }<\/p>\n<p>    else<br \/>\n    {<br \/>\n        \/\/\u51fa\u73b0\u5f02\u5e38<br \/>\n        printf(&#034;error fail!&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    return 0;<\/p>\n<p>}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1254\" src=\"2026-07-30vruuxjrp2x4.png\" width=\"1431\" \/><\/p>\n<p>2.\u5199\u6cd5\u4e8c&#xff1a;\u91c7\u7528\u8f93\u51fa\u578b\u53c2\u6570<\/p>\n<p>\u8fd9\u91cc\u7684\u8f93\u51fa\u578b\u53c2\u6570\u5c31\u4ee3\u8868\u5c06\u4ed6\u8fdb\u884c\u624b\u52a8\u7684\u8f6c\u5316\u3002\u6210\u5bf9\u5e94\u7684\u9000\u51fa\u7801&#xff0c;\u8fd9\u4e0e\u9000\u51fa\u7801\u7684\u5b58\u50a8\u6709\u5173&#xff0c;\u8fd9\u4e2a\u5b58\u50a8\u4e00\u4f1a\u4f1a\u8be6\u7ec6\u7684\u7ed9\u4f60\u8fdb\u884c\u4ecb\u7ecd\u3002<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if(pi &#061;&#061; 0)<br \/>\n    {<br \/>\n        \/\/\u5b50\u8fdb\u7a0b<br \/>\n        int cnt&#061;5;<br \/>\n        while(cnt&#8211;)<br \/>\n        {<br \/>\n            printf(&#034;\u6211\u662f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6211\u7684\u7236\u4eb2\u7684id:%d,\u6211\u7684id\u662f%d \\\\n&#034;,getppid(),getpid());<br \/>\n        }<br \/>\n        sleep(10);<br \/>\n    }<\/p>\n<p>    else if (pi &gt;0)<br \/>\n    {<br \/>\n        \/\/\u7236\u8fdb\u7a0b<br \/>\n        int status &#061;0;<br \/>\n        wait(&amp;status);<br \/>\n        printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n    }<\/p>\n<p>    else<br \/>\n    {<br \/>\n        \/\/\u51fa\u73b0\u5f02\u5e38<br \/>\n        printf(&#034;error fail!&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    return 0;<\/p>\n<p>} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1361\" src=\"2026-07-30d1qs4e3jpen.png\" width=\"1494\" \/><\/p>\n<h5 id=\"waitpid()\">waitpid()<\/h5>\n<p>\u8fd4\u56de\u503c&#xff1a;<\/p>\n<p>waitpid()&#xff1a;\u8c03\u7528\u6210\u529f\u65f6&#xff0c;\u8fd4\u56de\u72b6\u6001\u53d1\u751f\u53d8\u5316\u7684\u5b50\u8fdb\u7a0b PID&#xff1b; \u82e5\u53c2\u6570\u4e2d\u6307\u5b9a\u4e86 WNOHANG \u975e\u963b\u585e\u6807\u5fd7&#xff0c;\u4e14\u5b58\u5728\u5339\u914d pid \u7684\u5b50\u8fdb\u7a0b&#xff0c;\u4f46\u8be5\u5b50\u8fdb\u7a0b\u72b6\u6001\u5c1a\u672a\u53d1\u751f\u6539\u53d8&#xff0c;\u5219\u8fd4\u56de 0&#xff1b; \u8c03\u7528\u51fa\u9519\u65f6&#xff0c;\u8fd4\u56de -1\u3002<\/p>\n<p>\u53c2\u6570&#xff1a;<\/p>\n<p>\u8fd9\u91ccwaitpid\u6709\u4e09\u4e2a\u53c2\u6570<\/p>\n<p> pid_t waitpid(pid_t pid, int *wstatus, int options); <\/p>\n<p>pid:<\/p>\n<p>\u00a0 \u00a0pid&#061;&#061;-1 \u4ee3\u8868\u7b49\u5f85\u4efb\u610f\u4e00\u4e2a\u5b50\u8fdb\u7a0b&#xff0c; \u4e0ewait\u7b49\u6548<\/p>\n<p>\u00a0 \u00a0pid&gt;0 \u4ee3\u8868\u7b49\u5f85\u4e0e\u8fdb\u7a0b\u7684pid\u76f8\u7b49\u7684\u8fdb\u7a0b\u7684\u3002<\/p>\n<p>wstatus&#xff1a;<\/p>\n<p>\u00a0 \u00a0 \u4e0ewait\u7684status\u76f8\u540c\u3002<\/p>\n<p>\u00a0 \u00a0 \u7b2c\u4e00\u4e2aWIFEXITED&#xff08;wifexited&#xff09;&#xff1a;\u82e5\u4e3a\u6b63\u5e38\u7684\u7ed3\u675f\u72b6\u6001&#xff0c;\u5219\u4e3a\u771f(\u67e5\u770b\u8fdb\u7a0b\u662f\u5426\u6b63\u5e38\u7684\u9000\u51fa)<\/p>\n<p>\u00a0 \u00a0 WEXITSTATUS&#xff1a;\u67e5\u770b\u8fdb\u7a0b\u7684\u9000\u51fa\u7801\u3002<\/p>\n<p>\u00a0 \u00a0 \u4e5f\u53ef\u4ee5\u4f7f\u7528NULL&#xff1a; \u8868\u793a\u5bf9\u9000\u51fa\u7801\u4e0d\u5173\u5fc3\u3002<\/p>\n<p>options:&#xff08;\u540e\u9762\u4f1a\u8be6\u89e3\u8fdb\u884c\u963b\u585e\u7b49\u5f85\u548c\u4e0d\u963b\u585e\u7b49\u5f85\u7684&#xff09;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u9ed8\u8ba4\u662f0&#xff0c;\u8868\u793a\u963b\u585e\u7b49\u5f85\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0\u00a0WNOHANG &#xff1a;\u82e5\u5b50\u8fdb\u7a0b\u7684pid\u6ca1\u6709\u7ed3\u675f&#xff0c;\u4e0d\u4e0e\u7b49\u5f85&#xff0c; \u6b63\u5e38\u7ed3\u675f&#xff0c; \u5219\u8fd4\u56de\u5b50\u8fdb\u7a0b\u7684pid\u3002<\/p>\n<p>\u7b49\u5f85\u6211\u4eec\u7684id\u4e3api\u7684\u8fdb\u7a0b&#xff0c;\u8fd0\u884c\u5b8c\u8fdb\u884c\u56de\u6536\u3002<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if(pi &#061;&#061; 0)<br \/>\n    {<br \/>\n        \/\/\u5b50\u8fdb\u7a0b<br \/>\n        int cnt&#061;5;<br \/>\n        while(cnt&#8211;)<br \/>\n        {<br \/>\n            printf(&#034;\u6211\u662f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6211\u7684\u7236\u4eb2\u7684id:%d,\u6211\u7684id\u662f%d \\\\n&#034;,getppid(),getpid());<br \/>\n        }<br \/>\n        sleep(10);<br \/>\n    }<\/p>\n<p>    else if (pi &gt;0)<br \/>\n    {<br \/>\n        \/\/\u7236\u8fdb\u7a0b<br \/>\n        \/\/ int status &#061;0;<br \/>\n        \/\/ wait(&amp;status);<br \/>\n        \/\/ printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n        int status &#061;0;<br \/>\n        waitpid(pi, &amp;status, 0);\/\/\u4e0d\u8fdb\u884c\u963b\u585e\u7b49\u5f85<br \/>\n        printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n    }<\/p>\n<p>    else<br \/>\n    {<br \/>\n        \/\/\u51fa\u73b0\u5f02\u5e38<br \/>\n        printf(&#034;error fail!&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    return 0;<\/p>\n<p>} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1317\" src=\"2026-07-30bbem0nrzp12.png\" width=\"1605\" \/><\/p>\n<p>\u603b\u7ed3&#xff1a;<\/p>\n<ul>\n<li>\u5982\u679c\u5b50\u8fdb\u7a0b\u5df2\u7ecf\u9000\u51fa&#xff0c;\u8c03\u7528 wait\/waitpid \u65f6&#xff0c;wait\/waitpid \u4f1a\u7acb\u5373\u8fd4\u56de&#xff0c;\u5e76\u4e14\u91ca\u653e\u8d44\u6e90&#xff0c;\u83b7\u5f97\u5b50\u8fdb\u7a0b\u9000\u51fa\u4fe1\u606f\u3002<\/li>\n<li>\u5982\u679c\u5728\u4efb\u610f\u65f6\u523b\u8c03\u7528 wait\/waitpid&#xff0c;\u5b50\u8fdb\u7a0b\u5b58\u5728\u4e14\u6b63\u5e38\u8fd0\u884c&#xff0c;\u5219\u8fdb\u7a0b\u53ef\u80fd\u963b\u585e\u3002<\/li>\n<li>\u5982\u679c\u4e0d\u5b58\u5728\u8be5\u5b50\u8fdb\u7a0b&#xff0c;\u5219\u7acb\u5373\u51fa\u9519\u8fd4\u56de\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"254\" src=\"2026-07-30afu4oiqlxzb.png\" width=\"448\" \/><\/p>\n<h3 id=\"%E8%8E%B7%E5%8F%96%E5%AD%90%E8%BF%9B%E7%A8%8B%E7%9A%84status%EF%BC%88%E8%AF%A6%E7%BB%86%EF%BC%8C%E7%AE%80%E5%8D%95%E6%98%93%E6%87%82%EF%BC%89\"><span style=\"color:#fe2c24\">\u83b7\u53d6\u5b50\u8fdb\u7a0b\u7684status&#xff08;\u8be6\u7ec6&#xff0c;\u7b80\u5355\u6613\u61c2&#xff09;<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u6211\u4eec\u4e4b\u524d\u770b\u8fc7\u6211\u4eec\u7684status\u662f\u4e00\u4e2aint\u7c7b\u578b\u7684\u53d8\u91cf\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u6211\u4eec\u4e00\u4e2aint\u662f4\u4e2abyte&#xff0c;1\u4e2abyte\u662f8\u4e2a\u6bd4\u7279\u4f4d\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u5bf9\u5e94\u7684\u6211\u4eec\u7684int\u662f4&#215;8&#061;32\u4e2a\u6bd4\u7279\u4f4d\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u8fd9\u91cc\u6211\u4eec\u7684status\u4e8c\u8fdb\u5236&#xff1a;<\/span><\/p>\n<p><span style=\"color:#0d0016\">0000 0000 0000 0000 0000 0000 0000 0000\u00a0<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u8fd9\u91cc\u6211\u4eec\u7684\u524d16\u4f4d\u5f03\u800c\u4e0d\u7528\u3002\u4e0d\u5b58\u4efb\u4f55\u7684\u4e1c\u897f\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u6211\u4eec\u7684\u540e16\u4f4d&#xff08;15-8&#xff09;\u4e2d\u7684\u6b21\u524d8\u4f4d\u5b58\u9000\u51fa\u7801&#xff0c;\u5269\u4f59\u76848\u4f4d\u5b58\u4fe1\u53f7\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u6211\u4eec\u7ed9\u51fa\u7684\u4fe1\u53f7\u662f\u5728\u9000\u51fa\u7801\u7684\u5730\u65b9&#xff0c;\u5982\u679c\u6211\u4eec\u8fdb\u7a0b\u9000\u51fa\u7801\u662f1&#xff0c;\u90a3\u4e48\u5b83\u5bf9\u5e94\u7684status\u662f&#xff1a;<\/span><\/p>\n<p><span style=\"color:#0d0016\">0000 0000 0000 0000\u00a00000 0001\u00a00000 0000<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u6211\u4eec\u60f3\u8981\u5f97\u5230\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u8981\u5c06\u6211\u4eec\u7684status&gt;&gt;8\u4f4d&#xff0c;\u7136\u540e&amp;\u4e0a0XFF\u53d6\u51fa\u524d8\u4f4d\u5373\u53ef\u3002\u00a0<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u8fd9\u91cc\u7684\u4fe1\u53f7\u6211\u4eec\u4f1a\u5728\u540e\u7eed\u7684\u8fdb\u7a0b\u95f4\u7684\u4fe1\u53f7\u4e2d\u8fdb\u884c\u8bb2\u89e3&#xff08;\u4f46\u662f\u6211\u4eec\u80fd\u5199\u4e00\u4e9b\u4ee3\u7801\u6765\u770b\u770b\u4fe1\u53f7&#xff09;.<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u8fd9\u91cc\u6ce8\u610f\u7684\u662f\u6211\u4eec\u7684cor dump\u53ea\u5360\u4e00\u4e2a\u6bd4\u7279\u4f4d\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u8fd9\u91cc\u6ce8\u610f\u5982\u679c\u7a0b\u5e8f\u5f02\u5e38\u4e86\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u5c31\u6ca1\u4ec0\u4e48\u4f5c\u7528\u4e86\u3002<\/span><\/p>\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"384\" src=\"2026-07-30mep3a1yzebr.png\" width=\"512\" \/><\/p>\n<p>\u67e5\u770b\u201c9\u201d\u53f7\u4fe1\u53f7&#xff1a;<\/p>\n<p>\u8fd9\u91cc\u4e3a\u5565\u8981&amp;0X7F\u5462&#xff1f;&#xff1f;<\/p>\n<p>\u56e0\u4e3a\u6211\u53ea\u8981\u524d7\u4f4d\u7b2c8\u4f4d\u5b58\u50a8\u7684\u662fcore dump<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if(pi &#061;&#061; 0)<br \/>\n    {<br \/>\n        \/\/\u5b50\u8fdb\u7a0b<br \/>\n        while(1)<br \/>\n        {<br \/>\n            printf(&#034;\u6211\u662f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6211\u7684\u7236\u4eb2\u7684id:%d,\u6211\u7684id\u662f%d \\\\n&#034;,getppid(),getpid());<br \/>\n            sleep(3);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    else if (pi &gt;0)<br \/>\n    {<br \/>\n        \/\/\u7236\u8fdb\u7a0b<br \/>\n        \/\/ int status &#061;0;<br \/>\n        \/\/ wait(&amp;status);<br \/>\n        \/\/ printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n        int status &#061;0;<br \/>\n        waitpid(pi, &amp;status, 0);\/\/\u4e0d\u8fdb\u884c\u963b\u585e\u7b49\u5f85<br \/>\n        printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n        printf(&#034;\u4fe1\u53f7\u4f4d:%d\\\\n&#034;, status &amp; 0X7F);<br \/>\n    }<\/p>\n<p>    else<br \/>\n    {<br \/>\n        \/\/\u51fa\u73b0\u5f02\u5e38<br \/>\n        printf(&#034;error fail!&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    return 0;<\/p>\n<p>} <\/p>\n<p>\u6211\u4eec\u5c06\u4f7f\u75289\u53f7\u4fe1\u53f7\u6740\u6b7b\u8be5\u8fdb\u7a0b&#xff0c;<\/p>\n<p>\u6211\u4eec\u770b\u5230\u5bf9\u5e94\u7684\u4fe1\u53f7\u503c\u662f9\u53f7\u4fe1\u53f7\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"459\" src=\"2026-07-30upne1sh0bwx.png\" width=\"1179\" \/><\/p>\n<p>\u6211\u4eec\u770b\u770b\u5bf9\u5e94\u768411\u53f7\u4fe1\u53f7&#xff1a;<\/p>\n<p>\u6211\u4eec\u8fd0\u884c\u4e0b\u9762\u7684\u7a0b\u5e8f&#xff1a;<\/p>\n<p>\u6211\u4eec\u5bf9\u7a7a\u6307\u9488\u8fdb\u884c\u89e3\u5f15\u7528\u64cd\u4f5c\u80af\u5b9a\u662f\u9519\u8bef\u7684\u3002<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if(pi &#061;&#061; 0)<br \/>\n    {<br \/>\n        \/\/\u5b50\u8fdb\u7a0b<br \/>\n        while(1)<br \/>\n        {<br \/>\n            \/\/ printf(&#034;\u6211\u662f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6211\u7684\u7236\u4eb2\u7684id:%d,\u6211\u7684id\u662f%d \\\\n&#034;,getppid(),getpid());<br \/>\n            \/\/ sleep(3);<br \/>\n            int * ptr &#061;0;\/\/ptr\u662f\u4e00\u4e2a\u7a7a\u6307\u9488<br \/>\n            *ptr&#061;10;\/\/\u5bf9\u7a7a\u6307\u9488\u8fdb\u884c*\u64cd\u4f5c<br \/>\n        }<br \/>\n    }<\/p>\n<p>    else if (pi &gt;0)<br \/>\n    {<br \/>\n        \/\/\u7236\u8fdb\u7a0b<br \/>\n        \/\/ int status &#061;0;<br \/>\n        \/\/ wait(&amp;status);<br \/>\n        \/\/ printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n        int status &#061;0;<br \/>\n        waitpid(pi, &amp;status, 0);\/\/\u4e0d\u8fdb\u884c\u963b\u585e\u7b49\u5f85<br \/>\n        printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n        printf(&#034;\u4fe1\u53f7\u4f4d:%d\\\\n&#034;, status &amp; 0X7F);<br \/>\n    }<\/p>\n<p>    else<br \/>\n    {<br \/>\n        \/\/\u51fa\u73b0\u5f02\u5e38<br \/>\n        printf(&#034;error fail!&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    return 0;<\/p>\n<p>}<\/p>\n<p>\u6211\u4eec\u53d1\u73b0\u662f11\u53f7\u4fe1\u53f7&#xff0c;11\u53f7\u662f\u4ec0\u4e48\u5462\u6211\u4eec\u53ef\u4ee5\u67e5\u770b\u4e00\u4e0b&#xff1a;<\/p>\n<p>kill -l <\/p>\n<p>\u6211\u4eec\u53d1\u73b0\u662f\u6bb5\u9519\u8bef\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"432\" src=\"2026-07-30iexfx5grncx.png\" width=\"1692\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1365\" src=\"2026-07-30cwv0swbq4qi.png\" width=\"1580\" \/><\/p>\n<h3 id=\"%E9%98%BB%E5%A1%9E%E7%AD%89%E5%BE%85%E5%92%8C%E9%9D%9E%E9%98%BB%E5%A1%9E%E7%AD%89%E5%BE%85%EF%BC%9A\"><span style=\"color:#fe2c24\">\u963b\u585e\u7b49\u5f85\u548c\u975e\u963b\u585e\u7b49\u5f85&#xff1a;<\/span><\/h3>\n<p>\u50cf\u6211\u4eec\u7684\u963b\u585e\u7b49\u5f85\u4e0a\u9762\u5df2\u7ecf\u8fdb\u884c\u4e86\u5bf9\u5e94\u7684\u8bf4\u660e&#xff0c; \u5c31\u662f\u6211\u4eec\u7684\u7236\u8fdb\u7a0b\u963b\u585e\u5728\u54ea\u91cc\u7b49\u5f85\u6211\u4eec\u7684\u5b50\u8fdb\u7a0b\u8fd0\u884c\u7ed3\u675f&#xff0c; \u5c31\u5728\u90a3\u91cc\u4e00\u81f4\u7684\u8fdb\u884c\u7b49\u5f85\u3002<\/p>\n<p>\u975e\u963b\u585e\u7b49\u5f85&#xff1a;\u201c \u5728\u7b49\u5f85\u6211\u4eec\u7684\u5b50\u8fdb\u7a0b\u662f\u6211\u4eec\u7684\u7236\u8fdb\u7a0b\u4e5f\u4e00\u76f4\u5728\u505a\u81ea\u5df1\u7684\u5de5\u4f5c\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/wait.h&gt;<br \/>\n#include &lt;unistd.h&gt;<\/p>\n<p>int main() {<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if (pi &#061;&#061; 0) {<br \/>\n        \/\/ \u5b50\u8fdb\u7a0b<br \/>\n        int cnt &#061; 2;<br \/>\n        while (cnt&#8211;) {<br \/>\n            printf(&#034;\u6211\u662f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6211\u7684\u7236\u4eb2\u7684id:%d,\u6211\u7684id\u662f%d \\\\n&#034;, getppid(), getpid());<br \/>\n            sleep(3);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    else if (pi &gt; 0) {<br \/>\n        \/\/ \u7236\u8fdb\u7a0b<br \/>\n        \/\/  int status &#061;0;<br \/>\n        \/\/  wait(&amp;status);<br \/>\n        \/\/  printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n        int status &#061; 0;<br \/>\n        int ret &#061;0;<br \/>\n        while (ret &#061;&#061; 0) {<br \/>\n            ret &#061; waitpid(pi, &amp;status, WNOHANG); \/\/ \u975e\u963b\u585e\u7b49\u5f85<br \/>\n            printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n            printf(&#034;\u4fe1\u53f7\u4f4d:%d\\\\n&#034;, status &amp; 0X7F);<br \/>\n            sleep(2);<br \/>\n        }<br \/>\n        printf(&#034;\u5bf9\u5e94\u7684\u9000\u51fa\u7801\u4e3a&#xff1a;%d\\\\n&#034;, WEXITSTATUS(status));<br \/>\n        printf(&#034;\u4fe1\u53f7\u4f4d:%d\\\\n&#034;, status &amp; 0X7F);<br \/>\n    }<\/p>\n<p>    else {<br \/>\n        \/\/ \u51fa\u73b0\u5f02\u5e38<br \/>\n        printf(&#034;error fail!&#034;);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    return 0;<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"342\" src=\"2026-07-30pte5swam04s.png\" width=\"749\" \/><\/p>\n<h2 id=\"%E8%BF%9B%E7%A8%8B%E7%9A%84%E6%9B%BF%E6%8D%A2\"><span style=\"color:#fe2c24\">\u8fdb\u7a0b\u7684\u66ff\u6362<\/span><\/h2>\n<p>fork()\u4e4b\u540e&#xff0c;\u7236\u5b50\u5404\u81ea\u6267\u884c\u7236\u8fdb\u7a0b\u4ee3\u7801\u7684\u4e00\u90e8\u5206\u5982\u679c\u5b50\u8fdb\u7a0b\u5c31\u60f3\u6267\u884c\u4e00\u4e2a\u5168\u65b0\u7684\u7a0b\u5e8f\u5462&#xff1f;\u8fdb\u7a0b\u7684\u7a0b\u5e8f\u66ff\u6362\u6765\u5b8c\u6210\u8fd9\u4e2a\u529f\u80fd&#xff01;<\/p>\n<p>\u7a0b\u5e8f\u66ff\u6362\u662f\u901a\u8fc7\u7279\u5b9a\u7684\u63a5\u53e3&#xff0c;\u52a0\u8f7d\u78c1\u76d8\u4e0a\u7684\u4e00\u4e2a\u5168\u65b0\u7684\u7a0b\u5e8f(\u4ee3\u7801\u548c\u6570\u636e)&#xff0c;\u52a0\u8f7d\u5230\u8c03\u7528\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u4e2d&#xff01;<\/p>\n<h3 id=\"%E6%9B%BF%E6%8D%A2%E5%8E%9F%E7%90%86%EF%BC%9A\"><span style=\"color:#fe2c24\">\u66ff\u6362\u539f\u7406&#xff1a;<\/span><\/h3>\n<p>\u7528 fork \u521b\u5efa\u5b50\u8fdb\u7a0b\u540e\u6267\u884c\u7684\u662f\u548c\u7236\u8fdb\u7a0b\u76f8\u540c\u7684\u7a0b\u5e8f (\u4f46\u6709\u53ef\u80fd\u6267\u884c\u4e0d\u540c\u7684\u4ee3\u7801\u5206\u652f), \u5b50\u8fdb\u7a0b\u5f80\u5f80\u8981\u8c03\u7528\u4e00\u79cd exec \u51fd\u6570\u4ee5\u6267\u884c\u53e6\u4e00\u4e2a\u7a0b\u5e8f\u3002\u5f53\u8fdb\u7a0b\u8c03\u7528\u4e00\u79cd exec \u51fd\u6570\u65f6&#xff0c;\u8be5\u8fdb\u7a0b\u7684\u7528\u6237\u7a7a\u95f4\u4ee3\u7801\u548c\u6570\u636e\u5b8c\u5168\u88ab\u65b0\u7a0b\u5e8f\u66ff\u6362&#xff0c;\u4ece\u65b0\u7a0b\u5e8f\u7684\u542f\u52a8\u4f8b\u7a0b\u5f00\u59cb\u6267\u884c\u3002\u8c03\u7528 exec \u5e76\u4e0d\u521b\u5efa\u65b0\u8fdb\u7a0b&#xff0c;\u6240\u4ee5\u8c03\u7528 exec \u524d\u540e\u8be5\u8fdb\u7a0b\u7684 id \u5e76\u672a\u6539\u53d8\u3002 <img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1248\" src=\"2026-07-30tpzrcepikre.png\" width=\"3328\" \/><\/p>\n<p>\u5728\u7a0b\u5e8f\u66ff\u6362\u7684\u8fc7\u7a0b\u4e2d\u5e76\u6ca1\u6709\u521b\u5efa\u65b0\u7684\u8fdb\u7a0b&#xff0c;\u53ea\u662f\u628a\u4e4b\u524d\u7684\u8fdb\u7a0b\u7684\u4ee3\u7801\u548c\u6570\u636e\u8fdb\u884c\u66ff\u6362&#xff0c;\u8fd9\u91cc\u7684\u66ff\u6362\u662f\u8986\u76d6\u5f0f\u7684\u66ff\u6362\u3002<\/p>\n<p>\u6211\u4e3a\u4ec0\u4e48\u8bf4\u4ed6\u6ca1\u6709\u521b\u5efa\u65b0\u7684\u8fdb\u7a0b\u5462&#xff1f;\u6211\u4eec\u5c31\u6765\u89c1\u4e00\u89c1\u628a\u3002<\/p>\n<p>\u6211\u4eec\u9700\u8981\u7528\u5230&#xff1a;execl\u8fd9\u4e2a\u51fd\u6570\u3002<\/p>\n<h3 id=\"%E6%9B%BF%E6%8D%A2%E7%9A%84%E6%93%8D%E4%BD%9C%EF%BC%9A\"><span style=\"color:#fe2c24\">\u66ff\u6362\u7684\u64cd\u4f5c&#xff1a;<\/span><\/h3>\n<p>\u5148\u770b\u4e00\u4e0b\u5bf9\u5e94\u7684\u5b98\u65b9\u6587\u6863&#xff1a;<\/p>\n<p>man execl<\/p>\n<p>\u53c2\u6570\u7b2c\u4e00\u4e2a\u53c2\u6570\u662fpath&#xff1a;\u5c31\u662f\u8981\u66ff\u6362\u7684\u7a0b\u5e8f\u7684\u8def\u5f84\u5728\u54ea\u91cc\u3002<\/p>\n<p>\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662fagr&#xff1a;\u6211\u4eec\u8981\u600e\u4e48\u8fdb\u884c\u6267\u884c&#xff0c;\u6211\u4eec\u547d\u4ee4\u884c\u600e\u4e48\u5199\u6211\u4eec\u5c31\u600e\u4e48\u5199\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1224\" src=\"2026-07-30ryzeilagrqg.png\" width=\"2241\" \/><\/p>\n<p>\u6211\u4eec\u5148\u6d45\u6d45\u7684\u4f7f\u7528\u4e00\u4e0b\u3002<\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u8981\u4ee5NULL\u8fdb\u884c\u7ed3\u5c3e<\/span>\u3002<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;unistd.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    execl(&#034;\/usr\/bin\/ls&#034;, &#034;ls&#034;, &#034;-l&#034;,&#034;-a&#034;,NULL);<br \/>\n    printf(&#034;\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u6211\u4eec\u8fd0\u884c\u4e00\u4e0b&#xff1a;<\/p>\n<p>\u6211\u4eec\u540e\u9762\u8fd8\u6709\u4e00\u53e5\u8bdd\u6ca1\u6709\u6267\u884c&#xff0c;<span style=\"color:#fe2c24\">\u8fd9\u5c31\u8bf4\u660e\u8fd9\u4e2a\u7a0b\u5e8f\u628a\u6211\u4eec\u5f53\u524d\u7684\u7a0b\u5e8f\u8fdb\u884c\u4e86\u66ff\u6362<\/span>\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"387\" src=\"2026-07-30lm0yhobel0i.png\" width=\"1101\" \/><\/p>\n<p>\u5f53\u7136\u6211\u4eec\u4e5f\u53ef\u4ee5\u5199c&#043;&#043;&#xff0c; python&#xff0c;php&#xff0c; shell\u811a\u672c&#8230;..\u7b49\u7b49\u8fdb\u884c\u66ff\u6362\u3002<\/p>\n<p>\u6211\u4eec\u6765\u6d4b\u8bd5\u4e00\u4e0b&#xff1a;<\/p>\n<p>\u6211\u4eec\u4e66\u5199\u4e86\u4ee5\u4e00\u4e2ac&#043;&#043;\u7a0b\u5e8f&#xff1a;<\/p>\n<p>#include&lt;iostream&gt;<br \/>\n#include&lt;cstdio&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    std::cout&lt;&lt;&#034;\u6211\u662f\u4e00\u4e2ac&#043;&#043;\u7a0b\u5e8f&#034;&lt;&lt; std::endl;<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<p>\u90a3\u6211\u4eec\u5728c\u8bed\u8a00\u8fdb\u884c\u8c03\u7528&#xff1a;&#xff08;\u8981\u8fdb\u884c\u63d0\u524d\u7f16\u8bd1&#xff09;<\/p>\n<p>c\u8bed\u8a00\u7a0b\u5e8f&#xff1a;<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;unistd.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    execl(&#034;.\/ctest&#034;, &#034;.\/ctest&#034;,NULL);<br \/>\n    printf(&#034;\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u6211\u4eec\u770b\u5230\u6211\u4eec\u771f\u7684\u5c06c&#043;&#043;\u4ee3\u7801\u8fdb\u884c\u4e86\u5bf9\u5e94\u7684\u66ff\u6362\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1257\" src=\"2026-07-302cldm0voqw4.png\" width=\"1935\" \/><\/p>\n<p>\u90a3\u4e48\u6211\u5c06\u8fdb\u4e00\u6b65\u7684\u8fdb\u884c\u9a8c\u8bc1\u6211\u4eec\u5728\u66ff\u6362\u8fc7\u7a0b\u4e2d\u6ca1\u6709\u521b\u5efa\u8fdb\u7a0b&#xff1a;<\/p>\n<p>\u6211\u4eec\u5bf9\u5e94\u7684c&#043;&#043;\u7a0b\u5e8f&#xff1a;<\/p>\n<p>#include&lt;iostream&gt;<br \/>\n#include&lt;cstdio&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    std::cout&lt;&lt;&#034;\u6211\u662f\u4e00\u4e2ac&#043;&#043;\u7a0b\u5e8f\u6211\u7684id\u662f&#034; &lt;&lt; getpid()&lt;&lt;std::endl;<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<p>c:<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;unistd.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    printf(&#034;\u6211\u662f\u4e00\u4e2ac\u8bed\u8a00\u7a0b\u5e8f\u6211\u7684id&#xff1a;%d\\\\n&#034;, getpid());<br \/>\n    execl(&#034;.\/ctest&#034;, &#034;.\/ctest&#034;,NULL);<br \/>\n    printf(&#034;\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n} <\/p>\n<p>\u6211\u4eec\u8fd0\u884c\u4e00\u4e0b&#xff1a;<\/p>\n<p>\u6211\u4eec\u7684id\u4e00\u6478\u4e00\u6837\u6240\u4ee5\u6211\u4eec\u7684\u8fdb\u7a0b\u662f\u6ca1\u6709\u521b\u5efa\u65b0\u8fdb\u7a0b\u8fdb\u884c\u6267\u884c\u66ff\u6362\u7684\u7a0b\u5e8f\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"126\" src=\"2026-07-30va4d1wwumdq.png\" width=\"603\" \/><\/p>\n<h3 id=\"%E7%A8%8B%E5%BA%8F%E7%9A%84%E8%BF%94%E5%9B%9E%EF%BC%9A\"><span style=\"color:#fe2c24\">\u7a0b\u5e8f\u7684\u8fd4\u56de&#xff1a;<\/span><\/h3>\n<p>\u6211\u4eec\u8fd9\u91cc\u8981\u6ce8\u610f\u6211\u4eec\u66ff\u6362\u6210\u529f\u65f6&#xff0c;execl\u51fd\u6570\u662f\u6ca1\u6709\u8fd4\u56de\u503c\u7684&#xff0c;\u56e0\u4e3a\u6ca1\u5fc5\u8981&#xff0c;\u6709\u4e5f\u6ca1\u7528&#xff0c; \u4e3a\u4ec0\u4e48\u8fd9\u4e48\u8bf4\u5462&#xff1f;&#xff1f;&#xff1f;\u56e0\u4e3a\u6211\u4eec\u7684\u7a0b\u5e8f\u88ab\u66ff\u6362\u65f6&#xff0c; \u6211\u4eec\u7684\u539f\u6765\u7684\u4ee3\u7801\u5df2\u7ecf\u88ab\u8986\u76d6\u4e86&#xff0c; \u6211\u4eec\u540e\u9762\u62ff\u5230\u8fd4\u56de\u503c\u4e5f\u5c31\u6ca1\u7528\u4e86\u3002<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u6ce8\u610f\u6211\u4eec\u7684return\u4e5f\u662f\u6ca1\u7528\u4e86\u3002\u56e0\u6b64\u6211\u4eec\u4e00\u822c\u5c06\u9000\u51fa\u8bbe\u7f6e\u4f4dexit&#xff08;1&#xff09;\u8fd9\u4e48\u7684\u8fdb\u884c&#xff0c;\u8868\u793a\u66ff\u6362\u5931\u8d25&#xff0c; \u540e\u7eed\u7684\u4ee3\u7801\u4e5f\u6ca1\u6709\u5fc5\u8981\u6267\u884c\u4e86\u3002<\/p>\n<p>\u6211\u4eec\u4e00\u822c\u4f1a\u50cf\u4e0b\u9762\u90a3\u6837\u8fdb\u884c\u5bf9\u5e94\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    printf(&#034;\u6211\u662f\u4e00\u4e2ac\u8bed\u8a00\u7a0b\u5e8f\u6211\u7684id:%d\\\\n&#034;, getpid());<br \/>\n    execl(&#034;.\/ctest&#034;, &#034;.\/ctest&#034;,NULL);<br \/>\n    printf(&#034;\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\\\\n&#034;);<br \/>\n    exit(-1);<br \/>\n}<\/p>\n<p>\u90a3\u6211\u4eec\u5728\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\u53ef\u4ee5\u521b\u5efa\u5b50\u8fdb\u7a0b\u6765\u5b8c\u6210\u66ff\u6362\u3002<\/p>\n<h3 id=\"%E5%88%9B%E5%BB%BA%E5%AD%90%E8%BF%9B%E7%A8%8B%E5%AE%8C%E6%88%90%E6%9B%BF%E6%8D%A2%EF%BC%9A\"><span style=\"color:#fe2c24\">\u521b\u5efa\u5b50\u8fdb\u7a0b\u5b8c\u6210\u66ff\u6362&#xff1a;<\/span><\/h3>\n<p>\u6211\u4eec\u80fd\u770b\u5230\u6211\u4eec\u7684\u5b50\u8fdb\u7a0b\u5b8c\u6210\u5bf9\u5e94\u7684\u66ff\u6362&#xff0c;\u6211\u4eec\u7684\u7236\u8fdb\u7a0b\u53ef\u4ee5\u6267\u884c\u81ea\u5df1\u7684\u4ee3\u7801\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<\/p>\n<p>int main() {<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if (pi &#061;&#061; 0) {<br \/>\n        execl(&#034;.\/ctest&#034;, &#034;.\/ctest&#034;, NULL);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    waitpid(pi, NULL, 0);<br \/>\n    printf(&#034;\u56de\u6536\u6210\u529f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1413\" src=\"2026-07-304hzmm3lsbk4.png\" width=\"1566\" \/><\/p>\n<p>\u4e3a\u4ec0\u4e48\u5b50\u8fdb\u7a0b\u8fdb\u884c\u66ff\u6362\u7236\u8fdb\u7a0b\u6ca1\u6709\u5f71\u54cd\u5462&#xff1f;&#xff1f;&#xff1f;<\/p>\n<p>1.\u8fdb\u7a0b\u5177\u6709\u72ec\u7acb\u6027\u3002<\/p>\n<p>2.\u6570\u636e\u548c\u4ee3\u7801\u4f1a\u53d1\u751f\u5199\u65f6\u8003\u5457\u3002<\/p>\n<p>\u6700\u540e\u6211\u4eec\u6765\u8fdb\u884c\u5269\u4e0b\u7684\u63a5\u53e3\u7684\u4f7f\u7528&#xff1a;<\/p>\n<h3 id=\"exec%E5%AE%B6%E6%97%8F%EF%BC%9A\" style=\"background-color:transparent\"><span style=\"color:#fe2c24\">exec\u5bb6\u65cf&#xff1a;<\/span><\/h3>\n<p>\u6211\u4eec\u521a\u624d\u770b\u6587\u6863\u7684\u65f6\u5019\u8fd8\u6709\u51e0\u4e2a\u51fd\u6570&#xff1a;<\/p>\n<p>man execl<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1161\" src=\"2026-07-30pydgjbzpfj3.png\" width=\"2550\" \/><\/p>\n<h4 id=\"execl\"><span style=\"color:#b95514\">execl<\/span><\/h4>\n<p><span style=\"color:#b95514\">\u8bed\u6cd5&#xff1a;<\/span><\/p>\n<p>int execl(const char *pathname, const char *arg, &#8230;&#xff09;<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<\/p>\n<p>int main() {<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if (pi &#061;&#061; 0) {<br \/>\n        execl(&#034;\/usr\/bin\/ls&#034;, &#034;ls&#034;,&#034;-l&#034;,&#034;-a&#034;, NULL);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    waitpid(pi, NULL, 0);<br \/>\n    printf(&#034;\u56de\u6536\u6210\u529f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1362\" src=\"2026-07-30bo0zqhuyaeg.png\" width=\"1677\" \/><\/p>\n<h4 id=\"exclp\"><span style=\"color:#fe2c24\">exclp<\/span><\/h4>\n<p><span style=\"color:#fe2c24\">\u8bed\u6cd5&#xff1a;<\/span><\/p>\n<p>int execlp(const char *file, const char *arg, &#8230;);<\/p>\n<p>\u7279\u70b9&#xff1a;\u8fd9\u91cc\u7684 p\u662fPATH\u7684\u610f\u601d\u8bf4\u660e\u8fd9\u91cc\u7684\u8fd9\u4e2a\u51fd\u6570\u81ea\u5e26\u8def\u5f84&#xff0c; \u53ea\u8981\u6211\u4eec\u5199\u6587\u4ef6\u540d\u5373\u53ef\u3002<\/p>\n<p>\u4f7f\u7528&#xff1a;<\/p>\n<p>\u8fd9\u91cc\u7684ls\u4ee3\u8868\u7684\u610f\u601d\u4e0d\u4e00\u6837&#xff0c;\u7b2c\u4e00\u4e2als\u662f\u4ee3\u8868\u8981\u6267\u884c\u90a3\u4e2a\u6587\u4ef6&#xff0c; \u7b2c\u4e8c\u4e2a\u662f\u6211\u60f3\u600e\u4e48\u8fdb\u884c\u6267\u884c\u3002\u6211\u4eec\u5728\u4e0b\u9762\u7684\u4ee3\u7801\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u4e0d\u8981\u643a\u5e26\u8def\u5f84\u53ea\u8981\u77e5\u9053\u5bf9\u5e94\u7684\u6587\u4ef6\u540d\u5373\u53ef\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<\/p>\n<p>int main() {<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if (pi &#061;&#061; 0) {<br \/>\n        execlp(&#034;ls&#034;, &#034;ls&#034;,&#034;-l&#034;,&#034;-a&#034;, NULL);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    waitpid(pi, NULL, 0);<br \/>\n    printf(&#034;\u56de\u6536\u6210\u529f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<h4 id=\"%E2%80%8B%E7%BC%96%E8%BE%91execv\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1344\" src=\"2026-07-30qovzrmsofia.png\" width=\"1733\" \/><span style=\"color:#fe2c24\">execv<\/span><\/h4>\n<p><span style=\"color:#fe2c24\">\u8bed\u6cd5&#xff1a;<\/span><\/p>\n<p>int execv(const char *pathname, char *const argv[]);<\/p>\n<p>\u6211\u4eec\u770b\u5230\u4ed6\u6ca1\u6709p\u8bf4\u660e\u8981\u5e26\u8def\u5f84&#xff0c;\u6211\u4eec\u540e\u9762\u7684argv\u4ee3\u8868\u6211\u4eec\u8981\u4f20\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002<\/p>\n<p>\u4f7f\u7528&#xff1a;<\/p>\n<p>\u8fd9\u91cc\u7684argv\u5c31\u8bf4\u660e\u6211\u4e48\u8981\u4f20\u5165\u4e00\u4e2a\u547d\u4ee4\u884c\u6570\u7ec4\u3002 <span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;\u8fd9\u4e2a\u6570\u7ec4\u8981\u4ee5NULL\u8fdb\u884c\u7ed3\u5c3e<\/span><\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<\/p>\n<p>int main() {<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    pid_t pi &#061; fork();<br \/>\n    char* const arg[10]&#061;{<br \/>\n        &#034;ls&#034;,<br \/>\n        &#034;-l&#034;,<br \/>\n        &#034;-a&#034;,<br \/>\n        NULL<br \/>\n    };<br \/>\n    if (pi &#061;&#061; 0) {<br \/>\n        execv(&#034;\/usr\/bin\/ls&#034;,arg);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    waitpid(pi, NULL, 0);<br \/>\n    printf(&#034;\u56de\u6536\u6210\u529f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1347\" src=\"2026-07-30bppqacnszp2.png\" width=\"1815\" \/><\/p>\n<h4 id=\"execvp\"><span style=\"color:#fe2c24\">execvp<\/span><\/h4>\n<p>\u8bed\u6cd5&#xff1a;<\/p>\n<p>int execvp(const char *file, char *const argv[]);<\/p>\n<p>\u901a\u8fc7\u540d\u5b57\u6211\u4eec\u80fd\u770b\u5230\u4ed6\u6709p\u53ef\u4ee5\u76f4\u8fdb\u884c\u4f20\u8def\u5f84&#xff0c;\u6709v\u6240\u4ee5\u8981\u4f20\u5165\u4ee5\u547d\u4ee4\u884c\u6570\u7ec4\u3002<\/p>\n<p>\u4f7f\u7528&#xff1a;<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<\/p>\n<p>int main() {<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    pid_t pi &#061; fork();<br \/>\n    char* const arg[10]&#061;{<br \/>\n        &#034;ls&#034;,<br \/>\n        &#034;-l&#034;,<br \/>\n        &#034;-a&#034;,<br \/>\n        NULL<br \/>\n    };<br \/>\n    if (pi &#061;&#061; 0) {<br \/>\n        execvp(&#034;ls&#034;,arg);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    waitpid(pi, NULL, 0);<br \/>\n    printf(&#034;\u56de\u6536\u6210\u529f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1326\" src=\"2026-07-30kjvbmlzhdvf.png\" width=\"1602\" \/><\/p>\n<h4 id=\"execle\"><span style=\"color:#fe2c24\">execle<\/span><\/h4>\n<p><span style=\"color:#fe2c24\">\u8bed\u6cd5&#xff1a;<\/span><\/p>\n<p>int execle(const char *pathname, const char *arg, &#8230;char *const envp[]&#xff09; \u8fd9\u91cc\u6211\u4eec\u770b\u5230\u6709\u6ca1\u6709p\u8981\u4f20\u8def\u5f84&#xff0c;\u4e5f\u6ca1\u6709v\u6240\u4ee5\u4e0d\u662f\u4f20\u6211\u4eec\u7684\u547d\u4ee4\u884c\u53c2\u6570\u8868\u3002\u90a3\u6211\u4eec\u7684e\u5462&#xff1f;<\/p>\n<p>\u8fd9\u91cc\u7684e\u4ee3\u8868env\u8981\u4f20\u73af\u5883\u53d8\u91cf&#xff0c;\u548c\u6211\u4eec\u7684\u547d\u4ee4\u884c\u53c2\u6570\u4e00\u6837\u8fd9\u91cc\u8981\u4f20\u4e00\u4e2a\u6570\u7ec4\u3002\u4e0d\u80fd\u76f4\u63a5\u7684\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p>\u4f7f\u7528<\/p>\n<p>\u6211\u4eec\u8fd9\u91cc\u5199\u4e24\u4e2a\u7a0b\u5e8f\u8fdb\u884c\u9a8c\u8bc1&#xff1a;<\/p>\n<p>\u8fd9\u4e2a\u662f\u8fdb\u884c\u66ff\u6362\u7684\u7a0b\u5e8f&#xff1a;<\/p>\n<p>#include &lt;iostream&gt;<\/p>\n<p>int main(int argc, char *argv[], char *env[]) {<br \/>\n    \/\/ \u6253\u5370\u547d\u4ee4\u884c\u53c2\u6570<br \/>\n    for (int i &#061; 0; i &lt; argc; i&#043;&#043;) {<br \/>\n        printf(&#034;\u547d\u4ee4\u884c\u53c2\u6570argv[%d]\u2014\u2014&gt;%s\\\\n&#034;,i,argv[i]);<br \/>\n    }<\/p>\n<p>    \/\/ \u6253\u5370\u73af\u5883\u53d8\u91cf<br \/>\n    for (int i &#061; 0; env[i]; i&#043;&#043;) {<br \/>\n        printf(&#034;env[%d]\u2014\u2014&gt;%s\\\\n&#034;, i, env[i]);<br \/>\n    }<\/p>\n<p>    return 0;<br \/>\n} <\/p>\n<p>\u6211\u4eec\u7684c\u8bed\u8a00\u4e3b\u8981\u7684\u7a0b\u5e8f&#xff1a;<\/p>\n<p>\u89e3\u91ca\u4e00\u4e0b&#xff0c;\u6211\u66ff\u6362\u4e86\u8fd9\u4e2a\u7a0b\u5e8f&#xff0c;\u6211\u4eec\u4e0b\u9762\u7684\u7a0b\u5e8f\u548c\u8fdb\u884c\u8c03\u7528\u4e0a\u9762\u7684\u7a0b\u5e8f&#xff0c;\u6240\u4ee5\u7528\u5230\u7684\u4e0b\u9762\u7684\u90a3\u4e9b\u547d\u4ee4&#xff0c; \u6211\u4e48\u90fd\u5c06\u4ee5argv\u7684\u5f62\u5f0f\u4f20\u7ed9\u4e86\u4e0a\u9762\u7684main\u51fd\u6570\u3002env\u4f20\u7ed9\u4e86main\u7684env\u6240\u4ee5\u6211\u4eec\u8fd0\u884c\u4e00\u4e0b\u80fd\u770b\u5230\u5bf9\u5e94\u7684\u7ed3\u679c&#xff0c;\u8fd9\u4e2a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u76f8\u5f53\u4e0e\u6211\u4eec\u81ea\u5df1\u5728\u547d\u4ee4\u884c\u8fdb\u884c\u7684\u8f93\u5165\u3002<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include&lt;sys\/wait.h&gt;<\/p>\n<p>char* const envp[]&#061;{<br \/>\n    &#034;zhibu &#061; 1234&#034;,<br \/>\n    &#034;PATH &#061;1011&#034;,<br \/>\n    NULL<br \/>\n};<\/p>\n<p>int main() {<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    pid_t pi &#061; fork();<br \/>\n    char* const arg[10]&#061;{<br \/>\n        &#034;ls&#034;,<br \/>\n        &#034;-l&#034;,<br \/>\n        &#034;-a&#034;,<br \/>\n        NULL<br \/>\n    };<br \/>\n    if (pi &#061;&#061; 0) {<br \/>\n        execle(&#034;.\/ccpp&#034;,&#034;ccpp&#034;,&#034;-a&#034;, &#034;-b&#034;,NULL , envp);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    waitpid(pi, NULL, 0);<br \/>\n    printf(&#034;\u56de\u6536\u6210\u529f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u67e5\u770b\u4e0b\u9762\u7684\u7ed3\u679c&#xff0c;\u6211\u4eec\u7684\u547d\u4ee4\u884c\u53c2\u6570\u6ca1\u6709\u95ee\u9898&#xff0c;\u4f46\u662f\u6211\u4eec\u7684\u73af\u5883\u53d8\u91cf\u88ab\u66ff\u6362\u4e86\u3002\u6211\u4eec\u5982\u679c\u50cf\u4ee5\u589e\u52a0\u8bd5\u7684\u8fdb\u884c\u6dfb\u52a0\u7ed9\u600e\u4e48\u529e\u5462&#xff1f;&#xff1f;&#xff1f;\u4e0b\u9762\u7ed9\u51fa\u5bf9\u5e94\u7684\u4e24\u79cd\u65b9\u5f0f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"255\" src=\"2026-07-30wsjs2pqtjz5.png\" width=\"1254\" \/><\/p>\n<p>1.\u4f7f\u7528putenv\u8fdb\u884c\u6dfb\u52a0 \u00a0<\/p>\n<p>man putenv <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1196\" src=\"2026-07-30jcjhlmg41pj.png\" width=\"2556\" \/><\/p>\n<p>\u6211\u4eec\u8fd9\u4e0d\u4f7f\u7528execle\u6211\u4eec\u4f7f\u7528execl<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/wait.h&gt;<br \/>\n#include &lt;unistd.h&gt;<\/p>\n<p>char *const envp[] &#061; {&#034;zhibu &#061; 1234&#034;, &#034;PATH &#061;1011&#034;, NULL};<\/p>\n<p>int main() {<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    pid_t pi &#061; fork();<br \/>\n    char *const arg[10] &#061; {&#034;ls&#034;, &#034;-l&#034;, &#034;-a&#034;, NULL};<br \/>\n    if (pi &#061;&#061; 0) {<br \/>\n        putenv(&#034;zhibu &#061; 1234&#034;);<br \/>\n        execl(&#034;.\/ccpp&#034;, &#034;ccpp&#034;, &#034;-a&#034;, &#034;-b&#034;, NULL);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    waitpid(pi, NULL, 0);<br \/>\n    printf(&#034;\u56de\u6536\u6210\u529f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1023\" src=\"2026-07-30y04aqfyu5zc.png\" width=\"2559\" \/><\/p>\n<p>\u7b2c\u4e8c\u4e2d\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u7684\u5168\u5c40\u6307\u9488&#xff1a;environ<\/p>\n<p>\u4f7f\u7528\u4e4b\u524d\u8981\u63d0\u524d\u8fdb\u884c\u58f0\u660eextern** eniron<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/wait.h&gt;<br \/>\n#include &lt;unistd.h&gt;<\/p>\n<p>extern char **environ;<br \/>\nchar *const addenv[] &#061; {&#034;zhibu &#061; 1234&#034;, &#034;PATH &#061;1011&#034;, NULL};<br \/>\nchar *const arg[10] &#061; {&#034;ls&#034;, &#034;-l&#034;, &#034;-a&#034;, NULL};<\/p>\n<p>int main() {<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if (pi &#061;&#061; 0) {<\/p>\n<p>        for(int i&#061;0;addenv[i];i&#043;&#043;)<br \/>\n        {<br \/>\n            putenv(addenv[i]);<br \/>\n        }<\/p>\n<p>        execle(&#034;.\/ccpp&#034;, &#034;ccpp&#034;, &#034;-a&#034;, &#034;-b&#034;, NULL,environ);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    waitpid(pi, NULL, 0);<br \/>\n    printf(&#034;\u56de\u6536\u6210\u529f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1014\" src=\"2026-07-30x3ojbjtj2xm.png\" width=\"2559\" \/><\/p>\n<h4 id=\"execvpe\"><span style=\"color:#fe2c24\">execvpe<\/span><\/h4>\n<p>\u8bed\u6cd5&#xff1a;<\/p>\n<p>int execvpe(const char *file, char *const argv[],char *const envp[]);<\/p>\n<p>#define _GNU_SOURCE   \/\/\u5f00\u542fGNU\u6269\u5c55&#xff0c;\u8bc6\u522bexecvpe<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/wait.h&gt;<br \/>\n#include &lt;unistd.h&gt;<\/p>\n<p>char *const envp[] &#061; {&#034;zhibu &#061; 1234&#034;, &#034;PATH &#061;1011&#034;, NULL};<br \/>\nchar *const arg[10] &#061; {&#034;ccpp&#034;, &#034;-l&#034;, &#034;-a&#034;, NULL};<\/p>\n<p>int main() {<br \/>\n    printf(&#034;\u7a0b\u5e8f\u5f00\u59cb\u8fd0\u884c!\\\\n&#034;);<br \/>\n    pid_t pi &#061; fork();<br \/>\n    if (pi &#061;&#061; 0) {<br \/>\n        execvpe(&#034;ccpp&#034;,arg, envp);<br \/>\n        exit(-1);<br \/>\n    }<br \/>\n    waitpid(pi, NULL, 0);<br \/>\n    printf(&#034;\u56de\u6536\u6210\u529f\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u5f53\u7136\u8fd8\u6709\u4e00\u4e2a\u63a5\u53e3<\/p>\n<h4 id=\"execve(%E7%B3%BB%E7%BB%9F%E6%8E%A5%E5%8F%A3)\" style=\"background-color:transparent\">execve(\u7cfb\u7edf\u63a5\u53e3)<\/h4>\n<p>man execve <\/p>\n<p>\u6211\u4eec\u67e5\u770b\u4e00\u4e0b\u4e5f\u77e5\u9053\u4ed6\u662f\u4e00\u4e2a\u7cfb\u7edf\u8c03\u7528\u3002\u6240\u4ee5\u6211\u4eec\u524d\u9762\u76846\u4e2a\u662f\u5e93\u51fd\u6570\u8fdb\u884c\u4e86\u8bed\u8a00\u7ea7\u522b\u7684\u5c01\u88c5&#xff0c;\u4ed6\u4eec6\u4e2a\u5e95\u5c42\u90fd\u662f\u5728\u8c03\u7528\u6211\u4eec\u7684execve&#xff0c;\u6240\u4ee5\u6211\u4eec\u5e95\u5c42\u4f20\u7684path&#xff0c;argv&#xff0c;env\u90fd\u662f\u7ed9\u7cfb\u7edf\u4f20\u7684\u3002\u6240\u4ee5\u6211\u4eec\u5982\u679c\u6ca1\u4f20\u6211\u4eec\u7684env&#xff0c;\u6211\u4eec\u5e93\u51fd\u6570\u7684\u5185\u90e8\u4f1a\u8fdb\u884c\u4f20\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1239\" src=\"2026-07-3055fusljzrrm.png\" width=\"2526\" \/><\/p>\n<p style=\"text-align:center\">\u4e0b\u7bc7\u9884\u544a&#xff1a;shell\u7684\u7f16\u5199<\/p>\n<p style=\"text-align:center\">\u5b8c\u7ed3<\/p>\n<p style=\"text-align:center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"804\" src=\"2026-07-30cnickltrwrc.png\" width=\"1395\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\u4e3b\u9875<br \/>\n\u73b0\u6709\u4e13\u680f\u7b97\u6cd5\u7bc7Linux\u7bc7QT\u767e\u65e5\u7b51\u57fa\u7bc7\u6570\u636e\u7ed3\u6784\u7bc7<br \/>\n\u8fdb\u7a0b\u7684\u63a7\u5236 \u76ee\u5f55\/\u7d22\u5f15:<br \/>\n\u76ee\u5f55<br \/>\n\u8fdb\u7a0b\u7684\u521b\u5efa<br \/>\n\u8fdb\u7a0b\u7684\u521b\u5efa<br \/>\n\u6df1\u5ea6\u4e86\u89e3\\&#8221;fork\\&#8221;<br \/>\nfork\u7684\u8fd4\u56de\u503c&#xff1a;<br \/>\nfork\u7684\u7b80\u5355\u4f7f\u7528<br \/>\n\u8fdb\u7a0b\u5728\u865a\u62df\u673a\u7684\u4f5c\u7528&#xff1a;<br \/>\n\u5199\u65f6\u62f7\u8d1d&#xff1a;<br \/>\nfork\u7684\u5e38\u89c4\u7528\u6cd5&#xff1a;<br \/>\nfork\u8c03\u7528\u5931\u8d25\u7684\u5e38\u89c1\u539f\u56e0&#xff1a;<br \/>\n\u8fdb\u7a0b\u7684\u7ec8\u6b62&#xff1a;<br \/>\n\u8fdb\u7a0b\u9000\u51fa\u7684\u573a\u666f&#xff1a;<br \/>\n\u9000\u51fa\u7801\u7684\u8be6\u89e3&#xff1a;<br \/>\n\u6b63\u5e38\u7ec8\u6b62&amp;#xff08<\/p>\n","protected":false},"author":2,"featured_media":87551,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9099,58,43,44],"topic":[],"class_list":["post-87571","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-9099","tag-linux","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Linux\u7bc7\u3011\u6570\u5b57\u4e16\u754c\u7684\u201c\u603b\u6307\u6325\u201d\u2014\u2014\u8fdb\u7a0b\u63a7\u5236\u4e0e\u8c03\u5ea6\u673a\u5236\u8be6\u89e3 - \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\/87571.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Linux\u7bc7\u3011\u6570\u5b57\u4e16\u754c\u7684\u201c\u603b\u6307\u6325\u201d\u2014\u2014\u8fdb\u7a0b\u63a7\u5236\u4e0e\u8c03\u5ea6\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4f5c\u8005\u4e3b\u9875 \u73b0\u6709\u4e13\u680f\u7b97\u6cd5\u7bc7Linux\u7bc7QT\u767e\u65e5\u7b51\u57fa\u7bc7\u6570\u636e\u7ed3\u6784\u7bc7 \u8fdb\u7a0b\u7684\u63a7\u5236 \u76ee\u5f55\/\u7d22\u5f15: \u76ee\u5f55 \u8fdb\u7a0b\u7684\u521b\u5efa \u8fdb\u7a0b\u7684\u521b\u5efa \u6df1\u5ea6\u4e86\u89e3&quot;fork&quot; fork\u7684\u8fd4\u56de\u503c&#xff1a; fork\u7684\u7b80\u5355\u4f7f\u7528 \u8fdb\u7a0b\u5728\u865a\u62df\u673a\u7684\u4f5c\u7528&#xff1a; \u5199\u65f6\u62f7\u8d1d&#xff1a; fork\u7684\u5e38\u89c4\u7528\u6cd5&#xff1a; fork\u8c03\u7528\u5931\u8d25\u7684\u5e38\u89c1\u539f\u56e0&#xff1a; \u8fdb\u7a0b\u7684\u7ec8\u6b62&#xff1a; \u8fdb\u7a0b\u9000\u51fa\u7684\u573a\u666f&#xff1a; \u9000\u51fa\u7801\u7684\u8be6\u89e3&#xff1a; \u6b63\u5e38\u7ec8\u6b62&amp;#xff08\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/87571.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-30T06:58:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065819-6a6af60be11ae.jpg\" \/>\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=\"14 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/87571.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/87571.html\",\"name\":\"\u3010Linux\u7bc7\u3011\u6570\u5b57\u4e16\u754c\u7684\u201c\u603b\u6307\u6325\u201d\u2014\u2014\u8fdb\u7a0b\u63a7\u5236\u4e0e\u8c03\u5ea6\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-30T06:58:31+00:00\",\"dateModified\":\"2026-07-30T06:58:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/87571.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/87571.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/87571.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Linux\u7bc7\u3011\u6570\u5b57\u4e16\u754c\u7684\u201c\u603b\u6307\u6325\u201d\u2014\u2014\u8fdb\u7a0b\u63a7\u5236\u4e0e\u8c03\u5ea6\u673a\u5236\u8be6\u89e3\"}]},{\"@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\u7bc7\u3011\u6570\u5b57\u4e16\u754c\u7684\u201c\u603b\u6307\u6325\u201d\u2014\u2014\u8fdb\u7a0b\u63a7\u5236\u4e0e\u8c03\u5ea6\u673a\u5236\u8be6\u89e3 - \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\/87571.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Linux\u7bc7\u3011\u6570\u5b57\u4e16\u754c\u7684\u201c\u603b\u6307\u6325\u201d\u2014\u2014\u8fdb\u7a0b\u63a7\u5236\u4e0e\u8c03\u5ea6\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4f5c\u8005\u4e3b\u9875 \u73b0\u6709\u4e13\u680f\u7b97\u6cd5\u7bc7Linux\u7bc7QT\u767e\u65e5\u7b51\u57fa\u7bc7\u6570\u636e\u7ed3\u6784\u7bc7 \u8fdb\u7a0b\u7684\u63a7\u5236 \u76ee\u5f55\/\u7d22\u5f15: \u76ee\u5f55 \u8fdb\u7a0b\u7684\u521b\u5efa \u8fdb\u7a0b\u7684\u521b\u5efa \u6df1\u5ea6\u4e86\u89e3\"fork\" fork\u7684\u8fd4\u56de\u503c&#xff1a; fork\u7684\u7b80\u5355\u4f7f\u7528 \u8fdb\u7a0b\u5728\u865a\u62df\u673a\u7684\u4f5c\u7528&#xff1a; \u5199\u65f6\u62f7\u8d1d&#xff1a; fork\u7684\u5e38\u89c4\u7528\u6cd5&#xff1a; fork\u8c03\u7528\u5931\u8d25\u7684\u5e38\u89c1\u539f\u56e0&#xff1a; \u8fdb\u7a0b\u7684\u7ec8\u6b62&#xff1a; \u8fdb\u7a0b\u9000\u51fa\u7684\u573a\u666f&#xff1a; \u9000\u51fa\u7801\u7684\u8be6\u89e3&#xff1a; \u6b63\u5e38\u7ec8\u6b62&amp;#xff08","og_url":"https:\/\/www.wsisp.com\/helps\/87571.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-30T06:58:31+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260730065819-6a6af60be11ae.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"14 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/87571.html","url":"https:\/\/www.wsisp.com\/helps\/87571.html","name":"\u3010Linux\u7bc7\u3011\u6570\u5b57\u4e16\u754c\u7684\u201c\u603b\u6307\u6325\u201d\u2014\u2014\u8fdb\u7a0b\u63a7\u5236\u4e0e\u8c03\u5ea6\u673a\u5236\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-30T06:58:31+00:00","dateModified":"2026-07-30T06:58:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/87571.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/87571.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/87571.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Linux\u7bc7\u3011\u6570\u5b57\u4e16\u754c\u7684\u201c\u603b\u6307\u6325\u201d\u2014\u2014\u8fdb\u7a0b\u63a7\u5236\u4e0e\u8c03\u5ea6\u673a\u5236\u8be6\u89e3"}]},{"@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\/87571","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=87571"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/87571\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/87551"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=87571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=87571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=87571"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=87571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}