{"id":3115,"date":"2017-01-06T19:29:32","date_gmt":"2017-01-06T11:29:32","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=3115"},"modified":"2017-01-06T19:29:32","modified_gmt":"2017-01-06T11:29:32","slug":"linux%e7%9a%84%e8%bf%9b%e7%a8%8b%e7%8a%b6%e6%80%81","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/3115.html","title":{"rendered":"Linux\u7684\u8fdb\u7a0b\u72b6\u6001"},"content":{"rendered":"<p>=Start=<\/p>\n<h4>\u7f18\u7531\uff1a<\/h4>\n<p>\u8865\u5145\u4e00\u4e9b\u57fa\u7840\u7684Linux\u7cfb\u7edf\u77e5\u8bc6\u3002<\/p>\n<h4>\u6b63\u6587\uff1a<\/h4>\n<h5>\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<h6>\u8fdb\u7a0b\u72b6\u6001<\/h6>\n<p>\u4e3a\u4e86\u5f04\u660e\u767d\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u662f\u4ec0\u4e48\u610f\u601d\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u8fdb\u7a0b\u7684\u4e0d\u540c\u72b6\u6001\u3002\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u6709\u51e0\u4e2a\u72b6\u6001\uff08\u5728Linux\u5185\u6838\u91cc\uff0c\u8fdb\u7a0b\u6709\u65f6\u5019\u4e5f\u53eb\u505a\u4efb\u52a1\uff09\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u72b6\u6001\u5728 fs\/proc\/array.c \u6587\u4ef6\u91cc\u5b9a\u4e49\uff1a<\/p>\n<pre class=\"lang:c decode:true\">\/*\n* The task state array is a strange \"bitmap\" of\n* reasons to sleep. Thus \"running\" is zero, and\n* you can test for combinations of others with\n* simple bit tests.\n*\/\nstatic const char * const task_state_array[] = {\n\"R (running)\",      \/* 0 *\/\u6b63\u5728\u8fd0\u884c \u6216 \u53ef\u8fd0\u884c(\u5728\u8fd0\u884c\u961f\u5217\u6392\u961f\u4e2d)\n\"S (sleeping)\",     \/* 1 *\/\u53ef\u4e2d\u65ad\u7761\u7720(\u4f11\u7720\u4e2d\uff0c\u53d7\u963b\uff0c\u5728\u7b49\u5f85\u67d0\u4e2a\u6761\u4ef6\u7684\u5f62\u6210\u6216\u63a5\u6536\u5230\u4fe1\u53f7)\n\"D (disk sleep)\",   \/* 2 *\/\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720(\u901a\u5e38\u662f\u5728IO\u64cd\u4f5c)\uff0c\u6536\u5230\u4fe1\u53f7\u4e0d\u5524\u9192\u548c\u4e0d\u53ef\u8fd0\u884c\uff0c\u8fdb\u7a0b\u5fc5\u987b\u7b49\u5f85\u76f4\u5230\u6709\u4e2d\u65ad\u53d1\u751f\n\"T (stopped)\",      \/* 4 *\/\u6682\u505c\u72b6\u6001\uff0c\u8fdb\u7a0b\u6536\u5230 SIGSTOP, SIGSTP, SIGTIN, SIGTOU \u4fe1\u53f7\u540e\u505c\u6b62\u8fd0\u884c\n\"t (tracing stop)\", \/* 8 *\/\u8ddf\u8e2a\u72b6\u6001\uff0c\u6307\u7684\u662f\u8fdb\u7a0b\u6682\u505c\u4e0b\u6765\uff0c\u7b49\u5f85\u8ddf\u8e2a\u5b83\u7684\u8fdb\u7a0b\u5bf9\u5b83\u8fdb\u884c\u64cd\u4f5c\n\"X (dead)\",         \/* 16 *\/\u9000\u51fa\u72b6\u6001\uff0c\u8fdb\u7a0b\u5373\u5c06\u88ab\u9500\u6bc1\n\"Z (zombie)\",       \/* 32 *\/\u9000\u51fa\u72b6\u6001\uff0c\u8fdb\u7a0b\u6210\u4e3a\u50f5\u5c38\u8fdb\u7a0b\n};<\/pre>\n<p><strong>\u8fd0\u884c\u72b6\u6001\uff08running\uff09<\/strong>\u5e76\u4e0d\u610f\u5473\u7740\u8fdb\u7a0b\u4e00\u5b9a\u5728\u8fd0\u884c\u4e2d\uff0c\u5b83\u8868\u660e\u8fdb\u7a0b\u8981\u4e48\u662f\u5728\u8fd0\u884c\u4e2d\u8981\u4e48\u5728\u8fd0\u884c\u961f\u5217\u91cc\u3002<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u7761\u7720\u72b6\u6001\uff08sleeping\uff09<\/strong><\/span>\u610f\u5473\u7740\u8fdb\u7a0b\u5728\u7b49\u5f85\u4e8b\u4ef6\u5b8c\u6210\uff08\u8fd9\u91cc\u7684\u7761\u7720\u6709\u65f6\u5019\u4e5f\u53eb\u505a\u53ef\u4e2d\u65ad\u7761\u7720\uff08interruptible sleep\uff09\uff09\u3002\u78c1\u76d8\u4f11\u7720\u72b6\u6001\uff08disk sleep\uff09\u6709\u65f6\u5019\u4e5f\u53eb\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u72b6\u6001\uff08uninterruptible sleep\uff09\uff0c\u5728\u8fd9\u4e2a\u72b6\u6001\u7684\u8fdb\u7a0b\u901a\u5e38\u4f1a\u7b49\u5f85IO\u7684\u7ed3\u675f\u3002<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u6682\u505c\u72b6\u6001\uff08stopped\uff09<\/strong><\/span>\u53ef\u4ee5\u901a\u8fc7\u53d1\u9001 SIGSTOP \u4fe1\u53f7\u7ed9\u8fdb\u7a0b\u6765\u505c\u6b62\u8fdb\u7a0b\u3002\u8fd9\u4e2a\u88ab\u6682\u505c\u7684\u8fdb\u7a0b\u53ef\u4ee5\u901a\u8fc7\u53d1\u9001 SIGCONT \u4fe1\u53f7\u8ba9\u8fdb\u7a0b\u7ee7\u7eed\u8fd0\u884c\u3002<\/p>\n<p>\u8ddf\u8e2a\u72b6\u6001\uff08tracing stop\uff09\u5f53\u8fdb\u7a0b\u6b63\u5728\u88ab\u8ddf\u8e2a\u65f6\uff0c\u5b83\u5904\u4e8e TASK_TRACED \u8fd9\u4e2a\u7279\u6b8a\u7684\u72b6\u6001\u3002\u201c\u6b63\u5728\u88ab\u8ddf\u8e2a\u201d\u6307\u7684\u662f\u8fdb\u7a0b\u6682\u505c\u4e0b\u6765\uff0c\u7b49\u5f85\u8ddf\u8e2a\u5b83\u7684\u8fdb\u7a0b\u5bf9\u5b83\u8fdb\u884c\u64cd\u4f5c\u3002\u6bd4\u5982\u5728gdb\u4e2d\u5bf9\u88ab\u8ddf\u8e2a\u7684\u8fdb\u7a0b\u4e0b\u4e00\u4e2a\u65ad\u70b9\uff0c\u8fdb\u7a0b\u5728\u65ad\u70b9\u5904\u505c\u4e0b\u6765\u7684\u65f6\u5019\u5c31\u5904\u4e8e TASK_TRACED \u72b6\u6001\u3002\u800c\u5728\u5176\u4ed6\u65f6\u5019\uff0c\u88ab\u8ddf\u8e2a\u7684\u8fdb\u7a0b\u8fd8\u662f\u5904\u4e8e\u524d\u9762\u63d0\u5230\u7684\u90a3\u4e9b\u72b6\u6001\u3002<\/p>\n<p>\u6b7b\u4ea1\u72b6\u6001\uff08dead\uff09\u662f\u5185\u6838\u8fd0\u884c kernel\/exit.c \u91cc\u7684 do_exit() \u51fd\u6570\u8fd4\u56de\u7684\u72b6\u6001\u3002\u8fd9\u4e2a\u72b6\u6001\u53ea\u662f\u4e00\u4e2a\u8fd4\u56de\u72b6\u6001\uff0c\u4f60\u4e0d\u4f1a\u5728\u4efb\u52a1\u5217\u8868\u91cc\u770b\u5230\u8fd9\u4e2a\u72b6\u6001\u3002<\/p>\n<p><span style=\"color: #ff0000;\"><strong>\u50f5\u5c38\u72b6\u6001\uff08zombie\uff09<\/strong><\/span>\u662f\u4e00\u4e2a\u6bd4\u8f83\u7279\u6b8a\u7684\u72b6\u6001\u3002\u6709\u4e9b\u4eba\u8ba4\u4e3a\u8fd9\u4e2a\u72b6\u6001\u662f\u5728\u7236\u8fdb\u7a0b\u6b7b\u4ea1\u800c\u5b50\u8fdb\u7a0b\u5b58\u6d3b\u65f6\u4ea7\u751f\u7684\u3002\u5b9e\u9645\u4e0a\u4e0d\u662f\u8fd9\u6837\u7684\u3002\u7236\u8fdb\u7a0b\u53ef\u80fd\u5df2\u7ecf\u6b7b\u4e86\u4f46\u5b50\u8fdb\u7a0b\u4f9d\u7136\u5b58\u6d3b\u7740\uff0c\u90a3\u4e2a\u5b50\u8fdb\u7a0b\u7684\u7236\u8fdb\u7a0b\u5c06\u4f1a\u6210\u4e3ainit\u8fdb\u7a0b\u3002\u5f53\u8fdb\u7a0b\u9000\u51fa\u5e76\u4e14\u7236\u8fdb\u7a0b\uff08\u4f7f\u7528wait()\u7cfb\u7edf\u8c03\u7528\uff09\u6ca1\u6709\u8bfb\u53d6\u5230\u5b50\u8fdb\u7a0b\u9000\u51fa\u7684\u8fd4\u56de\u4ee3\u7801\u65f6\u5c31\u4f1a\u4ea7\u751f\u50f5\u5c38\u8fdb\u7a0b\u3002\u50f5\u5c38\u8fdb\u7a0b\u4f1a\u4ee5\u7ec8\u6b62\u72b6\u6001\u4fdd\u6301\u5728\u8fdb\u7a0b\u8868\u4e2d\uff0c\u5e76\u4e14\u4f1a\u4e00\u76f4\u5728\u7b49\u5f85\u7236\u8fdb\u7a0b\u8bfb\u53d6\u9000\u51fa\u72b6\u6001\u4ee3\u7801\u3002<\/p>\n<p>\u5404\u79cd\u72b6\u6001\u4e4b\u95f4\u7684\u8f6c\u6362\uff1a<\/p>\n<figure style=\"width: 430px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium\" src=\"https:\/\/idea.popcount.org\/2012-12-11-linux-process-states\/76a49594323247f21c9b3a69945445ee.svg\" width=\"430\" height=\"132\" \/><figcaption class=\"wp-caption-text\">Sources: linusakesson.net, ufsc.br, macdesign.net.<\/figcaption><\/figure>\n<h6>\u50f5\u5c38\u8fdb\u7a0b<\/h6>\n<h6>\u4ec0\u4e48\u662f\u50f5\u5c38\u8fdb\u7a0b\uff1f<\/h6>\n<p>\u6211\u4eec\u77e5\u9053\u9000\u51fa\u4e00\u4e2a\u8fdb\u7a0b\u7528\u7cfb\u7edf\u8c03\u7528exit\uff0c\u4f46\u662f\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u8be5\u8fdb\u7a0b\u9a6c\u4e0a\u5c31\u6d88\u5931\u4e86\uff0c\u4e8b\u5b9e\u4e0a\u5b83\u8fd8\u7559\u4e0b\u4e86\u4e00\u4e2a\u88ab\u79f0\u4e3a\u50f5\u5c38\u8fdb\u7a0b\uff08Zombie\uff09\u7684\u6570\u636e\u7ed3\u6784\u3002\u5728Linux\u8fdb\u7a0b\u76845\u79cd\u72b6\u6001\u4e2d\uff08R\u3001S\u3001D\u3001T\u3001Z\uff09\uff0c\u50f5\u5c38\u8fdb\u7a0b\uff08Z\uff09\u662f\u975e\u5e38\u7279\u6b8a\u7684\u4e00\u79cd\uff0c\u5b83\u5df2\u7ecf\u653e\u5f03\u4e86\u51e0\u4e4e\u6240\u6709\u5185\u5b58\u7a7a\u95f4\uff0c\u6ca1\u6709\u4efb\u4f55\u53ef\u6267\u884c\u4ee3\u7801\uff0c\u4e5f\u4e0d\u80fd\u88ab\u8c03\u5ea6\uff0c\u4ec5\u4ec5\u5728\u8fdb\u7a0b\u5217\u8868\u4e2d\u4fdd\u7559\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u8bb0\u8f7d\u8be5\u8fdb\u7a0b\u7684\u9000\u51fa\u72b6\u6001\u7b49\u4fe1\u606f\u4f9b\u5176\u4ed6\u8fdb\u7a0b\u6536\u96c6\uff0c\u9664\u6b64\u4e4b\u5916\uff0c\u50f5\u5c38\u8fdb\u7a0b\u4e0d\u518d\u5360\u6709\u4efb\u4f55\u5185\u5b58\u7a7a\u95f4\u3002\u4ece\u8fd9\u70b9\u6765\u770b\uff0c\u50f5\u5c38\u8fdb\u7a0b\u867d\u7136\u6709\u4e00\u4e2a\u5f88\u9177\u7684\u540d\u5b57\uff0c\u4f46\u5b83\u7684\u5f71\u54cd\u529b\u8fdc\u8fdc\u62b5\u4e0d\u4e0a\u90a3\u4e9b\u771f\u6b63\u7684\u50f5\u5c38\u5144\u5f1f\uff0c\u771f\u6b63\u7684\u50f5\u5c38\u603b\u80fd\u4ee4\u4eba\u611f\u5230\u6050\u6016\uff0c\u800c\u50f5\u5c38\u8fdb\u7a0b\u5374\u9664\u4e86\u7559\u4e0b\u4e00\u4e9b\u4f9b\u4eba\u51ed\u540a\u7684\u4fe1\u606f\uff0c\u5bf9\u7cfb\u7edf\u6beb\u65e0\u4f5c\u7528\u3002<\/p>\n<h6>\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u50f5\u5c38\u8fdb\u7a0b\uff1f<\/h6>\n<ul>\n<li>\u50f5\u5c38\u8fdb\u7a0b\u5c31\u662f\u5b50\u8fdb\u7a0b\u5df2\u7ecf\u7ed3\u675f\uff0c\u4f46\u662f\u7236\u8fdb\u7a0b\u6ca1\u6709\u5904\u7406\u7684\u8fdb\u7a0b\uff01<\/li>\n<li>\u7236\u8fdb\u7a0b\u53ef\u4ee5\u4f7f\u7528 waitpid\uff0cwait4 \u7b49\u6765\u5904\u7406\u50f5\u5c38\u8fdb\u7a0b\uff01<\/li>\n<li>\u5982\u679c\u7236\u8fdb\u7a0b\u4e0d\u5e78\u5728\u5b50\u8fdb\u7a0b\u4e4b\u524d\u201c\u6b7b\u4e86\u201d\uff0c\u90a3\u4e48\u5b50\u8fdb\u7a0b\u5c31\u4ea4\u7531init(pid == 1)\u8fdb\u7a0b\u53bb\u7ba1\u7406<\/li>\n<\/ul>\n<p>\u5373\uff0c\u7236\u8fdb\u7a0b\u8fd8\u6ca1\u6709\u6765\u5f97\u53ca\u5904\u7406\u5b50\u8fdb\u7a0b\u7684\u9000\u51fa\u72b6\u6001\u7b49\u4fe1\u606f\uff0c\u6240\u4ee5\u624d\u4f1a\u6709\u50f5\u5c38\u8fdb\u7a0b\u7684\u51fa\u73b0\u3002<\/p>\n<h5>\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li><a href=\"http:\/\/www.cnblogs.com\/dkblog\/archive\/2011\/03\/11\/1980556.html\">linux\u4e0a\u8fdb\u7a0b\u72b6\u6001\u67e5\u8be2<\/a><\/li>\n<li><a href=\"http:\/\/blog.chinaunix.net\/uid-26126915-id-2948970.html\">\u8fdb\u7a0b\u7684\u72b6\u6001<\/a><\/li>\n<li><a href=\"http:\/\/blog.sina.com.cn\/s\/blog_7c03bb1f0100wcco.html\">\u8fdb\u7a0b\u72b6\u6001<\/a><\/li>\n<li><a href=\"http:\/\/blog.csdn.net\/huzia\/article\/details\/18946491\">Linux\u8fdb\u7a0b\u72b6\u6001(ps stat)\u4e4bR\u3001S\u3001D\u3001T\u3001Z\u3001X<\/a>\u00a0#\u5168\u9762\u7ec6\u81f4<\/li>\n<li><a href=\"http:\/\/blog.hehehehehe.cn\/a\/10446.htm\">linux\u8fdb\u7a0b\u72b6\u6001\u67e5\u8be2\u2014\u2014ps<\/a><\/li>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u8fdb\u7a0b\u7b80\u4ecb<br \/>\n<a href=\"http:\/\/blog.jobbole.com\/82926\/\">http:\/\/blog.jobbole.com\/82926\/<\/a> #\u5168\u9762\u7ec6\u81f4<br \/>\n<a href=\"https:\/\/idea.popcount.org\/2012-12-11-linux-process-states\/\">https:\/\/idea.popcount.org\/2012-12-11-linux-process-states\/<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/1475683\/linux-process-states\">http:\/\/stackoverflow.com\/questions\/1475683\/linux-process-states<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u8865\u5145\u4e00\u4e9b\u57fa\u7840\u7684Linux\u7cfb\u7edf\u77e5\u8bc6\u3002 \u6b63\u6587\uff1a \u53c2\u8003\u89e3\u7b54\uff1a \u8fdb\u7a0b\u72b6\u6001 \u4e3a\u4e86\u5f04\u660e\u767d\u6b63\u5728\u8fd0\u884c\u7684 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11],"tags":[30,722,723],"class_list":["post-3115","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","tag-linux","tag-process","tag-zombie"],"views":4794,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=3115"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3115\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=3115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=3115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=3115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}