{"id":74852,"date":"2026-02-10T20:25:02","date_gmt":"2026-02-10T12:25:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/74852.html"},"modified":"2026-02-10T20:25:02","modified_gmt":"2026-02-10T12:25:02","slug":"linux%e8%bd%af%e4%bb%b6%e7%bc%96%e7%a8%8b-%e8%bf%9b%e7%a8%8b%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/74852.html","title":{"rendered":"Linux\u8f6f\u4ef6\u7f16\u7a0b: \u8fdb\u7a0b\u89e3\u6790"},"content":{"rendered":"<h2>1 \u8fdb\u7a0b\u57fa\u7840\u6982\u5ff5<\/h2>\n<h4>1.1 \u7a0b\u5e8f\u4e0e\u8fdb\u7a0b\u7684\u533a\u522b<\/h4>\n<p>\u7a0b\u5e8f&#xff1a;\u5b58\u50a8\u5728\u786c\u76d8\u4e0a\u7684\u9759\u6001\u4ee3\u7801\u548c\u6570\u636e\u96c6\u5408&#xff0c;\u662f\u672a\u6267\u884c\u7684\u6307\u4ee4\u5e8f\u5217<\/p>\n<p>\u8fdb\u7a0b&#xff1a;\u7a0b\u5e8f\u52a8\u6001\u6267\u884c\u7684\u5b9e\u4f8b&#xff0c;\u5305\u62ec\u521b\u5efa\u3001\u8c03\u5ea6\u3001\u6267\u884c\u5230\u6d88\u4ea1\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f<\/p>\n<p>\u5173\u952e\u533a\u522b&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7a0b\u5e8f\u662f\u9759\u6001\u7684&#xff0c;\u8fdb\u7a0b\u662f\u52a8\u6001\u7684<\/p>\n<\/li>\n<li>\n<p>\u7a0b\u5e8f\u662f\u5b58\u50a8\u5728\u5b58\u50a8\u4ecb\u8d28\u4e0a\u7684\u6587\u4ef6&#xff0c;\u8fdb\u7a0b\u662f\u5185\u5b58\u4e2d\u7684\u6267\u884c\u5b9e\u4f53<\/p>\n<\/li>\n<li>\n<p>\u4e00\u4e2a\u7a0b\u5e8f\u53ef\u4ee5\u5bf9\u5e94\u591a\u4e2a\u8fdb\u7a0b&#xff0c;\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u5bf9\u5e94\u4e00\u4e2a\u7a0b\u5e8f<\/p>\n<\/li>\n<\/ul>\n<h4>1.2 \u8fdb\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u89d2\u8272<\/h4>\n<p>\u8fdb\u7a0b\u662f\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u8d44\u6e90\u5206\u914d\u548c\u8c03\u5ea6\u7684\u57fa\u672c\u5355\u4f4d&#xff0c;\u6bcf\u4e2a\u8fdb\u7a0b\u62e5\u6709\u72ec\u7acb\u7684\u5730\u5740\u7a7a\u95f4\u548c\u7cfb\u7edf\u8d44\u6e90&#xff0c;\u786e\u4fdd\u8fdb\u7a0b\u95f4\u7684\u9694\u79bb\u6027\u548c\u5b89\u5168\u6027\u3002<\/p>\n<h3>2 \u8fdb\u7a0b\u7ba1\u7406\u547d\u4ee4\u8be6\u89e3<\/h3>\n<h4>2.1 \u8fdb\u7a0b\u67e5\u770b\u547d\u4ee4<\/h4>\n<h5>2.1.1 top\u547d\u4ee4 &#8211; \u5b9e\u65f6\u8fdb\u7a0b\u76d1\u63a7<\/h5>\n<p>top<\/p>\n<p>\u52a8\u6001\u663e\u793a\u7cfb\u7edf\u8fdb\u7a0b\u4fe1\u606f&#xff0c;\u6309CPU\u4f7f\u7528\u7387\u6392\u5e8f&#xff0c;\u5305\u542b&#xff1a;<\/p>\n<ul>\n<li>\n<p>PID&#xff1a;\u8fdb\u7a0bID&#xff08;\u552f\u4e00\u6807\u8bc6&#xff09;<\/p>\n<\/li>\n<li>\n<p>PPID&#xff1a;\u7236\u8fdb\u7a0bID<\/p>\n<\/li>\n<li>\n<p>CPU%&#xff1a;CPU\u4f7f\u7528\u7387<\/p>\n<\/li>\n<li>\n<p>MEM%&#xff1a;\u5185\u5b58\u4f7f\u7528\u7387<\/p>\n<\/li>\n<\/ul>\n<h5>2.1.2 ps\u547d\u4ee4 &#8211; \u8fdb\u7a0b\u72b6\u6001\u67e5\u770b<\/h5>\n<p>ps -ef                    # \u67e5\u770b\u6240\u6709\u8fdb\u7a0b\u8be6\u7ec6\u4fe1\u606f<br \/>\nps -aux                   # \u67e5\u770b\u8fdb\u7a0b\u72b6\u6001\u548c\u8d44\u6e90\u4f7f\u7528<br \/>\nps -ef | grep \u8fdb\u7a0b\u540d      # \u8fc7\u6ee4\u7279\u5b9a\u8fdb\u7a0b<br \/>\nps -aux | grep \u8fdb\u7a0b\u540d     # \u8fc7\u6ee4\u5e76\u663e\u793a\u72b6\u6001<\/p>\n<p>\u5e38\u7528\u9009\u9879\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\n<p>-e&#xff1a;\u663e\u793a\u6240\u6709\u8fdb\u7a0b<\/p>\n<\/li>\n<li>\n<p>-f&#xff1a;\u5b8c\u6574\u683c\u5f0f\u663e\u793a<\/p>\n<\/li>\n<li>\n<p>-u&#xff1a;\u663e\u793a\u7528\u6237\u76f8\u5173\u4fe1\u606f<\/p>\n<\/li>\n<li>\n<p>-x&#xff1a;\u663e\u793a\u6ca1\u6709\u63a7\u5236\u7ec8\u7aef\u7684\u8fdb\u7a0b<\/p>\n<\/li>\n<\/ul>\n<h4>2.2 \u8fdb\u7a0b\u63a7\u5236\u547d\u4ee4<\/h4>\n<h5>2.2.1 \u8fdb\u7a0b\u7ec8\u6b62<\/h5>\n<p>kill -9 PID              # \u5f3a\u5236\u7ec8\u6b62\u6307\u5b9a\u8fdb\u7a0b<br \/>\nkillall -9 \u8fdb\u7a0b\u540d        # \u7ec8\u6b62\u6240\u6709\u540c\u540d\u8fdb\u7a0b<\/p>\n<h5>2.2.2 \u540e\u53f0\u4efb\u52a1\u7ba1\u7406<\/h5>\n<p>.\/program &amp;             # \u5728\u540e\u53f0\u8fd0\u884c\u7a0b\u5e8f<br \/>\njobs                    # \u67e5\u770b\u540e\u53f0\u4efb\u52a1\u5217\u8868<br \/>\nfg %1                   # \u5c061\u53f7\u540e\u53f0\u4efb\u52a1\u8c03\u5230\u524d\u53f0<br \/>\nCtrl &#043; Z                # \u6682\u505c\u524d\u53f0\u4efb\u52a1<br \/>\nbg %1                   # \u5728\u540e\u53f0\u7ee7\u7eed\u8fd0\u884c\u6682\u505c\u7684\u4efb\u52a1<\/p>\n<h5>2.2.3 \u8fdb\u7a0b\u4f18\u5148\u7ea7\u7ba1\u7406<\/h5>\n<p>nice -n \u4f18\u5148\u7ea7 \u547d\u4ee4     # \u6307\u5b9a\u4f18\u5148\u7ea7\u8fd0\u884c\u7a0b\u5e8f&#xff08;-20\u523019&#xff09;<br \/>\nrenice -n \u4f18\u5148\u7ea7 PID   # \u4fee\u6539\u8fd0\u884c\u4e2d\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7<\/p>\n<p>\u4f18\u5148\u7ea7\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6570\u503c\u8d8a\u5c0f\u4f18\u5148\u7ea7\u8d8a\u9ad8&#xff08;-20\u6700\u9ad8&#xff0c;19\u6700\u4f4e&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u666e\u901a\u7528\u6237\u53ea\u80fd\u964d\u4f4e\u4f18\u5148\u7ea7&#xff08;0-19&#xff09;<\/p>\n<\/li>\n<li>\n<p>root\u7528\u6237\u53ef\u8bbe\u7f6e\u4efb\u610f\u4f18\u5148\u7ea7<\/p>\n<\/li>\n<\/ul>\n<h3>3 \u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u4e0e\u5185\u5b58\u7ba1\u7406<\/h3>\n<h4>3.1 \u865a\u62df\u5730\u5740\u7a7a\u95f4\u5e03\u5c40<\/h4>\n<p>\u6bcf\u4e2a\u8fdb\u7a0b\u62e5\u6709\u72ec\u7acb\u76844GB\u865a\u62df\u5730\u5740\u7a7a\u95f4&#xff08;32\u4f4d\u7cfb\u7edf&#xff09;&#xff0c;\u5206\u5e03\u5982\u4e0b&#xff1a;<\/p>\n<p>0xFFFFFFFF &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n            |     \u5185\u6838\u7a7a\u95f4     | 1GB<br \/>\n0xC0000000 &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n            |      \u6808\u533a        | \u5411\u4e0b\u589e\u957f<br \/>\n            &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n            |      \u5806\u533a        | \u5411\u4e0a\u589e\u957f<br \/>\n            &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n            |  \u672a\u521d\u59cb\u5316\u6570\u636e\u6bb5   | .bss\u6bb5<br \/>\n            &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n            |   \u5df2\u521d\u59cb\u5316\u6570\u636e\u6bb5  | .data\u6bb5<br \/>\n            &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n            |   \u53ea\u8bfb\u6570\u636e\u6bb5     | .rodata\u6bb5<br \/>\n            &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n            |     \u4ee3\u7801\u6bb5       | .text\u6bb5<br \/>\n0x08048000 &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n            |   \u4fdd\u7559\u533a\u57df       |<br \/>\n0x00000000 &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<\/p>\n<h4>3.2 \u5185\u5b58\u533a\u57df\u8be6\u89e3<\/h4>\n<h5>3.2.1 \u4ee3\u7801\u6bb5&#xff08;.text&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u5b58\u653e\u7a0b\u5e8f\u6267\u884c\u7684\u673a\u5668\u6307\u4ee4<\/p>\n<\/li>\n<li>\n<p>\u53ea\u8bfb\u5c5e\u6027&#xff0c;\u591a\u4e2a\u8fdb\u7a0b\u53ef\u5171\u4eab\u540c\u4e00\u4ee3\u7801\u6bb5<\/p>\n<\/li>\n<li>\n<p>\u5728\u7a0b\u5e8f\u7f16\u8bd1\u65f6\u786e\u5b9a&#xff0c;\u8fd0\u884c\u65f6\u4e0d\u53ef\u4fee\u6539<\/p>\n<\/li>\n<\/ul>\n<h5>3.2.2 \u6570\u636e\u6bb5<\/h5>\n<ul>\n<li>\n<p>.data\u6bb5&#xff1a;\u5df2\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf<\/p>\n<\/li>\n<li>\n<p>.bss\u6bb5&#xff1a;\u672a\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf&#xff08;\u8fd0\u884c\u65f6\u521d\u59cb\u5316\u4e3a0&#xff09;<\/p>\n<\/li>\n<li>\n<p>.rodata\u6bb5&#xff1a;\u5b57\u7b26\u4e32\u5e38\u91cf\u7b49\u53ea\u8bfb\u6570\u636e<\/p>\n<\/li>\n<\/ul>\n<h5>3.2.3 \u5806\u533a&#xff08;heap&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u52a8\u6001\u5185\u5b58\u5206\u914d\u533a\u57df&#xff08;malloc\/free&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u624b\u52a8\u7ba1\u7406&#xff0c;\u5411\u9ad8\u5730\u5740\u589e\u957f<\/p>\n<\/li>\n<li>\n<p>\u9700\u8981\u7a0b\u5e8f\u5458\u663e\u5f0f\u91ca\u653e\u5185\u5b58<\/p>\n<\/li>\n<\/ul>\n<h5>3.2.4 \u6808\u533a&#xff08;stack&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u5b58\u653e\u5c40\u90e8\u53d8\u91cf\u548c\u51fd\u6570\u8c03\u7528\u4fe1\u606f<\/p>\n<\/li>\n<li>\n<p>\u81ea\u52a8\u7ba1\u7406&#xff0c;\u5411\u4f4e\u5730\u5740\u589e\u957f<\/p>\n<\/li>\n<li>\n<p>\u51fd\u6570\u8fd4\u56de\u65f6\u81ea\u52a8\u91ca\u653e<\/p>\n<\/li>\n<\/ul>\n<h4>3.3 \u5730\u5740\u7a7a\u95f4\u9694\u79bb\u673a\u5236<\/h4>\n<p>\u901a\u8fc7MMU&#xff08;\u5185\u5b58\u7ba1\u7406\u5355\u5143&#xff09;\u5b9e\u73b0\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u6620\u5c04&#xff0c;\u786e\u4fdd&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6bcf\u4e2a\u8fdb\u7a0b\u62e5\u6709\u72ec\u7acb\u7684\u5730\u5740\u7a7a\u95f4<\/p>\n<\/li>\n<li>\n<p>\u8fdb\u7a0b\u95f4\u5185\u5b58\u9694\u79bb&#xff0c;\u63d0\u9ad8\u7cfb\u7edf\u7a33\u5b9a\u6027<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301\u5185\u5b58\u5171\u4eab\u548c\u5199\u65f6\u590d\u5236\u6280\u672f<\/p>\n<\/li>\n<\/ul>\n<h3>4 \u8fdb\u7a0b\u72b6\u6001\u4e0e\u8c03\u5ea6\u7b97\u6cd5<\/h3>\n<h4>4.1 \u8fdb\u7a0b\u72b6\u6001\u8f6c\u6362<\/h4>\n<p>\u521b\u5efa \u2192 \u5c31\u7eea(R) \u2194 \u8fd0\u884c(R) \u2192 \u7ec8\u6b62(X)<br \/>\n            \u2193        \u2191<br \/>\n        \u7b49\u5f85(S\/D) \u2192 \u5c31\u7eea(R)<\/p>\n<h5>4.1.1 \u4e3b\u8981\u8fdb\u7a0b\u72b6\u6001<\/h5>\n<ul>\n<li>\n<p>\u8fd0\u884c\u6001(R)&#xff1a;\u8fdb\u7a0b\u6b63\u5728CPU\u4e0a\u6267\u884c<\/p>\n<\/li>\n<li>\n<p>\u5c31\u7eea\u6001(R)&#xff1a;\u8fdb\u7a0b\u51c6\u5907\u5c31\u7eea&#xff0c;\u7b49\u5f85CPU\u8c03\u5ea6<\/p>\n<\/li>\n<li>\n<p>\u53ef\u4e2d\u65ad\u7b49\u5f85\u6001(S)&#xff1a;\u7b49\u5f85\u8d44\u6e90&#xff0c;\u53ef\u88ab\u4fe1\u53f7\u4e2d\u65ad<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u53ef\u4e2d\u65ad\u7b49\u5f85\u6001(D)&#xff1a;\u7b49\u5f85\u786c\u4ef6\u8d44\u6e90&#xff0c;\u4e0d\u53ef\u4e2d\u65ad<\/p>\n<\/li>\n<li>\n<p>\u505c\u6b62\u6001(T)&#xff1a;\u8fdb\u7a0b\u88ab\u6682\u505c\u6267\u884c<\/p>\n<\/li>\n<li>\n<p>\u50f5\u5c38\u6001(Z)&#xff1a;\u8fdb\u7a0b\u5df2\u7ec8\u6b62&#xff0c;\u4f46\u8d44\u6e90\u672a\u56de\u6536<\/p>\n<\/li>\n<li>\n<p>\u6b7b\u4ea1\u6001(X)&#xff1a;\u8fdb\u7a0b\u5b8c\u5168\u7ec8\u6b62<\/p>\n<\/li>\n<\/ul>\n<h4>4.2 \u8fdb\u7a0b\u8c03\u5ea6\u7b97\u6cd5<\/h4>\n<h5 style=\"background-color:transparent\">4.2.1 \u5148\u6765\u5148\u670d\u52a1&#xff08;FCFS&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u6309\u8fdb\u7a0b\u5230\u8fbe\u987a\u5e8f\u8c03\u5ea6<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u73b0\u7b80\u5355&#xff0c;\u4f46\u53ef\u80fd\u5bfc\u81f4\u77ed\u8fdb\u7a0b\u7b49\u5f85\u65f6\u95f4\u957f<\/p>\n<\/li>\n<\/ul>\n<h5>4.2.2 \u77ed\u4f5c\u4e1a\u4f18\u5148&#xff08;SJF&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u4f18\u5148\u8c03\u5ea6\u9884\u8ba1\u6267\u884c\u65f6\u95f4\u77ed\u7684\u8fdb\u7a0b<\/p>\n<\/li>\n<li>\n<p>\u6700\u5c0f\u5316\u5e73\u5747\u7b49\u5f85\u65f6\u95f4&#xff0c;\u4f46\u9700\u8981\u9884\u77e5\u6267\u884c\u65f6\u95f4<\/p>\n<\/li>\n<\/ul>\n<h5>4.2.3 \u65f6\u95f4\u7247\u8f6e\u8f6c&#xff08;RR&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u6bcf\u4e2a\u8fdb\u7a0b\u5206\u914d\u56fa\u5b9a\u65f6\u95f4\u7247&#xff08;5-10ms&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u516c\u5e73\u6027\u597d&#xff0c;\u9002\u5408\u4ea4\u4e92\u5f0f\u7cfb\u7edf<\/p>\n<\/li>\n<li>\n<p>\u5b8f\u89c2\u5e76\u884c&#xff0c;\u5fae\u89c2\u4e32\u884c\u6267\u884c<\/p>\n<\/li>\n<\/ul>\n<h5>4.2.4 \u591a\u7ea7\u53cd\u9988\u961f\u5217<\/h5>\n<ul>\n<li>\n<p>\u7ed3\u5408\u591a\u79cd\u8c03\u5ea6\u7b56\u7565<\/p>\n<\/li>\n<li>\n<p>\u52a8\u6001\u8c03\u6574\u8fdb\u7a0b\u4f18\u5148\u7ea7<\/p>\n<\/li>\n<li>\n<p>\u5e73\u8861\u54cd\u5e94\u65f6\u95f4\u548c\u541e\u5410\u91cf<\/p>\n<\/li>\n<\/ul>\n<h3 style=\"background-color:transparent\">5 \u8fdb\u7a0b\u521b\u5efa\u4e0e\u63a7\u5236\u51fd\u6570<\/h3>\n<h4>5.1 fork\u51fd\u6570 &#8211; \u8fdb\u7a0b\u521b\u5efa<\/h4>\n<p>#include &lt;unistd.h&gt;<\/p>\n<p>pid_t fork(void);<\/p>\n<p>\u529f\u80fd\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u521b\u5efa\u5b50\u8fdb\u7a0b&#xff0c;\u5b50\u8fdb\u7a0b\u662f\u7236\u8fdb\u7a0b\u7684\u5b8c\u6574\u526f\u672c<\/p>\n<\/li>\n<li>\n<p>\u590d\u5236\u6587\u672c\u6bb5\u3001\u6570\u636e\u6bb5\u3001\u5806\u6808\u7b49\u6240\u6709\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>\u7236\u5b50\u8fdb\u7a0b\u5e76\u53d1\u6267\u884c&#xff0c;\u6267\u884c\u987a\u5e8f\u4e0d\u786e\u5b9a<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd4\u56de\u503c\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7236\u8fdb\u7a0b&#xff1a;\u8fd4\u56de\u5b50\u8fdb\u7a0bPID&#xff08;&gt;0&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u5b50\u8fdb\u7a0b&#xff1a;\u8fd4\u56de0<\/p>\n<\/li>\n<li>\n<p>\u9519\u8bef&#xff1a;\u8fd4\u56de-1<\/p>\n<\/li>\n<\/ul>\n<h4>5.2 \u8fdb\u7a0b\u4fe1\u606f\u83b7\u53d6\u51fd\u6570<\/h4>\n<p>#include &lt;unistd.h&gt;<\/p>\n<p>pid_t getpid(void);    \/\/ \u83b7\u53d6\u5f53\u524d\u8fdb\u7a0bPID<br \/>\npid_t getppid(void);   \/\/ \u83b7\u53d6\u7236\u8fdb\u7a0bPID<\/p>\n<h4>5.3 \u8fdb\u7a0b\u521b\u5efa\u5b9e\u6218\u793a\u4f8b<\/h4>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;unistd.h&gt;<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n     pid_t pid;<\/p>\n<p>    pid &#061; fork();<br \/>\n    if(-1 &#061;&#061; pid)<br \/>\n    {<br \/>\n        perror(&#034;fail to fork&#034;);<br \/>\n        return -1;<br \/>\n    }<\/p>\n<p>    if(pid &#061;&#061; 0)<br \/>\n    {<br \/>\n        printf(&#034;\u6211\u662f\u5b50\u8fdb\u7a0b,PID:%d,PPID:%d\\\\n&#034;,getpid(),getppid());<br \/>\n    }<br \/>\n    else if(pid &gt;&#061; 1)<br \/>\n    {<br \/>\n        printf(&#034;\u6211\u662f\u7236\u8fdb\u7a0b,PID:%d,childPID:%d\\\\n&#034;,getpid(),pid);<br \/>\n    }<\/p>\n<p>    printf(&#034;hello world\\\\n&#034;);<\/p>\n<p>    while(1)<br \/>\n    {<\/p>\n<p>    }<br \/>\n    return 0;<br \/>\n}<\/p>\n<h3 style=\"background-color:transparent\">6.\u5b9e\u6218\u5e94\u7528&#xff1a;\u5a92\u4f53\u6587\u4ef6\u904d\u5386<\/h3>\n<h4>6.1 \u76ee\u5f55\u904d\u5386\u4e0e\u6587\u4ef6\u8fc7\u6ee4<\/h4>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;sys\/types.h&gt;<br \/>\n#include &lt;sys\/stat.h&gt;<br \/>\n#include &lt;fcntl.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;dirent.h&gt;<\/p>\n<p>void Listdir(char *pdirpath)<br \/>\n{<br \/>\n    DIR *dp &#061; NULL;<br \/>\n    struct dirent *pp &#061; NULL;<br \/>\n    char filepath[512] &#061; {0};<br \/>\n    char *pstr &#061; NULL;<\/p>\n<p>    dp &#061; opendir(pdirpath);<br \/>\n    if (NULL &#061;&#061; dp)<br \/>\n    {<br \/>\n        perror(&#034;fail to opendir&#034;);<br \/>\n        return;<br \/>\n    }<\/p>\n<p>    while (1)<br \/>\n    {<br \/>\n        pp &#061; readdir(dp);<br \/>\n        if (NULL &#061;&#061; pp)<br \/>\n        {<br \/>\n            break;<br \/>\n        }<\/p>\n<p>        if (&#039;.&#039; &#061;&#061; pp-&gt;d_name[0])<br \/>\n        {<br \/>\n            continue;<br \/>\n        }<br \/>\n        pstr &#061; pp-&gt;d_name;<\/p>\n<p>        while(pstr[0] !&#061; &#039;.&#039;)<br \/>\n        {<br \/>\n            if(pstr[0] &#061;&#061; 0)<br \/>\n            {<br \/>\n                break;<br \/>\n            }<br \/>\n            pstr&#043;&#043;;<br \/>\n        }<br \/>\n        pstr&#043;&#043;;<br \/>\n        if ((!strcmp(pstr,&#034;flv&#034;) || !strcmp(pstr,&#034;avi&#034;) || !strcmp(pstr,&#034;rmvb&#034;) || !strcmp(pstr,&#034;rm&#034;)) &amp;&amp; pstr[0] !&#061; &#039;\\\\0&#039;)<br \/>\n        {<br \/>\n            sprintf(filepath, &#034;%s\/%s&#034;, pdirpath, pp-&gt;d_name);<br \/>\n            printf(&#034;%s\\\\n&#034;, filepath);<br \/>\n        }<br \/>\n        if (pp-&gt;d_type &#061;&#061; DT_DIR)<br \/>\n        {<br \/>\n            Listdir(filepath);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    closedir(dp);<\/p>\n<p>    return;<br \/>\n}<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n    char dirpath[256] &#061; {0};<\/p>\n<p>    printf(&#034;\u8bf7\u8f93\u5165\u76ee\u5f55\u8def\u5f84:\\\\n&#034;);<br \/>\n    gets(dirpath);<\/p>\n<p>    Listdir(dirpath);<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 \u8fdb\u7a0b\u57fa\u7840\u6982\u5ff51.1 \u7a0b\u5e8f\u4e0e\u8fdb\u7a0b\u7684\u533a\u522b\u7a0b\u5e8f&#xff1a;\u5b58\u50a8\u5728\u786c\u76d8\u4e0a\u7684\u9759\u6001\u4ee3\u7801\u548c\u6570\u636e\u96c6\u5408&#xff0c;\u662f\u672a\u6267\u884c\u7684\u6307\u4ee4\u5e8f\u5217\u8fdb\u7a0b&#xff1a;\u7a0b\u5e8f\u52a8\u6001\u6267\u884c\u7684\u5b9e\u4f8b&#xff0c;\u5305\u62ec\u521b\u5efa\u3001\u8c03\u5ea6\u3001\u6267\u884c\u5230\u6d88\u4ea1\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\u5173\u952e\u533a\u522b&#xff1a;\u7a0b\u5e8f\u662f\u9759\u6001\u7684&#xff0c;\u8fdb\u7a0b\u662f\u52a8\u6001\u7684\u7a0b\u5e8f\u662f\u5b58\u50a8\u5728\u5b58\u50a8\u4ecb\u8d28\u4e0a\u7684\u6587\u4ef6&#xff0c;\u8fdb\u7a0b\u662f\u5185\u5b58\u4e2d\u7684\u6267\u884c\u5b9e\u4f53\u4e00\u4e2a\u7a0b\u5e8f\u53ef\u4ee5\u5bf9\u5e94\u591a\u4e2a\u8fdb\u7a0b&#xff0c;\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u5bf9\u5e94\u4e00\u4e2a\u7a0b\u5e8f1.2 \u8fdb\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u89d2\u8272\u8fdb\u7a0b\u662f\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u8d44\u6e90\u5206\u914d\u548c\u8c03\u5ea6\u7684\u57fa<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7926,7927,4598,58,1714],"topic":[],"class_list":["post-74852","post","type-post","status-publish","format-standard","hentry","category-server","tag-7926","tag-7927","tag-fork","tag-linux","tag-1714"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux\u8f6f\u4ef6\u7f16\u7a0b: \u8fdb\u7a0b\u89e3\u6790 - \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\/74852.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux\u8f6f\u4ef6\u7f16\u7a0b: \u8fdb\u7a0b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"1 \u8fdb\u7a0b\u57fa\u7840\u6982\u5ff51.1 \u7a0b\u5e8f\u4e0e\u8fdb\u7a0b\u7684\u533a\u522b\u7a0b\u5e8f&#xff1a;\u5b58\u50a8\u5728\u786c\u76d8\u4e0a\u7684\u9759\u6001\u4ee3\u7801\u548c\u6570\u636e\u96c6\u5408&#xff0c;\u662f\u672a\u6267\u884c\u7684\u6307\u4ee4\u5e8f\u5217\u8fdb\u7a0b&#xff1a;\u7a0b\u5e8f\u52a8\u6001\u6267\u884c\u7684\u5b9e\u4f8b&#xff0c;\u5305\u62ec\u521b\u5efa\u3001\u8c03\u5ea6\u3001\u6267\u884c\u5230\u6d88\u4ea1\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\u5173\u952e\u533a\u522b&#xff1a;\u7a0b\u5e8f\u662f\u9759\u6001\u7684&#xff0c;\u8fdb\u7a0b\u662f\u52a8\u6001\u7684\u7a0b\u5e8f\u662f\u5b58\u50a8\u5728\u5b58\u50a8\u4ecb\u8d28\u4e0a\u7684\u6587\u4ef6&#xff0c;\u8fdb\u7a0b\u662f\u5185\u5b58\u4e2d\u7684\u6267\u884c\u5b9e\u4f53\u4e00\u4e2a\u7a0b\u5e8f\u53ef\u4ee5\u5bf9\u5e94\u591a\u4e2a\u8fdb\u7a0b&#xff0c;\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u5bf9\u5e94\u4e00\u4e2a\u7a0b\u5e8f1.2 \u8fdb\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u89d2\u8272\u8fdb\u7a0b\u662f\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u8d44\u6e90\u5206\u914d\u548c\u8c03\u5ea6\u7684\u57fa\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/74852.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-10T12:25:02+00:00\" \/>\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=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74852.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/74852.html\",\"name\":\"Linux\u8f6f\u4ef6\u7f16\u7a0b: \u8fdb\u7a0b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-10T12:25:02+00:00\",\"dateModified\":\"2026-02-10T12:25:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/74852.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/74852.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74852.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\u8f6f\u4ef6\u7f16\u7a0b: \u8fdb\u7a0b\u89e3\u6790\"}]},{\"@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":"Linux\u8f6f\u4ef6\u7f16\u7a0b: \u8fdb\u7a0b\u89e3\u6790 - \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\/74852.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux\u8f6f\u4ef6\u7f16\u7a0b: \u8fdb\u7a0b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"1 \u8fdb\u7a0b\u57fa\u7840\u6982\u5ff51.1 \u7a0b\u5e8f\u4e0e\u8fdb\u7a0b\u7684\u533a\u522b\u7a0b\u5e8f&#xff1a;\u5b58\u50a8\u5728\u786c\u76d8\u4e0a\u7684\u9759\u6001\u4ee3\u7801\u548c\u6570\u636e\u96c6\u5408&#xff0c;\u662f\u672a\u6267\u884c\u7684\u6307\u4ee4\u5e8f\u5217\u8fdb\u7a0b&#xff1a;\u7a0b\u5e8f\u52a8\u6001\u6267\u884c\u7684\u5b9e\u4f8b&#xff0c;\u5305\u62ec\u521b\u5efa\u3001\u8c03\u5ea6\u3001\u6267\u884c\u5230\u6d88\u4ea1\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\u5173\u952e\u533a\u522b&#xff1a;\u7a0b\u5e8f\u662f\u9759\u6001\u7684&#xff0c;\u8fdb\u7a0b\u662f\u52a8\u6001\u7684\u7a0b\u5e8f\u662f\u5b58\u50a8\u5728\u5b58\u50a8\u4ecb\u8d28\u4e0a\u7684\u6587\u4ef6&#xff0c;\u8fdb\u7a0b\u662f\u5185\u5b58\u4e2d\u7684\u6267\u884c\u5b9e\u4f53\u4e00\u4e2a\u7a0b\u5e8f\u53ef\u4ee5\u5bf9\u5e94\u591a\u4e2a\u8fdb\u7a0b&#xff0c;\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u5bf9\u5e94\u4e00\u4e2a\u7a0b\u5e8f1.2 \u8fdb\u7a0b\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u89d2\u8272\u8fdb\u7a0b\u662f\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u8d44\u6e90\u5206\u914d\u548c\u8c03\u5ea6\u7684\u57fa","og_url":"https:\/\/www.wsisp.com\/helps\/74852.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-10T12:25:02+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/74852.html","url":"https:\/\/www.wsisp.com\/helps\/74852.html","name":"Linux\u8f6f\u4ef6\u7f16\u7a0b: \u8fdb\u7a0b\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-10T12:25:02+00:00","dateModified":"2026-02-10T12:25:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/74852.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/74852.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/74852.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux\u8f6f\u4ef6\u7f16\u7a0b: \u8fdb\u7a0b\u89e3\u6790"}]},{"@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\/74852","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=74852"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/74852\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=74852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=74852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=74852"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=74852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}