{"id":63171,"date":"2025-04-29T08:10:44","date_gmt":"2025-04-29T00:10:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63171\/"},"modified":"2025-04-29T08:10:44","modified_gmt":"2025-04-29T00:10:44","slug":"%e6%9f%a5%e6%89%belinux%e5%86%85%e6%a0%b8%e6%ba%90%e4%bb%a3%e7%a0%81%e7%9a%84%e6%9c%80%e4%bd%b3%e9%80%94%e5%be%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63171\/","title":{"rendered":"\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u7684\u6700\u4f73\u9014\u5f84"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/171039132593165.jpg\" class=\"aligncenter\" title=\"\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u7684\u6700\u4f73\u9014\u5f84\u63d2\u56fe\" alt=\"\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u7684\u6700\u4f73\u9014\u5f84\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6807\u9898\uff1a\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u7684\u6700\u4f73\u9014\u5f84\uff0c\u9700\u8981\u5177\u4f53\u4ee3\u7801\u793a\u4f8b<\/strong><\/p>\n<p>\u5728\u5b66\u4e60Linux\u5185\u6838\u5f00\u53d1\u6216\u8005\u8fdb\u884c\u7cfb\u7edf\u8c03\u4f18\u65f6\uff0c\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u9879\u5de5\u4f5c\u3002\u4e86\u89e3Linux\u5185\u6838\u6e90\u4ee3\u7801\u7ed3\u6784\u3001\u51fd\u6570\u5b9a\u4e49\u53ca\u5b9e\u73b0\u7ec6\u8282\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u6df1\u5165\u5730\u7406\u89e3\u64cd\u4f5c\u7cfb\u7edf\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u8fdb\u800c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u89e3\u51b3\u95ee\u9898\u7684\u80fd\u529b\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u5728\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u65f6\uff0c\u6709\u54ea\u4e9b\u6700\u4f73\u9014\u5f84\u5462\uff1f\u4e0b\u9762\u5c06\u7ed3\u5408\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u6765\u4ecb\u7ecd\u4e00\u4e9b\u65b9\u6cd5\u3002<\/p>\n<p><strong>1. \u5728\u7ebf\u6d4f\u89c8Linux\u5185\u6838\u6e90\u4ee3\u7801<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u662f\u901a\u8fc7\u5728\u7ebf\u6d4f\u89c8\u5668\u6765\u67e5\u770bLinux\u5185\u6838\u6e90\u4ee3\u7801\uff0c\u8fd9\u6837\u80fd\u591f\u5feb\u901f\u5730\u67e5\u627e\u5230\u6240\u9700\u7684\u4ee3\u7801\u3002\u53ef\u4ee5\u4f7f\u7528\u7f51\u7ad9\u6bd4\u5982[lxr..no](http:\/\/lxr.linux.no\/)\u7b49\u5728\u7ebf\u9605\u8bfb\u5668\u6765\u6d4f\u89c8Linux\u5185\u6838\u6e90\u4ee3\u7801\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5047\u8bbe\u6211\u4eec\u8981\u67e5\u627esys_exit\u51fd\u6570\u7684\u5b9e\u73b0\u4ee3\u7801\uff0c\u53ef\u4ee5\u5728\u5728\u7ebf\u6d4f\u89c8\u5668\u4e2d\u641c\u7d22\u8be5\u51fd\u6570\u7684\u5173\u952e\u5b57\uff0c\u627e\u5230\u5bf9\u5e94\u7684\u4ee3\u7801\u6587\u4ef6\u3002\u5177\u4f53\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre>\/*\n * Free all assets associated with a process,\n * and notify \"group_stop\" of its death.\n *\/\nvoid do_exit(long code)\n{\n    struct task_struct *tsk = current;\n    struct mm_struct *mm = tsk-&amp;gt;mm;\n    struct exit_call_struct *p;\n\n    WARN_ON(atomic_read(&amp;amp;tsk-&amp;gt;fs_excl));\n    tracehook_finish_exit(tsk);\n\n    if (vtime_accounting_enabled() &amp;amp;&amp;amp; !do_task_stat(tsk))\n        vtime_exit(tsk);\n    cgroup_exit(tsk);\n\n    if (!tsk-&amp;gt;io_context)\n        tsk-&amp;gt;io_context = &amp;amp;noop_ioc;\n\n    \/* sync mm's RSS info back to its owner when required *\/\n    if (mm)\n        sync_mm_rss(mm);\n    \/*\n     * Make sure we are holding no locks:\n     *\/\n    DEBUG_LOCKS_WARN_ON(!rwsem_is_locked(&amp;amp;current-&amp;gt;mm-&amp;gt;mmap_sem) &amp;amp;&amp;amp;\n                        !rwsem_is_locked(&amp;amp;current-&amp;gt;mm-&amp;gt;page_table_lock));\n\n    BUG_ON(tsk-&amp;gt;journal_info != NULL);\n    do_memory_accounting(tsk);\n    security_ops-&amp;gt;task_free(tsk);\n\n    thread_group_exit(code);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5bf9\u4e8e\u521d\u5b66\u8005\u6216\u8005\u53ea\u662f\u67e5\u9605\u5c11\u91cf\u4ee3\u7801\u7684\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u4f7f\u7528\u5728\u7ebf\u6d4f\u89c8\u5668\u53ef\u4ee5\u7b80\u5355\u5feb\u6377\u5730\u83b7\u53d6\u6240\u9700\u7684\u5185\u6838\u6e90\u4ee3\u7801\u4fe1\u606f\u3002<\/p>\n<p><strong>2. \u4f7f\u7528git\u5de5\u5177\u67e5\u770bLinux\u5185\u6838\u6e90\u4ee3\u7801<\/strong><\/p>\n<p>\u53e6\u4e00\u4e2a\u65b9\u6cd5\u662f\u901a\u8fc7git\u5de5\u5177\u76f4\u63a5\u514b\u9686Linux\u5185\u6838\u6e90\u4ee3\u7801\u4ed3\u5e93\uff0c\u8fd9\u6837\u53ef\u4ee5\u5728\u672c\u5730\u8fdb\u884c\u67e5\u9605\u548c\u4fee\u6539\u3002\u9996\u5148\u9700\u8981\u5b89\u88c5git\u5de5\u5177\uff0c\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u514b\u9686Linux\u4ed3\u5e93\uff1a<\/p>\n<pre>git clone https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/torvalds\/linux.git<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u514b\u9686\u5b8c\u6210\u540e\uff0c\u5728\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u4e2d\u5c31\u80fd\u591f\u627e\u5230\u6240\u6709\u7684Linux\u5185\u6838\u6e90\u4ee3\u7801\u3002\u7136\u540e\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6216\u8005\u4ee3\u7801\u9605\u8bfb\u5de5\u5177\u6765\u67e5\u770b\u548c\u4fee\u6539\u4ee3\u7801\u3002\u5177\u4f53\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre>\/*\n * Main exit path for a task. Do some of the accounting and invoke\n * the relevant process signal handler.\n *\/\nvoid do_exit(long code)\n{\n    struct task_struct *tsk = current;\n    \n    \/* Free all assets associated with the process *\/\n    exit_task_struct(tsk);\n    \n    \/* Notify group_stop of the process's death *\/\n    exit_notify(code);\n    \n    \/* Call the scheduler to switch to a new process *\/\n    schedule();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7git\u5de5\u5177\u67e5\u770bLinux\u5185\u6838\u6e90\u4ee3\u7801\u7684\u65b9\u5f0f\u66f4\u9002\u5408\u5bf9\u5185\u6838\u5f00\u53d1\u6709\u9700\u6c42\u7684\u5f00\u53d1\u8005\uff0c\u53ef\u4ee5\u5728\u672c\u5730\u8fdb\u884c\u4ee3\u7801\u7684\u67e5\u770b\u3001\u8c03\u8bd5\u548c\u4fee\u6539\u3002<\/p>\n<p><strong>\u7ed3\u8bed<\/strong><\/p>\n<p>\u901a\u8fc7\u5728\u7ebf\u6d4f\u89c8\u5668\u548cgit\u5de5\u5177\u67e5\u770bLinux\u5185\u6838\u6e90\u4ee3\u7801\u662f\u5b66\u4e60\u5185\u6838\u5f00\u53d1\u548c\u7cfb\u7edf\u8c03\u4f18\u7684\u91cd\u8981\u8def\u5f84\u4e4b\u4e00\u3002\u5728\u67e5\u627e\u5185\u6838\u6e90\u4ee3\u7801\u65f6\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u5f0f\uff0c\u5e76\u901a\u8fc7\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u6765\u66f4\u597d\u5730\u7406\u89e3\u548c\u8fd0\u7528\u5185\u6838\u6e90\u4ee3\u7801\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u5927\u5bb6\u5728\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u65f6\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u7684\u6700\u4f73\u9014\u5f84\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6807\u9898\uff1a\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u7684\u6700\u4f73\u9014\u5f84\uff0c\u9700\u8981\u5177\u4f53\u4ee3\u7801\u793a\u4f8b \u5728\u5b66\u4e60Linux\u5185\u6838\u5f00\u53d1\u6216\u8005\u8fdb\u884c\u7cfb\u7edf\u8c03\u4f18\u65f6\uff0c\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u9879\u5de5\u4f5c\u3002\u4e86\u89e3Linux\u5185\u6838\u6e90\u4ee3\u7801\u7ed3\u6784\u3001\u51fd\u6570\u5b9a\u4e49\u53ca\u5b9e\u73b0\u7ec6\u8282\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u6df1\u5165\u5730\u7406\u89e3\u64cd\u4f5c\u7cfb\u7edf\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u8fdb\u800c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u89e3\u51b3\u95ee\u9898\u7684\u80fd\u529b\u3002 \u90a3\u4e48\uff0c\u5728\u67e5\u627eLinux\u5185\u6838\u6e90\u4ee3\u7801\u65f6\uff0c\u6709\u54ea\u4e9b\u6700\u4f73\u9014\u5f84\u5462\uff1f\u4e0b\u9762\u5c06\u7ed3\u5408\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u6765\u4ecb\u7ecd\u4e00\u4e9b\u65b9\u6cd5\u3002 1. \u5728\u7ebf\u6d4f\u89c8Linux\u5185\u6838\u6e90\u4ee3\u7801 \u6700\u7b80\u5355\u7684\u65b9\u5f0f\u662f\u901a\u8fc7\u5728\u7ebf\u6d4f\u89c8\u5668\u6765\u67e5\u770bLinux\u5185\u6838\u6e90\u4ee3\u7801\uff0c\u8fd9\u6837\u80fd\u591f\u5feb\u901f\u5730\u67e5\u627e\u5230\u6240\u9700\u7684\u4ee3\u7801\u3002\u53ef\u4ee5\u4f7f\u7528\u7f51\u7ad9\u6bd4\u5982[lxr..no](http:\/\/lxr.linux.no\/)\u7b49\u5728\u7ebf\u9605\u8bfb\u5668\u6765\u6d4f\u89c8Linux\u5185\u6838\u6e90\u4ee3\u7801\u3002 \u4f8b\u5982\uff0c\u5047\u8bbe\u6211\u4eec\u8981\u67e5\u627esys_exit\u51fd\u6570\u7684\u5b9e\u73b0\u4ee3\u7801\uff0c\u53ef\u4ee5\u5728\u5728\u7ebf\u6d4f\u89c8\u5668\u4e2d\u641c\u7d22\u8be5\u51fd\u6570\u7684\u5173\u952e\u5b57\uff0c\u627e\u5230\u5bf9\u5e94\u7684\u4ee3\u7801\u6587\u4ef6\u3002\u5177\u4f53\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a \/* * Free all assets associated with a process, * and notify &#8220;group_stop&#8221; of its death. *\/ void do_exit(long code) { struct task_struct *tsk = current; struct mm_struct *mm = tsk-&amp;gt;mm; struct exit_call_struct *p; WARN_ON(atomic_read(&amp;amp;tsk-&amp;gt;fs_excl)); tracehook_finish_exit(tsk); if (vtime_accounting_enabled() &amp;amp;&amp;amp; !do_task_stat(tsk)) vtime_exit(tsk); cgroup_exit(tsk); if (!tsk-&amp;gt;io_context) tsk-&amp;gt;io_context = &amp;amp;noop_ioc; \/* [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63171","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=63171"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63171\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}