{"id":1796,"date":"2019-01-05T09:46:22","date_gmt":"2019-01-05T01:46:22","guid":{"rendered":"https:\/\/www.yusian.com\/blog\/?p=1796"},"modified":"2020-12-02T09:51:29","modified_gmt":"2020-12-02T01:51:29","slug":"linux%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f%e5%9f%ba%e6%9c%ac%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/cpp\/2019\/01\/05\/0946221796.html","title":{"rendered":"Linux\u64cd\u4f5c\u7cfb\u7edf\u57fa\u672c\u4ecb\u7ecd"},"content":{"rendered":"<h3>1\u3001\u7a0b\u5e8f\u4e0e\u8fdb\u7a0b<\/h3>\n<ul>\n<li>\u7a0b\u5e8f\u76f8\u5f53\u4e8e\u5267\u672c\uff0c\u800c\u8fdb\u7a0b\u5219\u76f8\u5f53\u4e8e\u6839\u636e\u5267\u672c\u4e0a\u6f14\u7684\u620f\uff1b<\/li>\n<\/ul>\n<h3>2\u3001\u591a\u8fdb\u7a0b<\/h3>\n<ul>\n<li>\u5355\u9053\u7a0b\u5e8f\u8bbe\u8ba1\u6a21\u5f0f\uff1a\n<ul>\n<li>\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u6709\u4e00\u4e2a\u8fdb\u7a0b\u5360\u7528CPU\u8d44\u6e90<\/li>\n<li>\u5982\uff1aDOS\u64cd\u4f5c\u7cfb\u7edf<\/li>\n<\/ul>\n<\/li>\n<li>\u591a\u9053\u7a0b\u5e8f\u8bbe\u8ba1\u6a21\u5f0f\uff1a\n<ul>\n<li>CPU\u5212\u5206\u591a\u4e2a<strong>\u65f6\u95f4\u8f6e\u7247<\/strong>\uff0c\u901a\u8fc7<strong>\u65f6\u949f\u4e2d\u65ad<\/strong>\u7684\u65b9\u5f0f\u5207\u6362\u8fdb\u7a0b\uff0c<strong>\u786c\u4ef6\u624b\u6bb5<\/strong><\/li>\n<li>\u5982\uff1a100ns\u4e3a\u4e00\u4e2a\u65f6\u95f4\u8f6e\u7247\uff0c\u4eba\u7684\u773c\u775b\u8bc6\u522b\u5728\u6beb\u79d2\u7ea7\u522b\uff1b<\/li>\n<li>\u4ece\u4eba\u7684\u611f\u77e5\u4e0a\uff0cCPU\u662f\u540c\u65f6\u6267\u884c\u4e86\u591a\u4e2a\u7a0b\u5e8f\uff1b<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>3\u3001CPU\u5de5\u4f5c\u539f\u7406<\/h3>\n<ul>\n<li>\u786c\u76d8\u2014> \u5185\u5b58\u2014> Cache \u2014> \u9884\u53d6\u5668 \u2014> \u8bd1\u7801\u5668 \u2014> \u5bc4\u5b58\u5668 \u2014> \u7b97\u672f\u903b\u8f91\u5355\u5143(ALU) \u2014> \u5bc4\u5b58\u5668 \u2014> \u5185\u5b58 \u2014> \u786c\u76d8<\/li>\n<\/ul>\n<h3>4\u3001MMU\u5de5\u4f5c\u539f\u7406(\u5185\u5b58\u7ba1\u7406\u5355\u5143)<\/h3>\n<ul>\n<li>\u865a\u62df\u5730\u5740\u4e0e\u7269\u7406\u5185\u5b58\u7684\u6620\u5c04<\/li>\n<li>\u8bbe\u7f6e\u4fee\u6539\u5185\u5b58\u8bbf\u95ee\u7ea7\u522b(0 ~ 3)\uff0cLinux\u53ea\u4f7f\u7528\u4e860\u7ea7\u4e0e3\u7ea7\n<ul>\n<li>0\u7ea7\u6700\u9ad8\uff0c\u7528\u4e8e\u8bbf\u95ee\u5185\u6838\u5fc3\u533a(3G-4G\u5730\u5740\u8303\u56f4)<\/li>\n<li>3\u7ea7\u6700\u4f4e\uff0c\u7528\u4e8e\u8bbf\u95ee\u7528\u6237\u533a(0G-3G\u5730\u5740\u8303\u56f4)<\/li>\n<\/ul>\n<\/li>\n<li>\u8fdb\u7a0b\u76f8\u4e92\u72ec\u7acb\uff0c\u540c\u4e00\u7a0b\u5e8f\u4e0d\u540c\u8fdb\u7a0b\u4e4b\u95f4\u6709\u72ec\u7acb\u7684\u7269\u7406\u5730\u5740\u6620\u5c04<\/li>\n<li>\u76f8\u540c\u7a0b\u5e8f\u4e0d\u540c\u8fdb\u7a0b\u5185\u6838\u5fc3\u533a\u6620\u5c04\u7684\u7269\u7406\u5185\u5b58\u4e3a\u540c\u4e00\u7247\u7a7a\u95f4<\/li>\n<\/ul>\n<h3>5\u3001\u8fdb\u7a0b\u63a7\u5236\u5757PCB\uff08\u8fdb\u7a0b\u63cf\u8ff0\u7b26\uff09<\/h3>\n<ul>\n<li>PCB\u7684\u4f4e\u5c42\u5b9e\u73b0\u662ftask_struct\u7ed3\u6784\u4f53<\/li>\n<li>\u8fdb\u7a0bid\uff0c\u7cfb\u7edf\u4e2d\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u6709\u552f\u4e00id\uff0cpid_t\u7c7b\u578b(\u5b9e\u8d28\u4e3a\u975e\u8d1f\u6574\u6570)<\/li>\n<li>\u8fdb\u7a0b\u7684\u4e94\u79cd\u72b6\u6001\n<ul>\n<li>\u51c6\u5907 \u2014> \u53ef\u4e0e\u5c31\u7eea\u5408\u5e76\u6210\u4e00\u4e2a\u72b6\u6001<\/li>\n<li>\u5c31\u7eea \u2014> \u7b49\u5f85\u65f6\u95f4\u8f6e\u7247<\/li>\n<li>\u8fd0\u884c \u2014> \u5360\u7528CPU<\/li>\n<li>\u6302\u8d77 \u2014> \u7b49\u5f85CPU\u5916\u7684\u5176\u4ed6\u8d44\u6e90\uff0c\u4e3b\u52a8\u653e\u5f03CPU<\/li>\n<li>\u505c\u6b62 \u2014> \u8fd0\u884c\u7ed3\u675f<\/li>\n<\/ul>\n<\/li>\n<li>\u8fdb\u7a0b\u5207\u6362\u65f6\u9700\u8981\u4fdd\u5b58\u548c\u6062\u590d\u5bc4\u5b58\u5668\u6570\u636e<\/li>\n<li>\u63cf\u8ff0\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4fe1\u606f\n<ul>\n<li>MMU\u7ef4\u62a4\uff0c\u4f46\u5b58\u50a8\u5728PCB\u4e2d<\/li>\n<\/ul>\n<\/li>\n<li>\u63cf\u8ff0\u63a7\u5236\u7ec8\u7aef\u4fe1\u606f<\/li>\n<li>\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff0c\u8fdb\u7a0b\u76ee\u5f55<\/li>\n<li>umask\u63a9\u7801\uff0c\u4fdd\u62a4\u6587\u4ef6\u9ed8\u8ba4\u6743\u9650<\/li>\n<li>\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868\uff0c\u5305\u542b\u5f88\u591a\u6307\u5411file\u7684\u7ed3\u6784\u4f53\u6307\u9488<\/li>\n<li>\u548c\u4fe1\u53f7\u76f8\u5173\u7684\u4fe1\u606f<\/li>\n<li>\u7528\u6237id\u548c\u7ec4id<\/li>\n<li>\u4f1a\u8bdd(Session)\u548c\u8fdb\u7a0b\u7ec4<\/li>\n<li>\u8fdb\u7a0b\u53ef\u4ee5\u4f7f\u7528\u7684\u8d44\u6e90\u4e0a\u9650\uff08ulimit -a\uff09<\/li>\n<\/ul>\n<h3>6\u3001\u73af\u5883\u53d8\u91cf<\/h3>\n<ul>\n<li>\u64cd\u4f5c\u4e2d\u7528\u6765\u6307\u5b9a\u64cd\u4f5c\u7cfb\u7edf\u8fd0\u884c\u73af\u5883\u7684\u4e00\u4e9b\u53c2\u6570\n<ul>\n<li>\u5b57\u7b26\u4e32<\/li>\n<li>\u952e\u503c\u5bf9<\/li>\n<li>\u63cf\u8ff0\u73af\u5883\u4fe1\u606f<\/li>\n<\/ul>\n<\/li>\n<li>PATH\uff1a\u8bb0\u5f55\u4e86\u5e94\u7528\u7a0b\u5e8f\u6240\u5728\u7684\u8def\u5f84\n<ul>\n<li>shell\u53ea\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u7a0b\u5e8f\uff0c\u662f\u56e0\u4e3ashell\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u8fdb\u884c\u4e86\u641c\u7d22<\/li>\n<\/ul>\n<\/li>\n<li>\u5176\u4ed6\u73af\u5883\u53d8\u91cf\n<ul>\n<li>$SHELL \u2014> \u7ec8\u7aef\u7c7b\u578b<\/li>\n<li>$HOME \u2014> \u4e3b\u76ee\u5f55\u8def\u5f84<\/li>\n<li>$LANG \u2014> \u5f53\u524d\u8bed\u8a00<\/li>\n<\/ul>\n<\/li>\n<li>\u5b58\u50a8\u5f62\u5f0f\n<ul>\n<li>\u4e0e\u547d\u4ee4\u884c\u53c2\u6570\u7c7b\u4f3c<\/li>\n<\/ul>\n<\/li>\n<li>\u4f7f\u7528\u5f62\u5f0f\n<ul>\n<li>\u4e0e\u547d\u4ee4\u884c\u53c2\u6570\u7c7b\u4f3c<\/li>\n<\/ul>\n<\/li>\n<li>\u52a0\u8f7d\u4f4d\u7f6e\n<ul>\n<li>\u9ad8\u4e8e\u6808\u7684\u8d77\u59cb\u4f4d\u7f6e<\/li>\n<\/ul>\n<\/li>\n<li>\u5f15\u5165\u73af\u5883\u53d8\u91cf\u8868\uff1a\n<ul>\n<li>extern char ** environ<\/p>\n<\/li>\n<li>\n<p>\u6253\u5370\u5f53\u524d\u6240\u6709\u7684\u73af\u5883\u53d8\u91cf<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-c line-numbers\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\/\/ \u73af\u5883\u53d8\u91cf\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\uff0c\u5916\u90e8\u58f0\u660e\u540e\u5373\u53ef\u76f4\u63a5\u4f7f\u7528\nextern char** environ;\nint main(){\n    \/\/ enviorn\u662f\u4e00\u4e2a\u6307\u5411\u6307\u9488\u7684\u6307\u9488\uff0c*environ\u5373\u4e3a\u4e00\u4e2a\u6279\u5411\u73af\u5883\u53d8\u91cf\u7684\u6307\u9488\n    \/\/ enviorn++\u53ef\u4f7f\u5f97\u6307\u9488\u540e\u79fb\u4e00\u4f4d\uff0c*environ\u6307\u9488\u4e3a\u7a7a\u5219\u5168\u90e8\u904d\u5386\n    while(*environ){\n        \/\/ %s\u53ef\u4ee5\u76f4\u63a5\u6253\u5370\u6307\u5411\u73af\u5883\u53d8\u91cf\u6307\u9488\u7684\u6307\u5411\u7684\u5185\u5bb9\n        printf(\"%s\\n\", *environ);\n        environ++;\n    }\n    return 0;\n}\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u76f8\u5173\u51fd\u6570\u6709\uff1a<strong>getenv\u3001setenv\u3001unsetenv<\/strong><\/p>\n<pre><code class=\"language-c line-numbers\">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n\nextern char** environ;\n\nint main(int argc, char* argv[]){\n  \/\/ \u9884\u8bbe\u4e00\u4e2a\u73af\u5883\u53d8\u91cf\u7684kye\u503c\n  const char* name = \"ABCDEFG\";\n  \/\/ 1\u3001\u83b7\u53d6\u8be5\u73af\u5883\u53d8\u91cf\u7684\u503c\n  char* val = getenv(name);\n  printf(\"%s:%s\\n\", name, val);\n  \/\/ 2\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u503c\n  int ret = setenv(name, \"Your are right!!\", 1);\n  if (ret == -1){\n      perror(\"setenv\");\n      exit(1);\n  }\n  printf(\"%s:%s\\n\", name, getenv(name));\n  \/\/ 3\u3001\u6e05\u9664\u8be5\u73af\u5883\u53d8\u91cf\n  ret = unsetenv(name);\n  if (ret == -1){\n      perror(\"unsetenv\");\n      exit(1);\n  }\n  printf(\"%s:%s\\n\", name, getenv(name));\n  return 0;\n}\n<\/code><\/pre>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u7a0b\u5e8f\u4e0e\u8fdb\u7a0b \u7a0b\u5e8f\u76f8\u5f53\u4e8e\u5267\u672c\uff0c\u800c\u8fdb\u7a0b\u5219\u76f8\u5f53\u4e8e\u6839\u636e\u5267\u672c\u4e0a\u6f14\u7684\u620f\uff1b 2\u3001\u591a\u8fdb\u7a0b \u5355\u9053\u7a0b\u5e8f\u8bbe\u8ba1\u6a21\u5f0f\uff1a \u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u6709\u4e00\u4e2a\u8fdb\u7a0b\u5360\u7528CPU\u8d44\u6e90 \u5982\uff1aDOS\u64cd\u4f5c\u7cfb\u7edf \u591a\u9053\u7a0b\u5e8f\u8bbe\u8ba1\u6a21\u5f0f\uff1a CPU\u5212\u5206\u591a\u4e2a\u65f6\u95f4\u8f6e\u7247\uff0c\u901a\u8fc7\u65f6\u949f\u4e2d\u65ad\u7684\u65b9\u5f0f\u5207\u6362\u8fdb\u7a0b\uff0c\u786c\u4ef6\u624b\u6bb5 \u5982\uff1a100ns\u4e3a\u4e00\u4e2a\u65f6\u95f4\u8f6e\u7247\uff0c\u4eba\u7684\u773c\u775b\u8bc6\u522b\u5728\u6beb\u79d2\u7ea7\u522b\uff1b \u4ece\u4eba\u7684\u611f\u77e5\u4e0a\uff0cCPU\u662f\u540c\u65f6\u6267\u884c\u4e86\u591a\u4e2a\u7a0b\u5e8f\uff1b 3\u3001CPU\u5de5\u4f5c\u539f\u7406 \u786c\u76d8\u2014> \u5185\u5b58\u2014> Cache \u2014> \u9884\u53d6\u5668 \u2014> \u8bd1\u7801\u5668 \u2014> \u5bc4\u5b58\u5668 \u2014> \u7b97\u672f\u903b\u8f91\u5355\u5143(ALU) \u2014> \u5bc4\u5b58\u5668 \u2014> \u5185\u5b58 \u2014> \u786c\u76d8 4\u3001MMU\u5de5\u4f5c\u539f\u7406(\u5185\u5b58\u7ba1\u7406\u5355\u5143) \u865a\u62df\u5730\u5740\u4e0e\u7269\u7406\u5185\u5b58\u7684\u6620\u5c04 \u8bbe\u7f6e\u4fee\u6539\u5185\u5b58\u8bbf\u95ee\u7ea7\u522b(0 ~ 3)\uff0cLinux\u53ea\u4f7f\u7528\u4e860\u7ea7\u4e0e3\u7ea7 0\u7ea7\u6700\u9ad8\uff0c\u7528\u4e8e\u8bbf\u95ee\u5185\u6838\u5fc3\u533a(3G-4G\u5730\u5740\u8303\u56f4) 3\u7ea7\u6700\u4f4e\uff0c\u7528\u4e8e\u8bbf\u95ee\u7528\u6237\u533a(0G-3G\u5730\u5740\u8303\u56f4) \u8fdb\u7a0b\u76f8\u4e92\u72ec\u7acb\uff0c\u540c\u4e00\u7a0b\u5e8f\u4e0d\u540c\u8fdb\u7a0b\u4e4b\u95f4\u6709\u72ec\u7acb\u7684\u7269\u7406\u5730\u5740\u6620\u5c04 \u76f8\u540c\u7a0b\u5e8f\u4e0d\u540c\u8fdb\u7a0b\u5185\u6838\u5fc3\u533a\u6620\u5c04\u7684\u7269\u7406\u5185\u5b58\u4e3a\u540c\u4e00\u7247\u7a7a\u95f4 5\u3001\u8fdb\u7a0b\u63a7\u5236\u5757PCB\uff08\u8fdb\u7a0b\u63cf\u8ff0\u7b26\uff09 PCB\u7684\u4f4e\u5c42\u5b9e\u73b0\u662ftask_struct\u7ed3\u6784\u4f53 \u8fdb\u7a0bid\uff0c\u7cfb\u7edf\u4e2d\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u6709\u552f\u4e00id\uff0cpid_t\u7c7b\u578b(\u5b9e\u8d28\u4e3a\u975e\u8d1f\u6574\u6570) \u8fdb\u7a0b\u7684\u4e94\u79cd\u72b6\u6001 \u51c6\u5907 \u2014> \u53ef\u4e0e\u5c31\u7eea\u5408\u5e76\u6210\u4e00\u4e2a\u72b6\u6001 \u5c31\u7eea \u2014> \u7b49\u5f85\u65f6\u95f4\u8f6e\u7247 \u8fd0\u884c \u2014> \u5360\u7528CPU \u6302\u8d77 \u2014> \u7b49\u5f85CPU\u5916\u7684\u5176\u4ed6\u8d44\u6e90\uff0c\u4e3b\u52a8\u653e\u5f03CPU \u505c\u6b62 \u2014> [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88],"tags":[310,312],"class_list":["post-1796","post","type-post","status-publish","format-standard","hentry","category-cpp","tag-linux","tag-312"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=1796"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1796\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=1796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=1796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=1796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}