{"id":161,"date":"2025-10-18T17:44:33","date_gmt":"2025-10-18T09:44:33","guid":{"rendered":"http:\/\/47.99.178.170\/?p=161"},"modified":"2025-10-23T21:54:11","modified_gmt":"2025-10-23T13:54:11","slug":"%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f%e8%bf%9b%e7%a8%8b%e7%ae%a1%e7%90%86%e8%b0%83%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/www.garfield-blog.top\/?p=161","title":{"rendered":"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u3010Linux\u3011\u8fdb\u7a0b\u8c03\u5ea6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u8fdb\u7a0b\u7684\u5b9a\u4e49<\/h2>\n\n\n\n<p><code>PCB<\/code> \u662f\u8fdb\u7a0b\u5b9e\u4f53\u7684\u4e00\u90e8\u5206\uff0c\u662f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u6700\u91cd\u8981\u7684\u8bb0\u5f55\u578b\u6570\u636e\u7ed3\u6784\u3002\u4f5c\u7528\u662f\u4f7f\u4e00\u4e2a\u5728 \u591a\u9053\u7a0b\u5e8f\u73af\u5883\u4e0b\u4e0d\u80fd\u72ec\u7acb\u8fd0\u884c\u7684\u7a0b\u5e8f\uff0c\u6210\u4e3a\u4e00\u4e2a\u80fd\u72ec\u7acb\u8fd0\u884c\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u6210\u4e3a\u80fd\u4e0e\u5176\u5b83\u8fdb\u7a0b \u5e76\u53d1\u6267\u884c\u7684\u8fdb\u7a0b\u3002<code>OS<\/code>\u662f\u6839\u636e<code>PCB<\/code>\u5bf9\u5e76\u53d1\u6267\u884c\u7684\u8fdb\u7a0b\u8fdb\u884c\u63a7\u5236\u548c\u7ba1\u7406\u7684<\/p>\n\n\n\n<p><code>Linux<\/code>\u7684\u8fdb\u7a0b\u63a7\u5236\u5757\u4e3a\u4e00\u4e2a\u7531\u7ed3\u6784<code>task_struct<\/code>\u6240\u5b9a\u4e49\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5176\u4e2d\u5305\u62ec\u7ba1\u7406\u8fdb\u7a0b\u6240\u9700\u7684\u5404\u79cd\u4fe1\u606f<\/p>\n\n\n\n<p>\u5728<code>0.11<\/code>\u7248\u672c\u7684<code>Linux Kernel<\/code>\u4e2d<code>task_struct<\/code>\u7684\u5b9a\u4e49\u5982\u4e0b\uff1b\u5728\u540e\u7eed\u7248\u672c\u7684<code>Linux<\/code>\u4e2d\u8fd9\u4e2a\u7ed3\u6784\u4f53\u4e0d\u65ad\u53d8\u5927\uff0c\u5728\u6700\u65b0\u7248\u7684<code>Linux<\/code>\u4e2d<code>task_struct<\/code>\u5b9a\u4e49\u5df2\u8fbe\u5230\u6570\u767e\u884c\u7684\u957f\u5ea6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct task_struct {<br>\/* these are hardcoded - don't touch *\/<br> &nbsp; &nbsp;long state; &nbsp; &nbsp;\/* -1 unrunnable, 0 runnable, &gt;0 stopped *\/<br> &nbsp; &nbsp;long counter;<br> &nbsp; &nbsp;long priority;<br> &nbsp; &nbsp;long signal;<br> &nbsp; &nbsp;struct sigaction sigaction&#91;32];<br> &nbsp; &nbsp;long blocked; &nbsp; &nbsp;\/* bitmap of masked signals *\/<br>\/* various fields *\/<br> &nbsp; &nbsp;int exit_code;<br> &nbsp; &nbsp;unsigned long start_code,end_code,end_data,brk,start_stack;<br> &nbsp; &nbsp;long pid,father,pgrp,session,leader;<br> &nbsp; &nbsp;unsigned short uid,euid,suid;<br> &nbsp; &nbsp;unsigned short gid,egid,sgid;<br> &nbsp; &nbsp;long alarm;<br> &nbsp; &nbsp;long utime,stime,cutime,cstime,start_time;<br> &nbsp; &nbsp;unsigned short used_math;<br>\/* file system info *\/<br> &nbsp; &nbsp;int tty; &nbsp; &nbsp; &nbsp; &nbsp;\/* -1 if no tty, so it must be signed *\/<br> &nbsp; &nbsp;unsigned short umask;<br> &nbsp; &nbsp;struct m_inode * pwd;<br> &nbsp; &nbsp;struct m_inode * root;<br> &nbsp; &nbsp;struct m_inode * executable;<br> &nbsp; &nbsp;unsigned long close_on_exec;<br> &nbsp; &nbsp;struct file * filp&#91;NR_OPEN];<br>\/* ldt for this task 0 - zero 1 - cs 2 - ds&amp;ss *\/<br> &nbsp; &nbsp;struct desc_struct ldt&#91;3];<br>\/* tss for this task *\/<br> &nbsp; &nbsp;struct tss_struct tss;<br>};<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u8fdb\u7a0b\u7684\u72b6\u6001<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u4e09\u6001\u6a21\u578b<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8fd0\u884c<code>running<\/code>\u6001\uff1a\u8fdb\u7a0b\u5360\u6709\u5904\u7406\u5668\u6b63\u5728\u8fd0\u884c\u7684\u72b6\u6001\u3002\u8fdb\u7a0b\u5df2\u83b7\u5f97<code>CPU<\/code>\uff0c\u5176\u7a0b\u5e8f\u6b63\u5728\u6267\u884c\u3002\u5728\u5355\u5904\u7406\u673a\u7cfb\u7edf\u4e2d\uff0c\u53ea\u6709\u4e00\u4e2a\u8fdb\u7a0b\u5904\u4e8e\u6267\u884c\u72b6\u6001\uff1b \u5728\u591a\u5904\u7406\u673a\u7cfb\u7edf\u4e2d\uff0c\u5219\u6709\u591a\u4e2a\u8fdb\u7a0b\u5904\u4e8e\u6267\u884c\u72b6\u6001\u3002<\/li>\n\n\n\n<li>\u5c31\u7eea<code>ready<\/code>\u6001\uff1a\u8fdb\u7a0b\u5177\u5907\u8fd0\u884c\u6761\u4ef6\uff0c\u7b49\u5f85\u7cfb\u7edf\u5206\u914d\u5904\u7406\u5668\u4ee5\u4fbf\u8fd0\u884c\u7684\u72b6\u6001\u3002\u5f53\u8fdb\u7a0b\u5df2\u5206\u914d\u5230\u9664<code>CPU<\/code>\u4ee5\u5916\u7684\u6240\u6709\u5fc5\u8981\u8d44\u6e90\u540e\uff0c\u53ea\u8981\u518d\u83b7\u5f97<code>CPU<\/code>\uff0c\u4fbf\u53ef\u7acb\u5373\u6267\u884c\uff0c\u8fdb\u7a0b\u8fd9\u65f6\u7684\u72b6\u6001\u79f0\u4e3a\u5c31\u7eea\u72b6\u6001\u3002\u5728\u4e00\u4e2a\u7cfb\u7edf\u4e2d\u5904\u4e8e\u5c31\u7eea\u72b6\u6001\u7684\u8fdb\u7a0b\u53ef\u80fd\u6709\u591a\u4e2a\uff0c\u901a\u5e38\u5c06\u5b83\u4eec\u6392\u6210\u4e00\u4e2a\u961f\u5217\uff0c\u79f0\u4e3a\u5c31\u7eea\u961f\u5217\u3002<\/li>\n\n\n\n<li>\u7b49\u5f85<code>wait<\/code>\u6001\uff1a\u53c8\u79f0\u963b\u585e\u6001\u6216\u7761\u7720\u6001\uff0c\u6307\u8fdb\u7a0b\u4e0d\u5177\u5907\u8fd0\u884c\u6761\u4ef6\uff0c\u6b63\u5728\u7b49\u5f85\u67d0\u4e2a\u65f6\u95f4\u5b8c\u6210\u7684\u72b6\u6001\u3002\u4e5f\u79f0\u4e3a\u7b49\u5f85\u6216\u7761\u7720\u72b6\u6001\uff0c\u4e00\u4e2a\u8fdb\u7a0b\u6b63\u5728\u7b49\u5f85\u67d0\u4e00\u4e8b\u4ef6\u53d1\u751f\uff08\u4f8b\u5982\u8bf7\u6c42<code>I\/O<\/code>\u800c\u7b49\u5f85<code>I\/O<\/code>\u5b8c\u6210\u7b49\uff09\u800c\u6682\u65f6\u505c\u6b62\u8fd0\u884c\uff0c\u8fd9\u65f6\u5373\u4f7f\u628a\u5904\u7406\u673a\u5206\u914d\u7ed9\u8fdb\u7a0b\u4e5f\u65e0\u6cd5\u8fd0\u884c\uff0c\u6545\u79f0\u8be5\u8fdb\u7a0b\u5904\u4e8e\u963b\u585e\u72b6\u6001\u3002<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/10\/01_\u8fdb\u7a0b\u7684\u4e09\u6001\u6a21\u578b.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"251\" data-original=\"https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/10\/01_\u8fdb\u7a0b\u7684\u4e09\u6001\u6a21\u578b.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-268\"\/><\/div><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">2.1.1 \u4e09\u6001\u6a21\u578b\u8fdb\u7a0b\u72b6\u6001\u5207\u6362<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8fd0\u884c\u6001\u2192\u963b\u585e\u6001\uff1a\u7b49\u5f85\u4f7f\u7528\u8d44\u6e90\uff1b\n<ul class=\"wp-block-list\">\n<li>\u5982\u7b49\u5f85\u5916\u8bbe\u4f20\u8f93\uff1b\u7b49\u5f85\u4eba\u5de5\u5e72\u9884\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u963b\u585e\u6001\u2192\u5c31\u7eea\u6001\uff1a\u8d44\u6e90\u5f97\u5230\u6ee1\u8db3\uff1b\n<ul class=\"wp-block-list\">\n<li>\u5982\u5916\u8bbe\u4f20\u8f93\u7ed3\u675f\uff1b\u4eba\u5de5\u5e72\u9884\u5b8c\u6210\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u8fd0\u884c\u6001\u2192\u5c31\u7eea\u6001\uff1a\u8fd0\u884c\u65f6\u95f4\u7247\u5230\uff1b<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 \u8fdb\u7a0b\u4e94\u6001\u6a21\u578b<\/h3>\n\n\n\n<p>\u4e94\u6001\u6a21\u578b\u5728\u4e09\u6001\u6a21\u578b\u7684\u57fa\u7840\u4e0a\u589e\u52a0\u4e86\u65b0\u5efa\u6001<code>new<\/code>\u548c\u7ec8\u6b62\u6001<code>exit<\/code>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u65b0\u5efa\u6001\uff1a\u5bf9\u5e94\u4e8e\u8fdb\u7a0b\u88ab\u521b\u5efa\u65f6\u7684\u72b6\u6001\uff0c\u5c1a\u672a\u8fdb\u5165\u5c31\u7eea\u961f\u5217\u3002\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\u9700\u8981\u901a\u8fc7\u4e24\u4e2a\u6b65\u9aa4\uff1a\n<ul class=\"wp-block-list\">\n<li>\n<ol class=\"wp-block-list\">\n<li>\u4e3a\u65b0\u8fdb\u7a0b\u5206\u914d\u6240\u9700\u8981\u7684\u8d44\u6e90\u548c\u5efa\u7acb\u5fc5\u8981\u7684\u7ba1\u7406\u4fe1\u606f\u3002<\/li>\n\n\n\n<li>\u8bbe\u7f6e\u8be5\u8fdb\u7a0b\u4e3a\u5c31\u7eea\u6001\uff0c\u5e76\u7b49\u5f85\u88ab\u8c03\u5ea6\u6267\u884c\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u7ec8\u6b62\u6001\uff1a\u6307\u8fdb\u7a0b\u5b8c\u6210\u4efb\u52a1\u5230\u8fbe\u6b63\u5e38\u7ed3\u675f\u70b9\uff0c\u6216\u51fa\u73b0\u65e0\u6cd5\u514b\u670d\u7684\u9519\u8bef\u800c\u5f02\u5e38\u7ec8\u6b62\uff0c\u6216\u88ab\u64cd\u4f5c\u7cfb\u7edf\u53ca\u6709\u7ec8\u6b62\u6743\u7684\u8fdb\u7a0b\u6240\u7ec8\u6b62\u65f6\u6240\u5904\u7684\u72b6\u6001\u3002\u5904\u4e8e\u7ec8\u6b62\u6001\u7684\u8fdb\u7a0b\u4e0d\u518d\u88ab\u8c03\u5ea6\u6267\u884c\uff0c\u4e0b\u4e00\u6b65\u5c06\u88ab\u7cfb\u7edf\u64a4\u9500\uff0c\u6700\u7ec8\u4ece\u7cfb\u7edf\u4e2d\u6d88\u5931\u3002\u7ec8\u6b62\u4e00\u4e2a\u8fdb\u7a0b\u9700\u8981\u4e24\u4e2a\u6b65\u9aa4\uff1a\n<ul class=\"wp-block-list\">\n<li><ol start=\"\"><li>\u5148\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u6216\u76f8\u5173\u7684\u8fdb\u7a0b\u8fdb\u884c\u5584\u540e\u5904\u7406\uff08\u5982\u62bd\u53d6\u4fe1\u606f\uff09<\/li><li>\u7136\u540e\u56de\u6536\u5360\u7528\u7684\u8d44\u6e90\u5e76\u88ab\u7cfb\u7edf\u5220\u9664<\/li><\/ol><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/10\/02_\u8fdb\u7a0b\u7684\u4e94\u6001\u6a21\u578b.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"738\" height=\"296\" data-original=\"https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/10\/02_\u8fdb\u7a0b\u7684\u4e94\u6001\u6a21\u578b.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-269\"\/><\/div><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">2.2.1 \u4e09\u6001\u6a21\u578b\u8fdb\u7a0b\u72b6\u6001\u5207\u6362<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>NULL\u2192\u65b0\u5efa\u6001\uff1a\u6267\u884c\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u521b\u5efa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u3002<\/li>\n\n\n\n<li>\u65b0\u5efa\u6001\u2192\u5c31\u7eea\u6001\uff1a\u5f53\u64cd\u4f5c\u7cfb\u7edf\u5b8c\u6210\u4e86\u8fdb\u7a0b\u521b\u5efa\u7684\u5fc5\u8981\u64cd\u4f5c\uff0c\u5e76\u4e14\u5f53\u524d\u7cfb\u7edf\u7684\u6027\u80fd\u548c\u865a\u62df\u5185\u5b58\u7684\u5bb9\u91cf\u5747\u5141\u8bb8\u3002<\/li>\n\n\n\n<li>\u8fd0\u884c\u6001\u2192\u7ec8\u6b62\u6001\uff1a\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u5230\u8fbe\u4e86\u81ea\u7136\u7ed3\u675f\u70b9\uff0c\u6216\u662f\u51fa\u73b0\u4e86\u65e0\u6cd5\u514b\u670d\u7684\u9519\u8bef\uff0c\u6216\u662f\u88ab\u64cd\u4f5c\u7cfb\u7edf\u6240\u7ec8\u7ed3\uff0c\u6216\u662f\u88ab\u5176\u4ed6\u6709\u7ec8\u6b62\u6743\u7684\u8fdb\u7a0b\u6240\u7ec8\u7ed3\u3002<\/li>\n\n\n\n<li>\u8fd0\u884c\u6001\u2192\u5c31\u7eea\u6001\uff1a\u8fd0\u884c\u65f6\u95f4\u7247\u5230\uff1b\u51fa\u73b0\u6709\u66f4\u9ad8\u4f18\u5148\u6743\u8fdb\u7a0b\u3002<\/li>\n\n\n\n<li>\u8fd0\u884c\u6001\u2192\u963b\u585e\u6001\uff1a\u7b49\u5f85\u4f7f\u7528\u8d44\u6e90\uff1b\u5982\u7b49\u5f85\u5916\u8bbe\u4f20\u8f93\uff1b\u7b49\u5f85\u4eba\u5de5\u5e72\u9884\u3002<\/li>\n\n\n\n<li>\u5c31\u7eea\u6001\u2192\u7ec8\u6b62\u6001\uff1a\u672a\u5728\u72b6\u6001\u8f6c\u6362\u56fe\u4e2d\u663e\u793a\uff0c\u4f46\u67d0\u4e9b\u64cd\u4f5c\u7cfb\u7edf\u5141\u8bb8\u7236\u8fdb\u7a0b\u7ec8\u7ed3\u5b50\u8fdb\u7a0b\u3002<\/li>\n\n\n\n<li>\u963b\u585e\u6001\u2192\u7ec8\u6b62\u6001\uff1a\u672a\u5728\u72b6\u6001\u8f6c\u6362\u56fe\u4e2d\u663e\u793a\uff0c\u4f46\u67d0\u4e9b\u64cd\u4f5c\u7cfb\u7edf\u5141\u8bb8\u7236\u8fdb\u7a0b\u7ec8\u7ed3\u5b50\u8fdb\u7a0b\u3002<\/li>\n\n\n\n<li>\u7ec8\u6b62\u6001\u2192NULL\uff1a\u5b8c\u6210\u5584\u540e\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 \u8fdb\u7a0b\u7684\u4e03\u6001\u6a21\u578b<\/h3>\n\n\n\n<p>\u4e03\u6001\u6a21\u578b\u5728\u4e94\u6001\u6a21\u578b\u7684\u57fa\u7840\u4e0a\u589e\u52a0\u4e86\u6302\u8d77\u5c31\u7eea\u6001<code>ready suspend<\/code>\u548c\u6302\u8d77\u7b49\u5f85\u6001<code>blocked suspend<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/10\/03_\u8fdb\u7a0b\u7684\u4e03\u6001\u6a21\u578b.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1093\" height=\"520\" data-original=\"https:\/\/www.garfield-blog.top\/wp-content\/uploads\/2025\/10\/03_\u8fdb\u7a0b\u7684\u4e03\u6001\u6a21\u578b.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-270\"  sizes=\"auto, (max-width: 1093px) 100vw, 1093px\" \/><\/div><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6302\u8d77\u5c31\u7eea\u6001\uff1a\u8fdb\u7a0b\u5177\u5907\u8fd0\u884c\u6761\u4ef6\uff0c\u4f46\u76ee\u524d\u5728\u5916\u5b58\u4e2d\uff0c\u53ea\u6709\u5b83\u88ab\u5bf9\u6362\u5230\u5185\u5b58\u624d\u80fd\u88ab\u8c03\u5ea6\u6267\u884c\u3002<\/li>\n\n\n\n<li>\u6302\u8d77\u7b49\u5f85\u6001\uff1a\u8868\u660e\u8fdb\u7a0b\u6b63\u5728\u7b49\u5f85\u67d0\u4e00\u4e2a\u4e8b\u4ef6\u53d1\u751f\u4e14\u5728\u5916\u5b58\u4e2d\u3002<img decoding=\"async\" src=\"\" alt=\"03_\u8fdb\u7a0b\u7684\u4e03\u6001\u6a21\u578b\"><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2.3.1 \u8fdb\u7a0b\u4e03\u6001\u6a21\u578b\u8f6c\u5316<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b49\u5f85\u6001\u2192\u6302\u8d77\u7b49\u5f85\u6001\uff1a\u64cd\u4f5c\u7cfb\u7edf\u6839\u636e\u5f53\u524d\u8d44\u6e90\u72b6\u51b5\u548c\u6027\u80fd\u8981\u6c42\uff0c\u53ef\u4ee5\u51b3\u5b9a\u628a\u7b49\u5f85\u6001\u8fdb\u7a0b\u5bf9\u6362\u51fa\u53bb\u6210\u4e3a\u6302\u8d77\u7b49\u5f85\u6001\u3002<\/li>\n\n\n\n<li>\u6302\u8d77\u7b49\u5f85\u6001\u2192\u6302\u8d77\u5c31\u7eea\u6001\uff1a\u5f15\u8d77\u8fdb\u7a0b\u7b49\u5f85\u7684\u4e8b\u4ef6\u53d1\u751f\u4e4b\u540e\uff0c\u76f8\u5e94\u7684\u6302\u8d77\u7b49\u5f85\u6001\u8fdb\u7a0b\u5c06\u8f6c\u6362\u4e3a\u6302\u8d77\u5c31\u7eea\u6001\u6302\u8d77\u5c31\u7eea\u6001\u2192\u5c31\u7eea\u6001\uff1a\u5f53\u5185\u5b58\u4e2d\u6ca1\u6709\u5c31\u7eea\u6001\u8fdb\u7a0b\uff0c\u6216\u8005\u6302\u8d77\u5c31\u7eea\u6001\u8fdb\u7a0b\u5177\u6709\u6bd4\u5c31\u7eea\u6001\u8fdb\u7a0b\u66f4\u9ad8\u7684\u4f18\u5148\u7ea7\uff0c\u7cfb\u7edf\u5c06\u628a\u6302\u8d77\u5c31\u7eea\u6001\u8fdb\u7a0b\u8f6c\u6362\u6210\u5c31\u7eea\u6001\u3002<\/li>\n\n\n\n<li>\u5c31\u7eea\u6001\u2192\u6302\u8d77\u5c31\u7eea\u6001\uff1a\u64cd\u4f5c\u7cfb\u7edf\u6839\u636e\u5f53\u524d\u8d44\u6e90\u72b6\u51b5\u548c\u6027\u80fd\u8981\u6c42\uff0c\u4e5f\u53ef\u4ee5\u51b3\u5b9a\u628a\u5c31\u7eea\u6001\u8fdb\u7a0b\u5bf9\u6362\u51fa\u53bb\u6210\u4e3a\u6302\u8d77\u5c31\u7eea\u6001\u3002<\/li>\n\n\n\n<li>\u6302\u8d77\u7b49\u5f85\u6001\u2192\u7b49\u5f85\u6001\uff1a\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u7b49\u5f85\u4e00\u4e2a\u4e8b\u4ef6\u65f6\uff0c\u539f\u5219\u4e0a\u4e0d\u9700\u8981\u628a\u5b83\u8c03\u5165\u5185\u5b58\u3002\u4f46\u662f\u5728\u4e0b\u9762\u4e00\u79cd\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e00\u72b6\u6001\u53d8\u5316\u662f\u53ef\u80fd\u7684\u3002\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u9000\u51fa\u540e\uff0c\u4e3b\u5b58\u5df2\u7ecf\u6709\u4e86\u4e00\u5927\u5757\u81ea\u7531\u7a7a\u95f4,\u800c\u67d0\u4e2a\u6302\u8d77\u7b49\u5f85\u6001\u8fdb\u7a0b\u5177\u6709\u8f83\u9ad8\u7684\u4f18\u5148\u7ea7\u5e76\u4e14\u64cd\u4f5c\u7cfb\u7edf\u5df2\u7ecf\u5f97\u77e5\u5bfc\u81f4\u5b83\u963b\u585e\u7684\u4e8b\u4ef6\u5373\u5c06\u7ed3\u675f\uff0c\u6b64\u65f6\u4fbf\u53d1\u751f\u4e86\u8fd9\u4e00\u72b6\u6001\u53d8\u5316\u3002<\/li>\n\n\n\n<li>\u8fd0\u884c\u6001\u2192\u6302\u8d77\u5c31\u7eea\u6001\uff1a\u5f53\u4e00\u4e2a\u5177\u6709\u8f83\u9ad8\u4f18\u5148\u7ea7\u7684\u6302\u8d77\u7b49\u5f85\u6001\u8fdb\u7a0b\u7684\u7b49\u5f85\u4e8b\u4ef6\u7ed3\u675f\u540e\uff0c\u5b83\u9700\u8981\u62a2\u5360 <code>CPU<\/code>\uff0c\u800c\u6b64\u65f6\u4e3b\u5b58\u7a7a\u95f4\u4e0d\u591f\uff0c\u4ece\u800c\u53ef\u80fd\u5bfc\u81f4\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u8f6c\u5316\u4e3a\u6302\u8d77\u5c31\u7eea\u6001\u3002\u53e6\u5916\u5904\u4e8e\u8fd0\u884c\u6001\u7684\u8fdb\u7a0b\u4e5f\u53ef\u4ee5\u81ea\u5df1\u6302\u8d77\u81ea\u5df1\u3002<\/li>\n\n\n\n<li>\u65b0\u5efa\u6001\u2192\u6302\u8d77\u5c31\u7eea\u6001\uff1a\u8003\u8651\u5230\u7cfb\u7edf\u5f53\u524d\u8d44\u6e90\u72b6\u51b5\u548c\u6027\u80fd\u8981\u6c42\uff0c\u53ef\u4ee5\u51b3\u5b9a\u65b0\u5efa\u7684\u8fdb\u7a0b\u5c06\u88ab\u5bf9\u6362\u51fa\u53bb\u6210\u4e3a\u6302\u8d77\u5c31\u7eea\u6001\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.4 \u6302\u8d77\u8fdb\u7a0b\u7684\u7279\u70b9<\/h3>\n\n\n\n<p><strong>\u6302\u8d77\u8fdb\u7a0b\u5177\u6709\u5982\u4e0b\u7279\u5f81\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6302\u8d77\u8fdb\u7a0b\u7b49\u540c\u4e8e\u4e0d\u5728\u5185\u5b58\u4e2d\u7684\u8fdb\u7a0b\uff0c\u56e0\u6b64\u6302\u8d77\u8fdb\u7a0b\u5c06\u4e0d\u53c2\u4e0e\u4f4e\u7ea7\u8c03\u5ea6\u76f4\u5230\u5b83\u4eec\u88ab\u8c03\u6362\u8fdb\u5185\u5b58\u3002<\/li>\n\n\n\n<li>\u8be5\u8fdb\u7a0b\u4e0d\u80fd\u7acb\u5373\u88ab\u6267\u884c<\/li>\n\n\n\n<li>\u6302\u8d77\u8fdb\u7a0b\u53ef\u80fd\u4f1a\u7b49\u5f85\u4e00\u4e2a\u4e8b\u4ef6\uff0c\u4f46\u6240\u7b49\u5f85\u7684\u4e8b\u4ef6\u662f\u72ec\u7acb\u4e8e\u6302\u8d77\u6761\u4ef6\u7684\uff0c\u4e8b\u4ef6\u7ed3\u675f\u5e76\u4e0d\u80fd\u5bfc\u81f4\u8fdb\u7a0b\u5177\u5907\u6267\u884c\u6761\u4ef6\uff08\u7b49\u5f85\u4e8b\u4ef6\u7ed3\u675f\u540e\u8fdb\u7a0b\u53d8\u4e3a\u6302\u8d77\u5c31\u7eea\u6001\uff09<\/li>\n\n\n\n<li>\u8fdb\u7a0b\u8fdb\u5165\u6302\u8d77\u72b6\u6001\u662f\u7531\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u3001\u7236\u8fdb\u7a0b\u6216\u8fdb\u7a0b\u672c\u8eab\u963b\u6b62\u5b83\u7684\u8fd0\u884c\u3002<\/li>\n\n\n\n<li>\u7ed3\u675f\u8fdb\u7a0b\u6302\u8d77\u72b6\u6001\u7684\u547d\u4ee4\u53ea\u80fd\u901a\u8fc7\u64cd\u4f5c\u7cfb\u7edf\u6216\u7236\u8fdb\u7a0b\u53d1\u51fa\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u8fdb\u7a0b\u8c03\u5ea6\u7b56\u7565<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5148\u6765\u5148\u670d\u52a1 <code>First-Come, First-Served, FCFS<\/code>\uff1a\u6309\u7167\u8fdb\u7a0b\u5230\u8fbe\u7684\u987a\u5e8f\u8fdb\u884c\u8c03\u5ea6\uff0c\u5148\u5230\u8fbe\u7684\u8fdb\u7a0b\u5148\u6267\u884c\uff0c\u76f4\u5230\u6267\u884c\u5b8c\u6216\u53d1\u751f\u963b\u585e\u3002<\/li>\n\n\n\n<li>\u6700\u77ed\u4f5c\u4e1a\u4f18\u5148 <code>Shortest Job Next, SJN<\/code>\uff1a\u9009\u62e9\u4f30\u8ba1\u6267\u884c\u65f6\u95f4\u6700\u77ed\u7684\u8fdb\u7a0b\u4f18\u5148\u6267\u884c\u3002\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u957f\u4f5c\u4e1a\u7b49\u5f85\u65f6\u95f4\u589e\u52a0\uff0c\u9002\u7528\u4e8e\u4f5c\u4e1a\u7684\u6267\u884c\u65f6\u95f4\u76f8\u5bf9\u786e\u5b9a\u7684\u60c5\u51b5\u3002<\/li>\n\n\n\n<li>\u4f18\u5148\u7ea7\u8c03\u5ea6\uff1a\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u5206\u914d\u4e00\u4e2a\u4f18\u5148\u7ea7\uff0c\u5e76\u6309\u7167\u4f18\u5148\u7ea7\u9ad8\u4f4e\u8fdb\u884c\u8c03\u5ea6\u3002\u53ef\u5206\u4e3a\u9759\u6001\u4f18\u5148\u7ea7\u8c03\u5ea6\uff08\u8fdb\u7a0b\u521b\u5efa\u65f6\u5206\u914d\uff09\u548c\u52a8\u6001\u4f18\u5148\u7ea7\u8c03\u5ea6\uff08\u6839\u636e\u8fdb\u7a0b\u7684\u884c\u4e3a\u548c\u72b6\u6001\u8fdb\u884c\u52a8\u6001\u8c03\u6574\uff09\u3002<\/li>\n\n\n\n<li>\u65f6\u95f4\u7247\u8f6e\u8f6c <code>Round Robin, RR<\/code>\uff1a\u5c06\u5904\u7406\u5668\u65f6\u95f4\u5206\u4e3a\u591a\u4e2a\u65f6\u95f4\u7247\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u83b7\u5f97\u4e00\u4e2a\u65f6\u95f4\u7247\uff0c\u5f53\u65f6\u95f4\u7247\u7528\u5b8c\u540e\uff0c\u8fdb\u7a0b\u88ab\u6682\u505c\uff0c\u6267\u884c\u4e0b\u4e00\u4e2a\u8fdb\u7a0b\u3002\u9002\u7528\u4e8e\u591a\u4efb\u52a1\u73af\u5883\u3002<\/li>\n\n\n\n<li>\u591a\u7ea7\u53cd\u9988\u961f\u5217\u8c03\u5ea6\uff1a\u5c06\u8fdb\u7a0b\u5206\u7ea7\uff0c\u6bcf\u4e2a\u7ea7\u522b\u6309\u7167\u4e0d\u540c\u7684\u8c03\u5ea6\u7b56\u7565\u8fdb\u884c\u8c03\u5ea6\u3002\u8fdb\u7a0b\u9996\u5148\u8fdb\u5165\u7b2c\u4e00\u7ea7\u961f\u5217\uff0c\u6309\u7167\u65f6\u95f4\u7247\u8f6e\u8f6c\u65b9\u5f0f\u6267\u884c\uff1b\u5982\u679c\u65f6\u95f4\u7247\u7ed3\u675f\u540e\u8fdb\u7a0b\u8fd8\u6ca1\u6709\u6267\u884c\u5b8c\uff0c\u5c06\u8fdb\u7a0b\u79fb\u5230\u4e0b\u4e00\u7ea7\u961f\u5217\u3002\u9002\u7528\u4e8e\u591a\u79cd\u6267\u884c\u65f6\u95f4\u4e0d\u786e\u5b9a\u7684\u573a\u666f\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u8fdb\u7a0b\u72b6\u6001\u7ba1\u7406<\/h2>\n\n\n\n<p>\u4ee5<code>Linux 0.11<\/code>\u7248\u672c\u6e90\u7801\u4e3a\u4f8b\uff0c\u8fdb\u7a0b\u7684\u72b6\u6001\u5b58\u50a8\u5728\u7ed3\u6784\u4f53<code>task_struct-&gt;state<\/code>\u5143\u7d20\u4e2d\uff0c\u8fdb\u7a0b\u7684\u72b6\u6001\u7531\u51e0\u4e2a\u5b8f\u8fdb\u884c\u5b9a\u4e49<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct task_struct {<br>\/* these are hardcoded - don't touch *\/<br> &nbsp; &nbsp;long state; &nbsp; &nbsp;\/* -1 unrunnable, 0 runnable, &gt;0 stopped *\/<br> &nbsp;  ...<br>};<br>\u200b<br>#define TASK_RUNNING &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  0 &nbsp; &nbsp;\/\/\u8fd0\u884c\u6001<br>#define TASK_INTERRUPTIBLE &nbsp; &nbsp; &nbsp;  1 &nbsp; &nbsp;\/\/\u53ef\u4e2d\u65ad\u7761\u7720\u6001<br>#define TASK_UNINTERRUPTIBLE &nbsp;  2 &nbsp; &nbsp;\/\/\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u6001<br>#define TASK_ZOMBIE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  3 &nbsp; &nbsp;\/\/\u50f5\u5c38\u6001<br>#define TASK_STOPPED &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  4 &nbsp; &nbsp;\/\/\u505c\u6b62\u6001<\/code><\/pre>\n\n\n\n<p>\u8fdb\u7a0b\u7684\u72b6\u6001\u5207\u6362\u548c\u8c03\u5ea6\u4f1a\u5728\u89e6\u53d1\u5916\u90e8\u4e2d\u65ad\u540e\u5bf9\u8fdb\u7a0b\u8fdb\u884c\u68c0\u67e5\uff0c\u4ee5\u51b3\u5b9a\u662f\u5426\u5207\u6362\u8fdb\u7a0b\u7684\u72b6\u6001\u6216\u8005\u66f4\u6539\u5f53\u524d\u6267\u884c\u7684\u8fdb\u7a0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u8fdb\u7a0b\u7684\u5b9a\u4e49 PCB \u662f\u8fdb\u7a0b\u5b9e\u4f53\u7684\u4e00\u90e8\u5206\uff0c\u662f\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u6700\u91cd\u8981\u7684\u8bb0\u5f55\u578b\u6570\u636e\u7ed3\u6784\u3002\u4f5c\u7528\u662f\u4f7f\u4e00\u4e2a\u5728 \u591a\u9053\u7a0b\u5e8f\u73af\u5883 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[6,8],"tags":[],"class_list":["post-161","post","type-post","status-publish","format-standard","hentry","category-linux-knowledge","category-8"],"_links":{"self":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=161"}],"version-history":[{"count":3,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":271,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions\/271"}],"wp:attachment":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}