{"id":119212,"date":"2026-10-29T03:48:26","date_gmt":"2026-10-28T19:48:26","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/119212.html"},"modified":"2026-10-29T03:48:26","modified_gmt":"2026-10-28T19:48:26","slug":"linux%e8%bf%9b%e7%a8%8b%e6%a0%b8%e5%bf%83%e8%80%83%e7%82%b9%e7%b2%be%e8%a6%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/119212.html","title":{"rendered":"Linux\u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u7cbe\u8981"},"content":{"rendered":"<h2>Linux \u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u4e0e\u5b9e\u6218\u7b14\u8bb0&#xff08;\u5d4c\u5165\u5f0f\/\u540e\u53f0\u9762\u8bd5\u5411&#xff09;<\/h2>\n<h3>\u4e00\u3001\u8fdb\u7a0b\u672c\u8d28\u4e0e PCB \u7ba1\u7406<\/h3>\n<p>\u8fdb\u7a0b\u662f\u7a0b\u5e8f\u7684\u4e00\u6b21\u52a8\u6001\u6267\u884c\u8fc7\u7a0b&#xff0c;\u533a\u522b\u4e8e\u78c1\u76d8\u4e0a\u9759\u6001\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff08;\u5982 a.out&#xff09;\u3002\u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7\u8fdb\u7a0b\u63a7\u5236\u5757&#xff08;PCB&#xff09;&#xff08;Linux \u4e2d\u4e3a task_struct \u7ed3\u6784\u4f53&#xff09;\u5bf9\u8fdb\u7a0b\u8fdb\u884c\u5168\u751f\u547d\u5468\u671f\u7ba1\u7406 \u3002<\/p>\n<table>\n<tr>\u6838\u5fc3\u8981\u7d20\u8bf4\u660e\u9762\u8bd5\u5173\u952e\u70b9<\/tr>\n<tbody>\n<tr>\n<td style=\"text-align:left\">PID<\/td>\n<td style=\"text-align:left\">\u8fdb\u7a0b\u552f\u4e00\u6807\u8bc6\u7b26<\/td>\n<td style=\"text-align:left\">\u5168\u5c40\u552f\u4e00&#xff0c;\u56de\u6536\u540e\u53ef\u80fd\u590d\u7528<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">\u8d44\u6e90\u63cf\u8ff0<\/td>\n<td style=\"text-align:left\">\u6253\u5f00\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868\u3001\u5185\u5b58\u6620\u5c04\u3001IO \u8bbe\u5907<\/td>\n<td style=\"text-align:left\">\u6587\u4ef6\u63cf\u8ff0\u7b26\u7ee7\u627f\u673a\u5236<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">\u8c03\u5ea6\u4fe1\u606f<\/td>\n<td style=\"text-align:left\">\u4f18\u5148\u7ea7\u3001\u72b6\u6001\u3001\u65f6\u95f4\u7247\u7edf\u8ba1<\/td>\n<td style=\"text-align:left\">CFS \u8c03\u5ea6\u7b97\u6cd5\u57fa\u7840<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">\u4e0a\u4e0b\u6587<\/td>\n<td style=\"text-align:left\">\u5bc4\u5b58\u5668\u503c\u3001\u6808\u6307\u9488\u3001\u7a0b\u5e8f\u8ba1\u6570\u5668<\/td>\n<td style=\"text-align:left\">\u8fdb\u7a0b\u5207\u6362\u65f6\u7684\u4fdd\u5b58\u4e0e\u6062\u590d<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">\u6743\u9650\u63a7\u5236<\/td>\n<td style=\"text-align:left\">UID\/GID\u3001umask \u63a9\u7801<\/td>\n<td style=\"text-align:left\">\u5b89\u5168\u6027\u4e0e\u6587\u4ef6\u8bbf\u95ee\u63a7\u5236<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5e76\u53d1 vs \u5e76\u884c&#xff1a;<\/p>\n<ul>\n<li>\u5e76\u53d1 (Concurrency)&#xff1a;\u5355\u6838 CPU \u901a\u8fc7\u65f6\u95f4\u7247\u8f6e\u8f6c\u5feb\u901f\u5207\u6362\u4efb\u52a1&#xff0c;\u5b8f\u89c2\u201c\u540c\u65f6\u201d&#xff0c;\u5fae\u89c2\u4e32\u884c\u3002<\/li>\n<li>\u5e76\u884c (Parallelism)&#xff1a;\u591a\u6838 CPU \u591a\u4e2a\u4efb\u52a1\u5728\u4e0d\u540c\u6838\u5fc3\u4e0a\u771f\u6b63\u540c\u65f6\u6267\u884c \u3002<\/li>\n<\/ul>\n<h3>\u4e8c\u3001\u865a\u62df\u5185\u5b58\u5206\u5e03&#xff08;32 \u4f4d\u6a21\u578b&#xff09;<\/h3>\n<p>32 \u4f4d\u7cfb\u7edf\u4e0b&#xff0c;4GB \u5730\u5740\u7a7a\u95f4\u901a\u5e38\u5212\u5206\u4e3a 3GB \u7528\u6237\u7a7a\u95f4 &#043; 1GB \u5185\u6838\u7a7a\u95f4\u3002<\/p>\n<p>\u9ad8\u5730\u5740<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n|   \u5185\u6838\u7a7a\u95f4 (1G)   | &lt;&#8212; \u7528\u6237\u6001\u4e0d\u53ef\u76f4\u63a5\u8bbf\u95ee<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n|       \u6808         | &lt;&#8212; \u5411\u4e0b\u589e\u957f (\u9ed8\u8ba4 8M, ulimit -s)<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n|  \u5171\u4eab\u5e93\/mmap \u533a   | &lt;&#8212; \u52a8\u6001\u5e93\u3001\u6587\u4ef6\u6620\u5c04<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n|       \u5806         | &lt;&#8212; \u5411\u4e0a\u589e\u957f (malloc\/free)<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n|    \u6570\u636e\u6bb5 (BSS)   | &lt;&#8212; \u672a\u521d\u59cb\u5316\u5168\u5c40\/\u9759\u6001\u53d8\u91cf<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n|    \u6570\u636e\u6bb5 (Data)  | &lt;&#8212; \u5df2\u521d\u59cb\u5316\u5168\u5c40\/\u9759\u6001\u53d8\u91cf<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n|    \u4ee3\u7801\u6bb5 (Text)  | &lt;&#8212; \u53ea\u8bfb\u6307\u4ee4<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n\u4f4e\u5730\u5740<\/p>\n<p>\u8d44\u6e90\u9650\u5236\u67e5\u770b&#xff1a; \u4f7f\u7528 ulimit -a \u67e5\u770b\u8fdb\u7a0b\u8d44\u6e90\u7ea6\u675f&#xff0c;\u5d4c\u5165\u5f0f\u5f00\u53d1\u9700\u91cd\u70b9\u5173\u6ce8&#xff1a;<\/p>\n<ul>\n<li>open files (-n)&#xff1a;\u9ed8\u8ba4 1024&#xff0c;\u9ad8\u5e76\u53d1\u670d\u52a1\u5668\u9700\u8c03\u5927\u3002<\/li>\n<li>stack size (-s)&#xff1a;\u9ed8\u8ba4 8192KB&#xff0c;\u9012\u5f52\u8fc7\u6df1\u6613\u5bfc\u81f4 Stack Overflow \u3002<\/li>\n<\/ul>\n<h3>\u4e09\u3001fork() \u673a\u5236\u4e0e\u5199\u65f6\u590d\u5236 (COW)<\/h3>\n<p>fork() \u662f Linux \u521b\u5efa\u8fdb\u7a0b\u7684\u6838\u5fc3\u7cfb\u7edf\u8c03\u7528&#xff0c;\u5176\u7279\u6027\u4e3a**\u201c\u4e00\u6b21\u8c03\u7528&#xff0c;\u4e24\u6b21\u8fd4\u56de\u201d**\u3002<\/p>\n<h4>1. \u8fd4\u56de\u503c\u903b\u8f91<\/h4>\n<p>#include &lt;unistd.h&gt;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<\/p>\n<p>int main() {<br \/>\n    pid_t pid &#061; fork();<\/p>\n<p>    if (pid &lt; 0) {<br \/>\n        \/\/ \u521b\u5efa\u5931\u8d25<br \/>\n        perror(&#034;fork failed&#034;);<br \/>\n        exit(1);<br \/>\n    } else if (pid &#061;&#061; 0) {<br \/>\n        \/\/ \u5b50\u8fdb\u7a0b\u903b\u8f91<br \/>\n        printf(&#034;Child Process: PID&#061;%d, PPID&#061;%d<br \/>\n&#034;, getpid(), getppid());<br \/>\n        exit(0);<br \/>\n    } else {<br \/>\n        \/\/ \u7236\u8fdb\u7a0b\u903b\u8f91        printf(&#034;Parent Process: PID&#061;%d, Child_PID&#061;%d<br \/>\n&#034;, getpid(), pid);<br \/>\n        \/\/ \u5fc5\u987b\u56de\u6536\u5b50\u8fdb\u7a0b&#xff0c;\u9632\u6b62\u50f5\u5c38<br \/>\n        wait(NULL);<br \/>\n    }<br \/>\n    return 0;<br \/>\n}<\/p>\n<h4>2. \u6838\u5fc3\u7279\u6027\u89e3\u6790<\/h4>\n<ul>\n<li>\u4ee3\u7801\u6267\u884c\u70b9&#xff1a;\u5b50\u8fdb\u7a0b\u4ece fork() \u8fd4\u56de\u5904\u5f00\u59cb\u6267\u884c&#xff0c;\u800c\u975e\u91cd\u65b0\u8fd0\u884c main\u3002<\/li>\n<li>\u72ec\u7acb\u6027&#xff1a;\u7236\u5b50\u8fdb\u7a0b\u62e5\u6709\u72ec\u7acb\u7684 PID \u548c PCB&#xff0c;\u4f46\u521d\u59cb\u4ee3\u7801\u903b\u8f91\u76f8\u540c\u3002<\/li>\n<li>\u5199\u65f6\u590d\u5236 (Copy On Write)&#xff1a;\n<ul>\n<li>fork \u77ac\u95f4&#xff1a;\u7236\u5b50\u8fdb\u7a0b\u5171\u4eab\u7269\u7406\u5185\u5b58\u9875&#xff0c;\u5185\u6838\u5c06\u9875\u9762\u6807\u8bb0\u4e3a\u53ea\u8bfb\u3002<\/li>\n<li>\u4fee\u6539\u53d1\u751f\u65f6&#xff1a;\u82e5\u4efb\u610f\u4e00\u65b9\u5c1d\u8bd5\u5199\u5165&#xff0c;\u5185\u6838\u89e6\u53d1\u7f3a\u9875\u5f02\u5e38&#xff0c;\u5355\u72ec\u62f7\u8d1d\u4e00\u4efd\u7269\u7406\u5185\u5b58\u7ed9\u4fee\u6539\u65b9&#xff0c;\u5b9e\u73b0\u5ef6\u8fdf\u62f7\u8d1d&#xff0c;\u6781\u5927\u964d\u4f4e\u5f00\u9500 \u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u8c03\u5ea6\u4e0d\u786e\u5b9a\u6027&#xff1a;\u7236\u5b50\u8fdb\u7a0b\u8c01\u5148\u8fd0\u884c\u7531\u5185\u6838\u8c03\u5ea6\u5668\u51b3\u5b9a&#xff0c;\u4e0d\u53ef\u5047\u8bbe\u987a\u5e8f\u3002<\/li>\n<\/ul>\n<h3>\u56db\u3001\u8fdb\u7a0b\u72b6\u6001\u6d41\u8f6c\u4e0e\u7279\u6b8a\u5f62\u6001<\/h3>\n<p>Linux \u8fdb\u7a0b\u72b6\u6001\u4e3b\u8981\u5305\u542b\u4ee5\u4e0b\u51e0\u79cd&#xff0c;\u5176\u4e2d Z \u6001 \u662f\u9762\u8bd5\u9ad8\u9891\u8003\u70b9\u3002<\/p>\n<table>\n<tr>\u72b6\u6001\u7801\u72b6\u6001\u540d\u79f0\u542b\u4e49\u80fd\u5426\u88ab\u4fe1\u53f7\u5524\u9192<\/tr>\n<tbody>\n<tr>\n<td style=\"text-align:left\">R<\/td>\n<td style=\"text-align:left\">Running<\/td>\n<td style=\"text-align:left\">\u6b63\u5728\u8fd0\u884c\u6216\u5728\u5c31\u7eea\u961f\u5217\u7b49\u5f85\u8c03\u5ea6<\/td>\n<td style=\"text-align:left\">N\/A<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">S<\/td>\n<td style=\"text-align:left\">Interruptible Sleep<\/td>\n<td style=\"text-align:left\">\u53ef\u4e2d\u65ad\u7761\u7720&#xff0c;\u7b49\u5f85\u8d44\u6e90<\/td>\n<td style=\"text-align:left\">\u80fd<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">D<\/td>\n<td style=\"text-align:left\">Uninterruptible Sleep<\/td>\n<td style=\"text-align:left\">\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720&#xff0c;\u901a\u5e38\u5728\u7b49\u5f85 IO<\/td>\n<td style=\"text-align:left\">\u4e0d\u80fd<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">T<\/td>\n<td style=\"text-align:left\">Stopped<\/td>\n<td style=\"text-align:left\">\u6682\u505c\u6001&#xff0c;\u6536\u5230 SIGSTOP \u7b49\u4fe1\u53f7<\/td>\n<td style=\"text-align:left\">\u80fd (SIGCONT)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">Z<\/td>\n<td style=\"text-align:left\">Zombie<\/td>\n<td style=\"text-align:left\">\u50f5\u6b7b\u6001&#xff0c;\u8fdb\u7a0b\u7ed3\u675f\u4f46 PCB \u672a\u56de\u6536<\/td>\n<td style=\"text-align:left\">\u4e0d\u80fd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u91cd\u70b9\u8fa8\u6790&#xff1a;\u5b64\u513f\u8fdb\u7a0b vs \u50f5\u5c38\u8fdb\u7a0b<\/h4>\n<ul>\n<li>\u5b64\u513f\u8fdb\u7a0b (Orphan)&#xff1a;\u7236\u8fdb\u7a0b\u5148\u9000\u51fa&#xff0c;\u5b50\u8fdb\u7a0b\u4ecd\u5728\u8fd0\u884c\u3002\n<ul>\n<li>\u5904\u7406\u673a\u5236&#xff1a;\u88ab init (PID 1) \u6216 systemd \u8fdb\u7a0b\u6536\u517b&#xff0c;\u8d44\u6e90\u81ea\u52a8\u56de\u6536&#xff0c;\u65e0\u5bb3\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u50f5\u5c38\u8fdb\u7a0b (Zombie)&#xff1a;\u5b50\u8fdb\u7a0b\u5148\u9000\u51fa&#xff0c;\u7236\u8fdb\u7a0b\u672a\u8c03\u7528 wait\/waitpid \u56de\u6536\u3002\n<ul>\n<li>\u5371\u5bb3&#xff1a;\u7528\u6237\u7a7a\u95f4\u8d44\u6e90\u5df2\u91ca\u653e&#xff0c;\u4f46 PCB \u4ecd\u9a7b\u7559\u5185\u6838&#xff0c;\u5360\u7528\u5185\u6838\u5185\u5b58\u69fd\u4f4d\u3002\u5927\u91cf\u50f5\u5c38\u8fdb\u7a0b\u4f1a\u5bfc\u81f4\u65e0\u6cd5\u521b\u5efa\u65b0\u8fdb\u7a0b \u3002<\/li>\n<li>\u89e3\u51b3&#xff1a;\u7236\u8fdb\u7a0b\u5fc5\u987b\u6b63\u786e\u5904\u7406\u4fe1\u53f7\u6216\u8c03\u7528 wait \u7cfb\u5217\u51fd\u6570&#xff1b;\u82e5\u7236\u8fdb\u7a0b\u50f5\u6b7b&#xff0c;\u9700\u6740\u6b7b\u7236\u8fdb\u7a0b\u8ba9 init \u6536\u517b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u4e94\u3001\u8fdb\u7a0b\u9000\u51fa\u7684 8 \u79cd\u65b9\u5f0f\u4e0e exit\/_exit \u533a\u522b<\/h3>\n<p>\u8fdb\u7a0b\u7ec8\u6b62\u5206\u4e3a\u6b63\u5e38\u9000\u51fa\u3001\u7cfb\u7edf\u8c03\u7528\u9000\u51fa\u548c\u5f02\u5e38\u7ec8\u6b62\u3002<\/p>\n<h4>1. \u9000\u51fa\u65b9\u5f0f\u5206\u7c7b<\/h4>\n<ul>\n<li>\u6b63\u5e38\u9000\u51fa&#xff1a;\n<li>main \u51fd\u6570 return\u3002<\/li>\n<li>exit()&#xff1a;C \u5e93\u51fd\u6570&#xff0c;\u6267\u884c\u6e05\u7406\u5de5\u4f5c\u3002<\/li>\n<\/li>\n<\/ul>\n<li>pthread_exit()&#xff1a;\u4e3b\u7ebf\u7a0b\u9000\u51fa\u3002<\/li>\n<ul>\n<li>\u7cfb\u7edf\u8c03\u7528\u9000\u51fa&#xff1a; 4. _exit() \/ _Exit()&#xff1a;\u76f4\u63a5\u9677\u5165\u5185\u6838&#xff0c;\u4e0d\u6267\u884c\u7528\u6237\u6001\u6e05\u7406\u3002<\/li>\n<li>\u5f02\u5e38\u7ec8\u6b62&#xff1a; 5. abort()&#xff1a;\u53d1\u9001 SIGABRT \u4fe1\u53f7\u3002 6. \u4fe1\u53f7\u6740\u6b7b&#xff1a;kill \u547d\u4ee4\u6216\u4ee3\u7801\u89e6\u53d1 SIGKILL\/SIGTERM\u3002 7. \u7ebf\u7a0b\u53d6\u6d88&#xff1a;\u6700\u540e\u4e00\u4e2a\u7ebf\u7a0b\u88ab pthread_cancel\u3002<\/li>\n<\/ul>\n<h4>2. \u6838\u5fc3\u9762\u8bd5\u9898&#xff1a;exit() vs _exit()<\/h4>\n<table>\n<tr>\u7279\u6027exit()_exit() \/ _Exit()<\/tr>\n<tbody>\n<tr>\n<td style=\"text-align:left\">\u5f52\u5c5e<\/td>\n<td style=\"text-align:left\">C \u6807\u51c6\u5e93 (stdlib.h)<\/td>\n<td style=\"text-align:left\">\u7cfb\u7edf\u8c03\u7528 (unistd.h)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">\u7f13\u51b2\u533a\u5904\u7406<\/td>\n<td style=\"text-align:left\">\u5237\u65b0 stdio \u7f13\u51b2\u533a (fwrite \u5185\u5bb9\u5199\u5165\u6587\u4ef6)<\/td>\n<td style=\"text-align:left\">\u4e0d\u5237\u65b0&#xff0c;\u76f4\u63a5\u4e22\u5f03\u7f13\u51b2\u533a\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">\u6e05\u7406\u94a9\u5b50<\/td>\n<td style=\"text-align:left\">\u6267\u884c atexit \u6ce8\u518c\u7684\u56de\u8c03\u51fd\u6570<\/td>\n<td style=\"text-align:left\">\u4e0d\u6267\u884c\u4efb\u4f55\u6e05\u7406\u94a9\u5b50<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">\u5e95\u5c42\u52a8\u4f5c<\/td>\n<td style=\"text-align:left\">\u8c03\u7528 _exit() \u8fdb\u5165\u5185\u6838<\/td>\n<td style=\"text-align:left\">\u76f4\u63a5\u8fdb\u5165\u5185\u6838\u91ca\u653e\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">\u5e94\u7528\u573a\u666f<\/td>\n<td style=\"text-align:left\">\u666e\u901a\u7a0b\u5e8f\u6b63\u5e38\u7ed3\u675f<\/td>\n<td style=\"text-align:left\">fork \u540e\u7684\u5b50\u8fdb\u7a0b\u51fa\u9519\u9000\u51fa (\u907f\u514d\u91cd\u590d\u5237\u65b0\u7236\u8fdb\u7a0b\u7f13\u51b2\u533a)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ee3\u7801\u793a\u4f8b&#xff1a;\u9a8c\u8bc1\u7f13\u51b2\u533a\u5dee\u5f02<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<\/p>\n<p>int main() {<br \/>\n    printf(&#034;Before fork: This is in buffer<br \/>\n&#034;); \/\/ \u6b64\u65f6\u6570\u636e\u5728\u7f13\u51b2\u533a&#xff0c;\u672a\u5199\u5165\u7ec8\u7aef<\/p>\n<p>    pid_t pid &#061; fork();<\/p>\n<p>    if (pid &#061;&#061; 0) {<br \/>\n        \/\/ \u5b50\u8fdb\u7a0b&#xff1a;\u4f7f\u7528 _exit \u907f\u514d\u5237\u65b0\u7236\u8fdb\u7a0b\u7684\u7f13\u51b2\u533a&#xff0c;\u9632\u6b62\u8f93\u51fa\u91cd\u590d<br \/>\n        _exit(0);<br \/>\n    } else {<br \/>\n        \/\/ \u7236\u8fdb\u7a0b&#xff1a;\u7b49\u5f85\u540e\u6b63\u5e38\u9000\u51fa&#xff0c;\u4f1a\u5237\u65b0\u7f13\u51b2\u533a<br \/>\n        sleep(1); exit(0);<br \/>\n    }<br \/>\n    \/\/ \u82e5\u5b50\u8fdb\u7a0b\u4e5f\u7528 exit(0)&#xff0c;&#034;Before fork&#8230;&#034; \u4f1a\u88ab\u6253\u5370\u4e24\u6b21<br \/>\n}<\/p>\n<h3>\u516d\u3001\u5e38\u7528\u8c03\u8bd5\u547d\u4ee4\u4e0e\u8c03\u5ea6\u7b97\u6cd5<\/h3>\n<h4>1. \u5173\u952e\u547d\u4ee4<\/h4>\n<ul>\n<li>ps aux&#xff1a;\u9759\u6001\u5feb\u7167&#xff0c;\u67e5\u770b PID\u3001STAT (\u72b6\u6001)\u3001CMD\u3002<\/li>\n<li>top&#xff1a;\u52a8\u6001\u76d1\u63a7&#xff0c;\u5b9e\u65f6\u67e5\u770b CPU\/Mem \u5360\u7528&#xff0c;\u6309 P \u6309 CPU \u6392\u5e8f&#xff0c;M \u6309\u5185\u5b58\u6392\u5e8f\u3002<\/li>\n<li>pstree&#xff1a;\u6811\u72b6\u5c55\u793a\u8fdb\u7a0b\u7236\u5b50\u5173\u7cfb&#xff0c;\u5feb\u901f\u5b9a\u4f4d\u5b64\u513f\/\u50f5\u5c38\u94fe\u3002<\/li>\n<li>kill -l&#xff1a;\u67e5\u770b\u6240\u6709\u53ef\u7528\u4fe1\u53f7\u5217\u8868\u3002<\/li>\n<\/ul>\n<h4>2. Linux \u8c03\u5ea6\u7b56\u7565<\/h4>\n<p>\u73b0\u4ee3 Linux \u5185\u6838\u9ed8\u8ba4\u91c7\u7528 CFS (Completely Fair Scheduler&#xff0c;\u5b8c\u5168\u516c\u5e73\u8c03\u5ea6) \u7b97\u6cd5&#xff0c;\u53d6\u4ee3\u4e86\u65e9\u671f\u7684 O(1) \u8c03\u5ea6\u5668\u3002<\/p>\n<ul>\n<li>\u6838\u5fc3\u601d\u60f3&#xff1a;\u57fa\u4e8e\u7ea2\u9ed1\u6811\u7ef4\u62a4\u6240\u6709\u53ef\u8fd0\u884c\u8fdb\u7a0b&#xff0c;\u6839\u636e vruntime (\u865a\u62df\u8fd0\u884c\u65f6\u95f4) \u9009\u62e9\u6700\u5c0f\u8282\u70b9\u6267\u884c&#xff0c;\u786e\u4fdd\u6bcf\u4e2a\u8fdb\u7a0b\u83b7\u5f97\u516c\u5e73\u7684 CPU \u65f6\u95f4\u7247 \u3002<\/li>\n<li>\u5176\u4ed6\u7b56\u7565&#xff1a;\u5b9e\u65f6\u8fdb\u7a0b\u53ef\u91c7\u7528 SCHED_FIFO (\u5148\u8fdb\u5148\u51fa) \u6216 SCHED_RR (\u65f6\u95f4\u7247\u8f6e\u8f6c)\u3002## \u4e03\u3001\u603b\u7ed3\u4e0e\u8fdb\u9636\u65b9\u5411 \u8fdb\u7a0b\u7ba1\u7406\u662f\u5d4c\u5165\u5f0f Linux \u4e0e\u540e\u53f0\u5f00\u53d1\u7684\u57fa\u77f3\u3002\u9762\u8bd5\u4e2d\u9700\u719f\u7ec3\u638c\u63e1&#xff1a;<\/li>\n<\/ul>\n<li>fork \u7684 COW \u673a\u5236\u53ca\u5176\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u3002<\/li>\n<li>\u50f5\u5c38\u8fdb\u7a0b\u7684\u4ea7\u751f\u539f\u7406\u53ca wait\/waitpid \u7684\u6b63\u786e\u7528\u6cd5\u3002<\/li>\n<li>exit \u4e0e _exit \u7684\u5e95\u5c42\u533a\u522b&#xff08;\u7f13\u51b2\u533a\u4e0e\u94a9\u5b50\u51fd\u6570&#xff09;\u3002<\/li>\n<li>\u8fdb\u7a0b\u72b6\u6001\u673a\u8f6c\u6362&#xff0c;\u7279\u522b\u662f D \u6001\u4e0e Z \u6001\u7684\u5904\u7406\u3002<\/li>\n<p>\u540e\u7eed\u5b66\u4e60\u8def\u7ebf&#xff1a;<\/p>\n<ul>\n<li>\u8fdb\u7a0b\u56de\u6536&#xff1a;\u6df1\u5165 waitpid \u9009\u9879\u4e0e\u975e\u963b\u585e\u56de\u6536\u3002<\/li>\n<li>\u8fdb\u7a0b\u6620\u50cf\u66ff\u6362&#xff1a;exec \u65cf\u51fd\u6570 (execl, execvp \u7b49) \u7684\u4f7f\u7528\u573a\u666f\u3002<\/li>\n<li>\u8fdb\u7a0b\u95f4\u901a\u4fe1 (IPC)&#xff1a;\u7ba1\u9053 (Pipe)\u3001\u6d88\u606f\u961f\u5217\u3001\u5171\u4eab\u5185\u5b58\u3001\u4fe1\u53f7\u91cf\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u53c2\u8003\u6765\u6e90<\/h3>\n<ul>\n<li>\u7f51\u6613\u540e\u7aef\u9762\u8bd5\u5168\u653b\u7565&#xff1a;\u4ece\u9ad8\u9891\u8003\u70b9\u5230\u5b9e\u6218\u65b9\u6848<\/li>\n<li>\u8d1d\u58f3\u627e\u623fJava\u7b14\u8bd5\u5168\u89e3\u6790&#xff1a;\u8003\u70b9\u5206\u5e03\u3001OOM\u6392\u67e5\u4e0e\u6392\u5e8f\u7b97\u6cd5\u5b9e\u6218<\/li>\n<\/ul>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux \u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u4e0e\u5b9e\u6218\u7b14\u8bb0&#xff08;\u5d4c\u5165\u5f0f\/\u540e\u53f0\u9762\u8bd5\u5411&#xff09;<br \/>\n\u4e00\u3001\u8fdb\u7a0b\u672c\u8d28\u4e0e PCB \u7ba1\u7406<br \/>\n\u8fdb\u7a0b\u662f\u7a0b\u5e8f\u7684\u4e00\u6b21\u52a8\u6001\u6267\u884c\u8fc7\u7a0b&#xff0c;\u533a\u522b\u4e8e\u78c1\u76d8\u4e0a\u9759\u6001\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff08;\u5982 a.out&#xff09;\u3002\u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7\u8fdb\u7a0b\u63a7\u5236\u5757&#xff08;PCB&#xff09;&#xff08;Linux \u4e2d\u4e3a task_struct \u7ed3\u6784\u4f53&#xff09;\u5bf9\u8fdb\u7a0b\u8fdb\u884c\u5168\u751f\u547d\u5468\u671f\u7ba1\u7406 \u3002<br \/>\n\u6838\u5fc3\u8981\u7d20\u8bf4\u660e\u9762\u8bd5\u5173\u952e\u70b9PID\u8fdb\u7a0b\u552f\u4e00\u6807\u8bc6\u7b26\u5168\u5c40\u552f\u4e00&#xff0c;\u56de<\/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":[174,58,103,148],"topic":[],"class_list":["post-119212","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-linux","tag-ubuntu","tag-visual-studio-code"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux\u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u7cbe\u8981 - \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\/119212.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux\u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u7cbe\u8981 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Linux \u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u4e0e\u5b9e\u6218\u7b14\u8bb0&#xff08;\u5d4c\u5165\u5f0f\/\u540e\u53f0\u9762\u8bd5\u5411&#xff09; \u4e00\u3001\u8fdb\u7a0b\u672c\u8d28\u4e0e PCB \u7ba1\u7406 \u8fdb\u7a0b\u662f\u7a0b\u5e8f\u7684\u4e00\u6b21\u52a8\u6001\u6267\u884c\u8fc7\u7a0b&#xff0c;\u533a\u522b\u4e8e\u78c1\u76d8\u4e0a\u9759\u6001\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff08;\u5982 a.out&#xff09;\u3002\u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7\u8fdb\u7a0b\u63a7\u5236\u5757&#xff08;PCB&#xff09;&#xff08;Linux \u4e2d\u4e3a task_struct \u7ed3\u6784\u4f53&#xff09;\u5bf9\u8fdb\u7a0b\u8fdb\u884c\u5168\u751f\u547d\u5468\u671f\u7ba1\u7406 \u3002 \u6838\u5fc3\u8981\u7d20\u8bf4\u660e\u9762\u8bd5\u5173\u952e\u70b9PID\u8fdb\u7a0b\u552f\u4e00\u6807\u8bc6\u7b26\u5168\u5c40\u552f\u4e00&#xff0c;\u56de\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/119212.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-28T19:48:26+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\/119212.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/119212.html\",\"name\":\"Linux\u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u7cbe\u8981 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-28T19:48:26+00:00\",\"dateModified\":\"2026-10-28T19:48:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/119212.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/119212.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/119212.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux\u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u7cbe\u8981\"}]},{\"@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\u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u7cbe\u8981 - \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\/119212.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux\u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u7cbe\u8981 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Linux \u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u4e0e\u5b9e\u6218\u7b14\u8bb0&#xff08;\u5d4c\u5165\u5f0f\/\u540e\u53f0\u9762\u8bd5\u5411&#xff09; \u4e00\u3001\u8fdb\u7a0b\u672c\u8d28\u4e0e PCB \u7ba1\u7406 \u8fdb\u7a0b\u662f\u7a0b\u5e8f\u7684\u4e00\u6b21\u52a8\u6001\u6267\u884c\u8fc7\u7a0b&#xff0c;\u533a\u522b\u4e8e\u78c1\u76d8\u4e0a\u9759\u6001\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6&#xff08;\u5982 a.out&#xff09;\u3002\u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7\u8fdb\u7a0b\u63a7\u5236\u5757&#xff08;PCB&#xff09;&#xff08;Linux \u4e2d\u4e3a task_struct \u7ed3\u6784\u4f53&#xff09;\u5bf9\u8fdb\u7a0b\u8fdb\u884c\u5168\u751f\u547d\u5468\u671f\u7ba1\u7406 \u3002 \u6838\u5fc3\u8981\u7d20\u8bf4\u660e\u9762\u8bd5\u5173\u952e\u70b9PID\u8fdb\u7a0b\u552f\u4e00\u6807\u8bc6\u7b26\u5168\u5c40\u552f\u4e00&#xff0c;\u56de","og_url":"https:\/\/www.wsisp.com\/helps\/119212.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-28T19:48:26+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\/119212.html","url":"https:\/\/www.wsisp.com\/helps\/119212.html","name":"Linux\u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u7cbe\u8981 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-28T19:48:26+00:00","dateModified":"2026-10-28T19:48:26+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/119212.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/119212.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/119212.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux\u8fdb\u7a0b\u6838\u5fc3\u8003\u70b9\u7cbe\u8981"}]},{"@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\/119212","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=119212"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/119212\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=119212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=119212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=119212"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=119212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}