{"id":256,"date":"2022-10-28T00:19:35","date_gmt":"2022-10-27T16:19:35","guid":{"rendered":"https:\/\/cococat.top\/?p=256"},"modified":"2022-10-28T00:19:35","modified_gmt":"2022-10-27T16:19:35","slug":"2022campusnote_1_os","status":"publish","type":"post","link":"https:\/\/cococat.top\/index.php\/2022\/10\/28\/2022campusnote_1_os\/","title":{"rendered":"2022\u6821\u62db\u7b14\u8bb01\uff1a\u64cd\u4f5c\u7cfb\u7edf"},"content":{"rendered":"<h1>1. Linux \u8fdb\u7a0b\u7a7a\u95f4<\/h1>\n<p>\uff08\u4ece\u4e0a\u5230\u4e0b\u662f\u4ece\u9ad8\u5730\u5740\u5230\u4f4e\u5730\u5740\uff09\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u6bb5\u540d<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">\u5185\u6838(kernel space)<\/td>\n<td style=\"text-align: center;\">\u2026<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u6808 \u2193<\/td>\n<td style=\"text-align: center;\">\u5b58\u653e\u5c40\u90e8\u53d8\u91cf\uff0c\u51fd\u6570\u53c2\u6570\u548c\u8fd4\u56de\u503c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">.mmap \u2193<\/td>\n<td style=\"text-align: center;\">\u5b9e\u73b0\u6587\u4ef6(\u8bbe\u5907)\u7684\u6620\u5c04\uff0c\u4f8b\u5982\u52a8\u6001\u94fe\u63a5\u5e93<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u5806 \u2191<\/td>\n<td style=\"text-align: center;\">\u5b58\u653e\u52a8\u6001\u5206\u914d\u7684\u5185\u5b58<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">.bss<\/td>\n<td style=\"text-align: center;\">\u672a\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u548c\uff08\u5168\u5c40\/\u5c40\u90e8\uff09\u9759\u6001\u53d8\u91cf<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">.data<\/td>\n<td style=\"text-align: center;\">\u53c8\u5206\u4e3a.rdata\uff08<strong>\u5168\u5c40<\/strong>\u5e38\u91cf\uff09\u548c.wdata\uff08\u5df2\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u548c\u5df2\u521d\u59cb\u5316\u7684\u5168\u5c40\/\u5c40\u90e8\u9759\u6001\u53d8\u91cf\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">.text<\/td>\n<td style=\"text-align: center;\">\u5b58\u653e\u4ee3\u7801<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>.data\u6bb5\u5728\u7f16\u8bd1\u65f6\u5c31\u5df2\u7ecf\u5206\u914d\u597d\uff0c\u5728\u6574\u4e2a\u7a0b\u5e8f\u8fd0\u884c\u671f\u95f4\u4e00\u76f4\u5b58\u5728\u3002<\/p>\n<h2>1.1. \u4e3a\u4ec0\u4e48\u8981\u5206\u5806\u548c\u6808\uff1f<\/h2>\n<p>\u6808\u4e0a\u7684\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u7531\u8fdb\u51fa\u6808\u81ea\u52a8\u7ba1\u7406\uff0c\u79bb\u5f00\u4f5c\u7528\u57df\u65f6\uff0c\u81ea\u52a8\u6790\u6784\u3001\u91ca\u653e\u5185\u5b58\uff0c\u4f46\u662f\u4e0d\u662f\u6240\u6709\u7684\u573a\u666f\u4e0b\u90fd\u9700\u8981\u8fd9\u79cd\u81ea\u52a8\u91ca\u653e\uff0c\u5f53\u6211\u4eec\u9700\u8981\u4e00\u5757\u5185\u5b58\u79bb\u5f00\u4f5c\u7528\u57df\u51fd\u6570\u540e\u4f9d\u7136\u5b58\u5728\uff0c\u5219\u6808\u4e0d\u80fd\u6ee1\u8db3\u8981\u6c42\u3002<\/p>\n<h2>1.2. \u9759\u6001\u53d8\u91cf\u653e\u5728\u54ea\u91cc\uff1f<\/h2>\n<p>\u5df2\u7ecf\u521d\u59cb\u5316\u7684\u653e\u5728.wdata\uff0c\u672a\u521d\u59cb\u5316\u7684\u653e\u5728.bss<\/p>\n<h2>1.3. \u5c40\u90e8\u5e38\u91cf\u653e\u5728\u54ea\u91cc\uff1f<\/h2>\n<p>\u5176\u5b9e\u5c31\u662fconst\u4fee\u9970\u7684\u5c40\u90e8\u53d8\u91cf\uff0c\u4f9d\u7136\u5728\u6808\u7aef\u800c\u975e.rdata<\/p>\n<h2>1.4. \u865a\u8868\u653e\u5728\u54ea\u91cc\uff1f<\/h2>\n<p>.rdata\u6bb5\u5373\u5168\u5c40\u5e38\u91cf\u533a<br \/>\n<a href=\"https:\/\/blog.csdn.net\/chczy1\/article\/details\/100521615\">https:\/\/blog.csdn.net\/chczy1\/article\/details\/100521615<\/a><\/p>\n<h2>1.5. \u5185\u6838\u6808\uff1f\u7528\u6237\u6808\uff1f<\/h2>\n<p>\u6bcf\u4e2a\u8fdb\u7a0b\u4f1a\u6709\u4e24\u4e2a\u6808\uff0c\u4e00\u4e2a\u7528\u6237\u6808\uff0c\u5b58\u5728\u4e8e\u7528\u6237\u7a7a\u95f4\uff0c\u4e00\u4e2a\u5185\u6838\u6808\uff0c\u5b58\u5728\u4e8e\u5185\u6838\u7a7a\u95f4\u3002\u5f53\u8fdb\u7a0b\u5728\u7528\u6237\u7a7a\u95f4\u8fd0\u884c\u65f6\uff0ccpu\u5806\u6808\u6307\u9488\u5bc4\u5b58\u5668\u91cc\u9762\u7684\u5185\u5bb9\u662f\u7528\u6237\u5806\u6808\u5730\u5740\uff0c\u4f7f\u7528\u7528\u6237\u6808\uff1b\u5f53\u8fdb\u7a0b\u5728\u5185\u6838\u7a7a\u95f4\u65f6\uff0ccpu\u5806\u6808\u6307\u9488\u5bc4\u5b58\u5668\u91cc\u9762\u7684\u5185\u5bb9\u662f\u5185\u6838\u6808\u7a7a\u95f4\u5730\u5740\uff0c\u4f7f\u7528\u5185\u6838\u6808<br \/>\n<a href=\"https:\/\/blog.csdn.net\/jasonLee_lijiaqi\/article\/details\/80181501\">https:\/\/blog.csdn.net\/jasonLee_lijiaqi\/article\/details\/80181501<\/a><\/p>\n<h2>1.6. \u5b50\u7ebf\u7a0b\u7684\u6808\u7a7a\u95f4\u5728\u7236\u7ebf\u7a0b\u7684\u4ec0\u4e48\u4f4d\u7f6e\uff1f<\/h2>\n<p>\u3010\u672a\u8bc1\u5b9e\u7684\u8bf4\u6cd5\u3011\u5728\u5806\u4e2d\u5f00\u8f9f\u3002\u6b64\u5916\uff0c\u5b50\u7ebf\u7a0b\u7684\u6808\u7a7a\u95f4\u5f00\u8f9f\u540e\u8fd8\u4f1a\u989d\u5916\u5206\u914d\u4e00\u5b9a\u5927\u5c0f\u7684\u533a\u57df\uff0c\u8fd9\u4e2a\u533a\u57df\u4e0d\u53ef\u8bfb\u4e0d\u53ef\u5199\uff0c\u8bbf\u95ee\u5373\u53d1\u751f\u6bb5\u9519\u8bef\uff0c\u7528\u6765\u9632\u6b62\u6808\u6ea2\u51fa\u3002<br \/>\n<a href=\"http:\/\/www.360doc.com\/content\/16\/0506\/11\/478627_556725732.shtml\">http:\/\/www.360doc.com\/content\/16\/0506\/11\/478627_556725732.shtml<\/a><\/p>\n<h1>2. MMAP<\/h1>\n<p>\u5c06\u4e00\u4e2a\u6587\u4ef6\uff08\u6216\u8bbe\u5907\uff09\u76f4\u63a5\u6620\u5c04\u5230\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u8fdb\u7a0b\u53ef\u4ee5\u901a\u8fc7\u6307\u9488\u64cd\u4f5c\u6b64\u6bb5\u5185\u5b58\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u5c06\u810f\u9875\u5199\u56de\uff0c\u800c\u4e0d\u5fc5\u624b\u52a8\u8c03\u7528read\/write\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u8c03\u7528msync\u5f3a\u5236\u540c\u6b65\u3002mmap\u5e76\u4e0d\u5206\u914d\u7a7a\u95f4\uff0c\u53ea\u662f\u5355\u7eaf\u7684\u5730\u5740\u6620\u5c04\uff0c\u591a\u4e2a\u8fdb\u7a0b\u4e4b\u95f4\u53ef\u4ee5\u901a\u8fc7mmap\u540c\u4e00\u4e2a\u6587\u4ef6\u5b9e\u73b0\u5171\u4eab\u5185\u5b58\u3002<br \/>\n\u4e0e\u4f20\u7edf\u7684\u6587\u4ef6\u8bfb\u53d6\u8fc7\u7a0b\u76f8\u6bd4\uff0cmmap\u673a\u5236\u901a\u8fc7\u5c06\u7528\u6237\u8fdb\u7a0b\u7a7a\u95f4\u76f4\u63a5\u6620\u5c04\u5230\u5916\u5b58\u4e2d\u7684\u6587\u4ef6\uff0c\u4ece\u800c\u7565\u53bb\u4e86\u5e38\u89c4\u6587\u4ef6\u8bfb\u53d6\u65b9\u5f0f\u4e2d\uff0c\u5148\u628a\u6587\u4ef6\u6570\u636e\u8bfb\u53d6\u5230\u5185\u6838\u7684\u9875\u7f13\u5b58\u3001\u800c\u540e\u518d\u5c06\u6570\u636e\u4ece\u5185\u6838\u7684\u9875\u7f13\u5b58\u62f7\u8d1d\u5230\u7528\u6237\u6001\u8fdb\u7a0b\u7a7a\u95f4\u7684\u8017\u65f6\u64cd\u4f5c\uff0c\u6240\u4ee5\u6548\u7387\u6bd4\u5e38\u89c4\u7684\u6587\u4ef6\u8bfb\u53d6\u66f4\u9ad8\u3002<br \/>\n<a href=\"https:\/\/blog.51cto.com\/u_15284125\/2988714\">https:\/\/blog.51cto.com\/u_15284125\/2988714<\/a><br \/>\n<a href=\"https:\/\/blog.nowcoder.net\/n\/850befe7c86d446ab73c89c5f18d8dcb?from=nowcoder_improve\">https:\/\/blog.nowcoder.net\/n\/850befe7c86d446ab73c89c5f18d8dcb?from=nowcoder_improve<\/a><\/p>\n<h1>3. \u5185\u5b58\u7ba1\u7406<\/h1>\n<h2>3.1. \u865a\u62df\u5185\u5b58\u673a\u5236<\/h2>\n<p>\u4e00\u79cd\u5185\u5b58\u7ba1\u7406\u6280\u672f\uff0c\u903b\u8f91\u4e0a\u8fde\u7eed\u7684\u5185\u5b58\u662f\u7531\u8bb8\u591a\u7269\u7406\u5185\u5b58\u4e0a\u7684\u5e76\u4e0d\u8fde\u7eed\u7684\u9875\u7ec4\u6210\uff0c\u53ef\u4ee5\u4f7f\u5f97\u4f7f\u5f97\u5e94\u7528\u7a0b\u5e8f\u8ba4\u4e3a\u62e5\u6709\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u3002<br \/>\n\u5177\u6709\u903b\u8f91\u5185\u5b58\u53ef\u4ee5\u5927\u4e8e\u7269\u7406\u5185\u5b58\u3001\u5b89\u5168\uff08\u907f\u514d\u8bbf\u95ee\u5185\u6838\u6216\u8005\u5176\u4ed6\u8fdb\u7a0b\u7684\u5185\u5b58\uff09\u3001\u53ef\u4ee5\u5171\u4eab\u5185\u5b58\u7b49\u4f18\u70b9\u3002<\/p>\n<h2>3.2. \u6bb5\u9875\u5f0f<\/h2>\n<p>\u6bb5\u5f0f\u5185\u5b58\u7ba1\u7406\u5c06\u5185\u5b58\u7684\u8fdb\u7a0b\u7a7a\u95f4\u6309\u903b\u8f91\u5206\u4e3a\u6570\u4e2a\u6bb5\uff08\u4f8b\u5982.data, .code\uff09\uff0c\u5e76\u5bf9\u6bcf\u4e2a\u6bb5\u5efa\u7acb\u5230\u7269\u7406\u5185\u5b58\u7684\u6620\u5c04\u5173\u7cfb\u3002<br \/>\n\u9875\u5f0f\u5185\u5b58\u7ba1\u7406\u65e0\u89c6\u903b\u8f91\u6bb5\uff0c\u5c06\u5185\u5b58\u7684\u6309\u56fa\u5b9a\u5927\u5c0f\uff08\u4e00\u822c\u662f4KB\uff09\u5206\u4e3a\u591a\u4e2a\u9875\uff0c\u6bcf\u4e2a\u903b\u8f91\u9875\u4e0e\u7269\u7406\u5185\u5b58\u5757\u8fdb\u884c\u6620\u5c04\u3002<br \/>\n\u6bb5\u9875\u5f0f\u5c31\u662f\u4ee5\u4e0a\u4e8c\u8005\u7684\u7ed3\u5408\uff0c\u5206\u6bb5\u5e76\u5728\u6bcf\u4e2a\u6bb5\u5185\u5206\u9875\u3002<\/p>\n<h2>3.3. TLB<\/h2>\n<p>\u903b\u8f91\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u8f6c\u6362\u9700\u8981\u9875\u8868\uff0c\u9875\u8868\u5728\u5185\u5b58\u7684\u5185\u6838\u7a7a\u95f4\u4e2d\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u7684PCB\u5305\u542b\u4e86\u6307\u5411\u9875\u8868\u7684\u6307\u9488\u3002TLB(translation lookaside buffer)\u8f6c\u8bd1\u540e\u5907\u7f13\u5b58\uff0c\u53c8\u79f0\u5feb\u8868\uff0c\u662f<strong>CPU\u4e2d\u7684<\/strong>\u4e00\u79cd\u7f13\u5b58\uff0c\u7f13\u5b58\u865a\u5b9e\u5730\u5740\u6620\u5c04\uff0c\u4f5c\u4e3a\u786c\u4ef6\u7f13\u5b58\uff0c\u67e5\u8be2\u901f\u5ea6\u6bd4\u9875\u8868\u5feb\u5f88\u591a\uff1b\u5f53TLB\u672a\u547d\u4e2d\uff0c\u518d\u67e5\u9875\u8868\u3002<\/p>\n<h2>3.4. \u7f3a\u9875\u4e2d\u65ad<\/h2>\n<p>\u5185\u5b58\u8fdb\u7a0b\u7a7a\u95f4\u4e2d\u4e0d\u662f\u6240\u6709\u9875\u90fd\u5b9e\u9645\u653e\u5728\u5185\u5b58\u4e2d\u3002\u5f53\u8bbf\u95ee\u5230\u7684\u903b\u8f91\u9875\u4e0d\u5728\u5185\u5b58\u4e2d\u65f6\uff0c\u9700\u8981\u8fdb\u5165\u7f3a\u9875\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u64cd\u4f5c\u7cfb\u7edf\u6839\u636e\u9875\u8868\u4e2d\u7684\u5916\u5b58\u5730\u5740\u627e\u5230\u5bf9\u5e94\u9875\u8c03\u5165\u5185\u5b58\u3002<\/p>\n<h2>3.5. \u9875\u9762\u7f6e\u6362\u7b97\u6cd5<\/h2>\n<p>\u53d1\u751f\u7f3a\u9875\u4e2d\u65ad\u65f6\uff0c\u82e5\u5185\u5b58\u4e2d\u6ca1\u6709\u95f2\u7f6e\u7684\u7269\u7406\u9875\uff0c\u5fc5\u987b\u9009\u62e9\u4e00\u5757\u8c03\u51fa\u5185\u5b58\u8fdb\u5165\u5916\u5b58\u3002\u5e38\u89c1\u7b97\u6cd5\u662fFIFO\uff08\u6dd8\u6c70\u6700\u65e9\u8fdb\u5165\u5185\u5b58\u7684\u9875\uff0c\u73b0\u5df2\u5f88\u5c11\u7528\uff09\u548cLRU\uff08\u6dd8\u6c70\u6700\u4e45\u672a\u88ab\u4f7f\u7528\u7684\u9875\uff0c\u5e38\u7528\uff0c\u9700\u8981\u8bb0\u5f55\u9875\u7684\u8bbf\u95ee\u60c5\u51b5\u6240\u4ee5\u5f00\u9500\u5927\uff0c\u786c\u4ef6\u5b9e\u73b0\u6bd4\u8f83\u590d\u6742\uff0c\u800c\u8f6f\u4ef6\u5b9e\u73b0\u53ef\u4ee5\u7528\u53cc\u5411\u94fe\u8868+\u54c8\u5e0c\uff0cLC146\uff09<\/p>\n<h2>3.6. \u52a8\u6001\u5185\u5b58\u5206\u914d\u7b97\u6cd5<\/h2>\n<p>\u4e00\u822c\u7528\u94fe\u8868\u7684\u65b9\u5f0f\u7ba1\u7406\u7a7a\u95f2\u5185\u5b58\u5757\u3002\u5e38\u7528\u7684\u5206\u914d\u65b9\u6cd5\u6709\u9996\u6b21\u9002\u5e94\u3001\u6700\u4f73\u9002\u5e94\u3001\u6700\u574f\u9002\u5e94<\/p>\n<h2>3.7. \u5185\u5b58\u6296\u52a8<\/h2>\n<p>\u4e3b\u8981\u6709\u4e24\u79cd\u53ef\u80fd\u7684\u539f\u56e0\uff1a<\/p>\n<ol>\n<li>\u5728\u4e00\u4e2a\u5faa\u73af\u4e2d\u5927\u91cf\u521b\u5efa\u4e34\u65f6\u5bf9\u8c61<\/li>\n<li>\u9875\u9762\u7f6e\u6362\u7b97\u6cd5\u4e0d\u5408\u7406<\/li>\n<\/ol>\n<h1>4. \u8fdb\u7a0b\u548c\u7ebf\u7a0b\u7684\u533a\u522b\uff1f<\/h1>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u533a\u522b\u9879<\/th>\n<th style=\"text-align: center;\">\u8fdb\u7a0b<\/th>\n<th style=\"text-align: center;\">\u7ebf\u7a0b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">\u6700\u5c0f\u5355\u4f4d\uff1f<\/td>\n<td style=\"text-align: center;\">\u8d44\u6e90\u5206\u914d\u7684\u6700\u5c0f\u5355\u4f4d<\/td>\n<td style=\"text-align: center;\">CPU\u8c03\u5ea6\u7684\u6700\u5c0f\u5355\u4f4d<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u79c1\u6709\u8d44\u6e90<\/td>\n<td style=\"text-align: center;\">\u8bbe\u5907\uff08\u6587\u4ef6\uff09\uff0c\u4ee3\u7801\u6bb5\uff0c\u6570\u636e\u6bb5\uff0c\u5806 \uff08\u8fd9\u4e9b\u90fd\u7531\u4e0b\u5c5e\u7ebf\u7a0b\u5171\u4eab\uff09<\/td>\n<td style=\"text-align: center;\">\u6808\uff0c\u5bc4\u5b58\u5668\uff0cPC\uff0cpid<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u5f00\u9500<\/td>\n<td style=\"text-align: center;\">\u521b\u5efa\u3001\u5207\u6362\u5f00\u9500\u5927<\/td>\n<td style=\"text-align: center;\">\u521b\u5efa\u3001\u5207\u6362\u5f00\u9500\u5c0f<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u76f8\u4e92\u5f71\u54cd<\/td>\n<td style=\"text-align: center;\">\u8fdb\u7a0b\u5d29\u4e86\u4e92\u76f8\u65e0\u5f71\u54cd<\/td>\n<td style=\"text-align: center;\">\u4e00\u4e2a\u7ebf\u7a0bsegfault\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u4f1a\u7ec8\u6b62\u540c\u4e00\u8fdb\u7a0b\u7684\u5176\u4ed6\u7ebf\u7a0b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>4.1. \u5982\u4f55\u7406\u89e3\u8fdb\u7a0b\u7684\u521b\u5efa\/\u5207\u6362\u5f00\u9500\u66f4\u5927\uff1f<\/h2>\n<p>\u8fdb\u7a0b\u6709\u72ec\u7acb\u7684\u8fdb\u7a0b\u7a7a\u95f4\uff0c\u800c\u7ebf\u7a0b\u90fd\u662f\u5171\u7528\u4e3b\u7ebf\u7a0b\u7684\u8fdb\u7a0b\u7a7a\u95f4\u3002\u5728\u521b\u5efa\/\u5207\u6362\u8fdb\u7a0b\u65f6\uff0c\u9700\u8981\u8fdb\u884c\u8fdb\u7a0b\u7a7a\u95f4\u7684\u5207\u6362\uff0c\u6b64\u65f6\u9700\u8981\u4fee\u6539\u9875\u8868\uff08\u9875\u8868\u4fee\u6539\u540e\u81ea\u7136TLB\u4e5f\u5931\u6548\uff09\uff0c\u6b64\u6b65\u9aa4\u5b58\u5728\u5f00\u9500\uff0c\u5e76\u4e14\u5207\u6362\u540e\u7531\u4e8eTLB\u5931\u6548\uff0c\u8fd0\u884c\u901f\u5ea6\u4f1a\u53d8\u6162\u3002\u800c\u7ebf\u7a0b\u5207\u6362\u4e0d\u9700\u8981\u4fee\u6539\u9875\u8868\u4e0eTLB<\/p>\n<h1>5. \u7ebf\u7a0b\u6a21\u578b\u4e0e\u534f\u7a0b<\/h1>\n<h2>5.1. \u7ebf\u7a0b\u6a21\u578b\uff1a\u7528\u6237\u6001\u7ebf\u7a0b\u548c\u5185\u6838\u6001\u7ebf\u7a0b<\/h2>\n<p>\u8fd0\u884c\u4e8e\u7528\u6237\u6001\u7684\u7ebf\u7a0b\u672c\u8eab\u662f\u4e0d\u80fd\u88abOS\u5185\u6838\u611f\u77e5\u7684\uff1b\u5185\u6838\u8c03\u5ea6\u7684\u5bf9\u8c61\u88ab\u79f0\u4f5c\u5185\u6838\u8c03\u5ea6\u5b9e\u4f53(kernel scheduling entity, KSE)\uff0c\u53c8\u88ab\u79f0\u4e3a\u5185\u6838\u7ea7\u7ebf\u7a0b\uff08Kernel-Level Thread, KLT\uff09\u3002\u7528\u6237\u6001\u7ebf\u7a0b\uff08User-Level Thread, ULT\uff09\u548c\u5185\u6838\u6001\u7ebf\u7a0b\u4e4b\u95f4\u7684\u5bf9\u5e94\u5173\u7cfb\u88ab\u79f0\u4e3a\u7ebf\u7a0b\u6a21\u578b\u3002<br \/>\n\u6700\u7ecf\u5178\u7684\u7ebf\u7a0b\u6a21\u578b\u65b9\u6848\u662f<strong>\u4e00\u5bf9\u4e00\u7ebf\u7a0b\u6a21\u578b<\/strong>\uff0c\u5373KLT\uff0c\u5728\u5927\u90e8\u5206\u7f16\u7a0b\u8bed\u8a00\u7684\u7ebf\u7a0b\u5e93\u4e2d\uff08\u5305\u62eclinux pthread, C++11 <code>std::thread<\/code>, <code>Java::lang::thread<\/code>\uff09\uff0c\u7528\u6237\u6001\u7ebf\u7a0b\u548c\u5185\u6838\u6001\u7ebf\u7a0b\u90fd\u662f\u4e00\u5bf9\u4e00\u7684\u5173\u7cfb\uff0c\u4f8b\u5982<code>std::thread<\/code>\u53ea\u662f\u5bf9KSE\u7684\u4e00\u5c42\u5c01\u88c5\u3002\u5728\u4e00\u5bf9\u4e00\u7684\u7ebf\u7a0b\u6a21\u578b\u4e0b\uff0c\u7ebf\u7a0b\u7684\u521b\u5efa\u3001\u9500\u6bc1\u3001\u8c03\u5ea6\u5b8c\u5168\u501f\u52a9OS\u5185\u6838\u63d0\u4f9b\u7684\u7ebf\u7a0b\u529f\u80fd\uff0c\u5b9e\u73b0\u7b80\u5355\u3002\u6b64\u6a21\u5f0f\u4e0b<strong>\u7ebf\u7a0b\u8fd0\u884c\u5728\u7528\u6237\u6001\uff0c\u800c\u8c03\u5ea6\u548c\u7ba1\u7406\u5728\u5185\u6838\u6001<\/strong>\u3002\u4e0d\u8fc7\u4e5f\u6b63\u662f\u56e0\u4e3a\u8fd9\u4e2a\u539f\u56e0\uff0c\u7ebf\u7a0b\u91cf\u5f88\u5927\u7684\u573a\u666f\u4e0b\u5bf9OS\u6027\u80fd\u6709\u8f83\u5927\u5f71\u54cd\u3002<br \/>\n\u534f\u7a0b\u5219\u662f\u4e00\u79cd\u5178\u578b\u7684<strong>\u591a\u5bf9\u4e00\u7ebf\u7a0b\u6a21\u578b<\/strong>\uff0c\u5373ULT\uff0c\u591a\u4e2a\u7528\u6237\u6001\u7ebf\u7a0b\uff08\u5373\u534f\u7a0b\uff09\u5bf9\u5e94\u4e00\u4e2a\u5185\u6838\u6001\u7ebf\u7a0b\uff0c\u534f\u7a0b\u4e4b\u95f4\u7684\u5207\u6362\u7531\u8bed\u8a00\u7684\u534f\u7a0b\u5e93\u81ea\u884c\u8c03\u5ea6\u3002ULT\u7684<strong>\u8fd0\u884c\u548c\u7ba1\u7406\u8c03\u5ea6\u90fd\u5728\u7528\u6237\u6001<\/strong>\u3002\u7531\u4e8eOS\u4e0d\u80fd\u611f\u77e5\u534f\u7a0b\u7684\u5b58\u5728\uff0c\u6545\u5b58\u5728\u4e00\u4e2a\u534f\u7a0b\u963b\u585e\u540e\u5bfc\u81f4\u4e00\u4e2a\u8fdb\u7a0b\u4e0b\u7684\u6240\u6709\u534f\u7a0b\u90fd\u963b\u585e\u7684\u7f3a\u70b9\u3002<br \/>\n\u6b64\u5916\uff0c\u5b58\u5728\u4e00\u79cd<strong>\u6df7\u5408\u578b\u7ebf\u7a0b\u6a21\u578b<\/strong>\u3002\u8fd9\u79cd\u6a21\u578b\u7efc\u5408\u4e86\u4e0a\u8ff0\u4e24\u8005\u7684\u4f18\u70b9\uff0c\u4e3a\u4e00\u4e2a\u8fdb\u7a0b\u521b\u5efa\u591a\u4e2a\u5185\u6838\u6001\u7ebf\u7a0b\uff0c\u7528\u6237\u6001\u7ebf\u7a0b\u5219\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u4e0e\u4e0d\u540c\u7684\u5185\u6838\u6001\u8fdb\u7a0b\u8fdb\u884c\u6620\u5c04\u3002\u5f53\u67d0\u4e2a\u5185\u6838\u7ea7\u7ebf\u7a0b\u7531\u4e8e\u5176\u5bf9\u5e94\u7684\u67d0\u4e2a\u7528\u6237\u6001\u7ebf\u7a0b\u963b\u585e\u800c\u88ab\u8c03\u5ea6\u6682\u505c\u8fd0\u884c\u65f6\uff0c\u8bed\u8a00\u7684\u7ebf\u7a0b\u5e93\u53ef\u4ee5\u4fee\u6539\u5176\u4e2d\u672a\u963b\u585e\u7684\u7528\u6237\u6001\u7ebf\u7a0b\uff0c\u5c06\u4ed6\u4eec\u4e0e\u5176\u4ed6\u7684\u5185\u6838\u6001\u7ebf\u7a0b\u91cd\u65b0\u5efa\u7acb\u6620\u5c04\u5173\u7cfb\u3002\u8fd9\u79cd\u8c03\u5ea6\u673a\u5236\u5f88\u590d\u6742\uff0c\u4e00\u4e2a\u5178\u578b\u4f8b\u5b50\u662fgo\u8bed\u8a00\u7684\u8fd0\u884c\u65f6\u8c03\u5ea6\u5668\u3002<br \/>\n<a href=\"https:\/\/www.jianshu.com\/p\/dca73cbb87a6\">https:\/\/www.jianshu.com\/p\/dca73cbb87a6<\/a><br \/>\n<a href=\"https:\/\/cloud.tencent.com\/developer\/article\/1793593\">https:\/\/cloud.tencent.com\/developer\/article\/1793593<\/a><\/p>\n<h2>5.2. \u534f\u7a0b\uff1f<\/h2>\n<p>\u8f7b\u91cf\u7684\u7528\u6237\u6001\u7ebf\u7a0b\uff08\u4e0d\u50cf\u8fdb\u7a0b\/\u7ebf\u7a0b\u53ef\u80fd\u6709\u5185\u6838\u6001\uff09\uff0c\u4e0d\u662f\u7531CPU\u8c03\u5ea6\u800c\u662f\u7531\u7528\u6237\u7a0b\u5e8f\u5728\u4e00\u4e2a\u7ebf\u7a0b\u5185\u81ea\u884c\u8c03\u5ea6\u3002\u4e00\u4e2a\u7ebf\u7a0b\u5185\u7684\u591a\u4e2a\u534f\u7a0b\u5206\u65f6\u8fd0\u884c\uff0c\u662f\u5e76\u53d1(concurrency)\u800c\u4e0d\u662f\u5e76\u884c(parrallel)\u3002\u5207\u6362\u5f00\u9500\u66f4\u4f4e\u3002OS\u4e0d\u80fd\u611f\u77e5\u534f\u7a0b\u5b58\u5728\uff0c\u4e00\u4e2a\u534f\u7a0b\u963b\u585e\u5219OS\u4f1a\u8ba4\u4e3a\u8be5\u7ebf\u7a0b\u963b\u585e\u800c\u5bfc\u81f4\u8c03\u5ea6\u3002<\/p>\n<h1>6. \u8fdb\u7a0b\u901a\u4fe1\u7684\u65b9\u5f0f\uff08IPC\uff09<\/h1>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u65b9\u5f0f<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">\u4fe1\u53f7Singal<\/td>\n<td style=\"text-align: center;\">\u9700\u8981\u6ce8\u518c\u4fe1\u53f7\u6355\u83b7\u51fd\u6570\u3002\u4f8b\u5982ctrl+C\u7684\u786c\u4ef6\u4e2d\u65adSIGINT\uff0c\u8c03\u8bd5\u65f6\u7684SIGTRAP<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u4fe1\u53f7\u91cfSemaphore<\/td>\n<td style=\"text-align: center;\">PV\u64cd\u4f5c\u3002P\uff1a-1\uff0c\u82e5&gt;=0\u5219\u7ee7\u7eed\uff1b\u5426\u5219\u963b\u585e\u7b49\u5f85\uff1bV\uff1a+1\uff0c\u82e5&lt;= 0\u5219\u5c06\u4e00\u4e2a\u963b\u585e\u7b49\u5f85\u7684\u8fdb\u7a0b\u5524\u9192\u4e3a\u5c31\u7eea\u6001<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u533f\u540d\u7ba1\u9053Pipe<\/td>\n<td style=\"text-align: center;\">\u534a\u53cc\u5de5\uff0c\u5728\u5185\u5b58\u4e2d\u5b58\u5728\uff0c\u53ea\u80fd\u5728\u6709\u4eb2\u7f18\u5173\u7cfb\u7684\u8fdb\u7a0b\u95f4\u901a\u4fe1<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u547d\u540d\u7ba1\u9053FIFO<\/td>\n<td style=\"text-align: center;\">\u534a\u53cc\u5de5\uff0c\u4ee5\u6587\u4ef6\u7684\u65b9\u5f0f\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u5b58\u5728\uff0c\u53ef\u4ee5\u5728\u4efb\u610f\u8fdb\u7a0b\u95f4\u901a\u4fe1<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u5171\u4eab\u5185\u5b58Shared Memory<\/td>\n<td style=\"text-align: center;\">\u53ef\u4ee5\u914d\u5408\u4fe1\u53f7\u91cf\/\u4e92\u65a5\u9501\uff0c\u5f53\u505a\u4e34\u754c\u533a\u6765\u4f7f\u7528\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u6d88\u606f\u961f\u5217Message Queue<\/td>\n<td style=\"text-align: center;\">\u6d88\u606f\u7c7b\u578b\u53ef\u4ee5\u5b9a\u4e49\uff0c\u4e0d\u50cf\u7ba1\u9053\u90a3\u6837\u53ea\u80fd\u8bfb\u5b57\u8282\u6d41\uff1b\u4e5f\u662f\u56e0\u4e3a\u53ef\u4ee5\u5b9a\u4e49\uff0c\u53ef\u4ee5\u9009\u62e9\u6027\u63a5\u53d7\u6d88\u606f\uff0c\u800c\u4e0d\u662f\u7ba1\u9053\u90a3\u6837\u5168\u8bfb\u53d6\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">Socket\u901a\u4fe1<\/td>\n<td style=\"text-align: center;\">\u53ef\u4ee5\u7528\u4e8e\u4e0d\u540c\u4e3b\u673a\u4e0a\u7684\u8fdb\u7a0b\u901a\u4fe1\u3002RPC\u5c5e\u4e8e\u8fd9\u4e00\u7c7b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>7. \u7ebf\u7a0b\u901a\u4fe1\u7684\u65b9\u5f0f<\/h1>\n<p>\u4e13\u6709\u65b9\u5f0f\uff1a\u5168\u5c40\u53d8\u91cf\uff01\u5171\u7528\u6240\u5c5e\u8fdb\u7a0b\u7684.rdata\u6bb5<br \/>\n\u4fe1\u53f7\u91cf\u3001\u4e92\u65a5\u9501\u3002<\/p>\n<h1>8. \u540c\u6b65\u548c\u4e92\u65a5\u7684\u6982\u5ff5<\/h1>\n<p>\u540c\u6b65\uff1a\u591a\u4e2a\u8fdb\/\u7ebf\u7a0b\u6309\u7167\u4e00\u5b9a\u7684\u987a\u5e8f\u6267\u884c<br \/>\n\u4e92\u65a5\uff1a\u540c\u4e00\u65f6\u523b\u53ea\u5141\u8bb8\u4e00\u4e2a\u8bbf\u95ee\u8005\u8bbf\u95ee\u67d0\u4e00\u8d44\u6e90<\/p>\n<h1>9. \u8fdb\/\u7ebf\u7a0b\u540c\u6b65\u7684\u65b9\u5f0f\u4e0e\u5176C++\u4f7f\u7528\u65b9\u5f0f<\/h1>\n<p>\u539f\u5b50\u53d8\u91cf\uff1aC++<code>std::atomic<\/code> <a href=\"https:\/\/cococat.top\/index.php\/2022\/10\/09\/%e3%80%90%e6%96%bd%e5%b7%a5%e4%b8%ad%e3%80%91c%e5%8e%9f%e5%ad%90%e5%8f%98%e9%87%8f%e4%b8%8e%e5%86%85%e5%ad%98%e5%ba%8f%ef%bc%9a%e6%97%a0%e9%94%81%e7%bc%96%e7%a8%8b%e7%9a%84%e5%8e%9f%e7%90%86\/\">\u672c\u535a\u5ba2\u4e0a\u7684\u4ecb\u7ecd<\/a><br \/>\n\u4e92\u65a5\u9501\uff1aC++<code>std::mutex<\/code>\u4ee5\u53ca\u57fa\u4e8e\u57fa\u7840\u4e92\u65a5\u9501\u5f00\u53d1\u7684\u8bfb\u5199\u9501\u3002<br \/>\n\u4fe1\u53f7\u91cf\uff1aLinux \/ Windows API\u4e2d\u7684semaphore<br \/>\n\u6761\u4ef6\u53d8\u91cf\uff1aC++<code>std::condition_variable<\/code>\uff0c\u7b49\u5f85\u6761\u4ef6\u4e3a\u771f\u518d\u88ab\u901a\u77e5\u5524\u9192\u3002<br \/>\n\u4e34\u754c\u533a\uff1aWindows Api\u4e2d<code>CRITICAL_SECTION<\/code>\uff0c\u53ea\u80fd\u7528\u4e8e\u540c\u4e00\u8fdb\u7a0b\u5185\u7684\u7ebf\u7a0b\u540c\u6b65\uff0c\u662f\u7528\u6237\u6001\u7684\u540c\u6b65\u673a\u5236\u3002<\/p>\n<h1>10. \u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b<\/h1>\n<p>\u6ce8\u610f\u70b9\uff1a\u4e00\u4e2a\u4e92\u65a5\u9501\u7528\u4e8e\u63a7\u5236\u7f13\u51b2\u533a\u7684\u5199\u5165\u548c\u8bfb\u51fa\uff0c\u4e24\u4e2a\u4fe1\u53f7\u91cf\u7528\u4e8e\u4ee3\u8868\u7a7a\u95f2\u7f13\u51b2\u533a\u548c\u5f85\u6d88\u8d39\u7f13\u51b2\u533a\u7684\u6570\u91cf\u3002<\/p>\n<pre><code class=\"language-c++\">semaphore mutex=1; \/\/\u4e34\u754c\u533a\u4e92\u65a5\u4fe1\u53f7\u91cf\nsemaphore empty=n;  \/\/\u7a7a\u95f2\u7f13\u51b2\u533a\nsemaphore full=0;  \/\/\u7f13\u51b2\u533a\u521d\u59cb\u5316\u4e3a\u7a7a\nproducer ()\/\/\u751f\u4ea7\u8005\u8fdb\u7a0b\n{     \n    while(1)\n    {\n        produce an item in nextp;  \/\/\u751f\u4ea7\u6570\u636e\n        P(empty);  \/\/\u83b7\u53d6\u7a7a\u7f13\u51b2\u533a\u5355\u5143\n        P(mutex);  \/\/\u8fdb\u5165\u4e34\u754c\u533a.\n        add nextp to buffer;  \/\/\u5c06\u6570\u636e\u653e\u5165\u7f13\u51b2\u533a\n        V(mutex);  \/\/\u79bb\u5f00\u4e34\u754c\u533a,\u91ca\u653e\u4e92\u65a5\u4fe1\u53f7\u91cf\n        V(full);  \/\/\u6ee1\u7f13\u51b2\u533a\u6570\u52a01\n    }\n}\nconsumer () \n{  \/\/\u6d88\u8d39\u8005\u8fdb\u7a0b\n    while(1)\n    {\n        P(full);  \/\/\u83b7\u53d6\u6ee1\u7f13\u51b2\u533a\u5355\u5143\n        P(mutex);  \/\/ \u8fdb\u5165\u4e34\u754c\u533a\n        remove an item from buffer;  \/\/\u4ece\u7f13\u51b2\u533a\u4e2d\u53d6\u51fa\u6570\u636e\n        V (mutex);  \/\/\u79bb\u5f00\u4e34\u754c\u533a\uff0c\u91ca\u653e\u4e92\u65a5\u4fe1\u53f7\u91cf\n        V (empty) ;  \/\/\u7a7a\u7f13\u51b2\u533a\u6570\u52a01\n        consume the item;  \/\/\u6d88\u8d39\u6570\u636e\n    }\n}<\/code><\/pre>\n<h1>11. Linux PCB<\/h1>\n<h2>11.1. \u5305\u542b\u7684\u5185\u5bb9<\/h2>\n<p>linux\u6e90\u7801\u4e2d\u7ed3\u6784\u4f53<code>task_struct<\/code>\uff0c\u5176\u6700\u91cd\u8981\u7684\u6210\u5458\u6709\uff1a<\/p>\n<ul>\n<li>\u8fdb\u7a0b\u53f7<\/li>\n<li>\u8fdb\u7a0b\u72b6\u6001\uff1a\u963b\u585e\/\u8fd0\u884c\u7b49<\/li>\n<li>\u8d44\u6e90\u6e05\u5355\uff1a\u5206\u914d\u7684\u6587\u4ef6\uff08\u53ca\u8bbe\u5907\uff09\u7684fid<\/li>\n<li>\u4e0a\u4e0b\u6587\u6570\u636e\uff1a\u4e2d\u65ad\u65f6\u5c06PC\u3001\u5bc4\u5b58\u5668\u3001\u5806\u6808\u7b49\u6570\u636e\u5b58\u5165\u6b64\u5904\uff0c\u4fdd\u62a4\u73b0\u573a<\/li>\n<li>\u9875\u8868\u6307\u9488<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.cnblogs.com\/yungyu16\/p\/13024626.html\">https:\/\/www.cnblogs.com\/yungyu16\/p\/13024626.html<\/a><\/p>\n<h2>11.2. \u5b58\u653e\u7684\u4f4d\u7f6e<\/h2>\n<p>\u5185\u6838\u7a7a\u95f4<\/p>\n<h1>12. \u8fdb\u7a0b\u7684\u72b6\u6001<\/h1>\n<p>\u8fd0\u884c\u3001\u5c31\u7eea\u3001\u963b\u585e\u3002<\/p>\n<ul>\n<li>\u8fd0\u884c-&gt;\u5c31\u7eea\uff1a\u5206\u914d\u7684\u65f6\u95f4\u7247\u7528\u5b8c<\/li>\n<li>\u5c31\u7eea-&gt;\u8fd0\u884c\uff1aCPU\u8c03\u5ea6<\/li>\n<li>\u8fd0\u884c-&gt;\u963b\u585e\uff1a\u7b49\u5f85\u8d44\u6e90\u5206\u914d<\/li>\n<li>\u963b\u585e-&gt;\u5c31\u7eea\uff1a\u5f97\u5230\u5206\u914d\u7684\u8d44\u6e90<\/li>\n<\/ul>\n<h1>13. \u50f5\u5c38\u8fdb\u7a0b\u548c\u5b64\u513f\u8fdb\u7a0b<\/h1>\n<h2>13.1. \u5b9a\u4e49<\/h2>\n<p>\u50f5\u5c38\u8fdb\u7a0b\uff1a\u5b50\u8fdb\u7a0b\u9000\u51fa\u540e\uff0c\u7236\u8fdb\u7a0b\u672a\u8c03\u7528<code>wait()<\/code>\u6216\u8005<code>waitpid()<\/code>\u83b7\u53d6\u5b50\u8fdb\u7a0b\u4fe1\u606f\uff0c\u5b50\u8fdb\u7a0b\u7684PCB\u672a\u88ab\u91ca\u653e\uff0c\u7559\u5728\u8fdb\u7a0b\u5217\u8868\u4e2d\u5360\u7528\u8fdb\u7a0b\u53f7\u3002<br \/>\n\u5b64\u513f\u8fdb\u7a0b\uff1a\u7236\u8fdb\u7a0b\u5728\u5b50\u8fdb\u7a0b\u8fd0\u884c\u7ed3\u675f\u524d\u5c31\u9000\u51fa\uff0c\u4f1a\u88abinit(pid=1)\u8fdb\u7a0b\u6536\u517b\u5e76\u5728\u8fd0\u884c\u7ed3\u675f\u540e\u91ca\u653e\u8d44\u6e90\u3002<\/p>\n<h2>13.2. \u5982\u4f55\u907f\u514d\u50f5\u5c38\u8fdb\u7a0b\/\u5b64\u513f\u8fdb\u7a0b<\/h2>\n<p>\u9996\u5148\u662f\u5c3d\u53ef\u80fd\u4e0d\u8981\u5fd8\u8bb0<code>wait()<\/code>\u548c<code>waitpid()<\/code>\u3002\u4f46\u662f\u82e5\u672a\u9000\u51fa\u5219<code>wait()<\/code>\u4f1a\u963b\u585e\uff0c<code>waitpid()<\/code>\u5219\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u7acb\u523b\u8fd4\u56de\u3002<br \/>\n\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u6280\u5de7\uff0c\u4f8b\u5982\u4e8c\u6b21<code>fork<\/code>\uff1a\u8ba9\u5b50\u8fdb\u7a0b<code>fork<\/code>\u51fa\u5b59\u8fdb\u7a0b\uff0c\u968f\u540e\u9500\u6bc1\u5b50\u8fdb\u7a0b\uff0c\u8fd9\u6837\u5b59\u8fdb\u7a0b\u53d8\u4e3a\u5b64\u513f\u8fdb\u7a0b\uff0c\u7531init\u63a5\u7ba1\u3002<br \/>\n\u6700\u540e\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7<code>SIGCHILD<\/code>\u901a\u77e5\u5185\u6838\u5bf9\u5b50\u8fdb\u7a0b\u7684\u7ed3\u675f\u4e0d\u5173\u5fc3\uff0c\u7531\u5185\u6838\u56de\u6536\u3002<\/p>\n<h1>14. \u8fdb\u7a0b\u8c03\u5ea6\u65b9\u5f0f<\/h1>\n<ul>\n<li>\u5148\u5230\u5148\u670d\u52a1\uff08First Come First Service, FCFS\uff09\uff1a\u7ef4\u62a4\u961f\u5217\uff0c\u961f\u9996\u6267\u884c<\/li>\n<li>\u77ed\u4f5c\u4e1a\u4f18\u5148\uff08SJF\uff09\uff1a\u9009\u62e9\u9884\u4f30\u8fd0\u884c\u65f6\u95f4\u6700\u77ed\u7684\u6267\u884c\u3002\u5bb9\u6613\u5bfc\u81f4\u957f\u4f5c\u4e1a\u957f\u671f\u4e0d\u88ab\u8c03\u5ea6\u3002<\/li>\n<li>\u65f6\u95f4\u7247\u8f6e\u8f6c\uff08RR\uff09\uff1a\u7ef4\u62a4\u961f\u5217\uff0c\u961f\u9996\u8fd0\u884c\u4e00\u4e2a\u65f6\u95f4\u7247\u540e\u653e\u5165\u961f\u5c3e\u3002<\/li>\n<li>\u4f18\u5148\u7ea7\u8c03\u5ea6\uff1a\u4ece\u961f\u5217\u4e2d\u9009\u62e9\u4f18\u5148\u7ea7\u6700\u9ad8\u7684\u6267\u884c\u3002\u8fd8\u6709\u62a2\u5360\u5f0f\uff0c\u66f4\u9ad8\u4f18\u5148\u7ea7\u5230\u6765\u65f6\u76f4\u63a5\u7ec8\u6b62\u5f53\u524d\u65f6\u95f4\u7247\uff0c\u6267\u884c\u8be5\u66f4\u9ad8\u4f18\u5148\u7ea7\u7684\u8fdb\u7a0b\u3002<\/li>\n<\/ul>\n<h1>15. fork()<\/h1>\n<p>\u5982\u679c\u6210\u529f\u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u7236\u8fdb\u7a0b\u8fd4\u56de\u5b50\u8fdb\u7a0bPID\uff0c\u5b50\u8fdb\u7a0b\u8fd4\u56de0\uff1b\u5982\u679c\u521b\u5efa\u5931\u8d25\uff0c\u8fd4\u56de-1\u3002<br \/>\n<code>fork()<\/code>\u5728\u521b\u5efa\u5b50\u8fdb\u7a0b\u65f6\uff0c\u4f1a\u4f7f\u7528<strong>\u5199\u65f6\u590d\u5236(Copy On Write)\u7b56\u7565<\/strong>\u3002\u5b50\u8fdb\u7a0b\u5728\u521b\u5efa\u65f6\u9700\u8981\u590d\u5236\u7236\u8fdb\u7a0b\u7684.code\u3001.data\u3001\u5806\u6808\u548c\u9875\u8868\uff0c\u4f46\u662f\u8fd9\u91cc\u5e76\u4e0d\u662f\u7acb\u523b\u590d\u5236\u7269\u7406\u9875\uff0c\u800c\u662f\u6682\u65f6\u901a\u8fc7\u865a\u62df\u5185\u5b58\u673a\u5236\u5171\u4eab\u7269\u7406\u9875\u3002\u5f53\u5176\u4e2d\u4e00\u4e2a\u8fdb\u7a0b\u5bf9\u5171\u4eab\u9875\u8fdb\u884c\u5199\u64cd\u4f5c\u65f6\uff0c\u624d\u4f1a\u590d\u5236\u7269\u7406\u9875\uff0c\u5e76\u4e14\u4fee\u6539\u9875\u8868\u3002<\/p>\n<h1>16. \u6b7b\u9501<\/h1>\n<h2>16.1. \u4ea7\u751f\u6761\u4ef6<\/h2>\n<p>\u6b7b\u9501\u662f\u4e24\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u4e92\u76f8\u7b49\u5f85\u5bf9\u65b9\u6240\u6301\u6709\u7684\u8d44\u6e90\u3002\u53d1\u751f\u6761\u4ef6\u662f\uff1a1. \u8d44\u6e90\u4e92\u65a5\uff0c\u53ea\u80fd\u88ab\u4e00\u4e2a\u8bbf\u95ee\u8005\u62e5\u6709\uff1b2. \u5360\u6709\u4e14\u7b49\u5f85\uff1b3. \u53d1\u751f\u4e86\u5faa\u73af\u7b49\u5f85\uff1b4. \u4e0d\u53ef\u62a2\u5360<\/p>\n<h2>16.2. \u6b7b\u9501\u5224\u65ad<\/h2>\n<p>\u5224\u65ad\u6709\u5411\u56fe\u4e2d\u7684\u73af<\/p>\n<h2>16.3. \u6b7b\u9501\u5904\u7406<\/h2>\n<p>\u56de\u9000\u90e8\u5206\u6b7b\u9501\u8fdb\u7a0b\uff1b\u6216\u62a2\u5360\u8d44\u6e90\u3002<\/p>\n<h2>16.4. \u907f\u514d\u65b9\u6cd5<\/h2>\n<p>\u94f6\u884c\u5bb6\u7b97\u6cd5\uff0c\u5bf9\u8fdb\u7a0b\u5206\u914d\u8d44\u6e90\u524d\uff0c\u68c0\u67e5\u4e24\u4e2a\u65b9\u9762\uff1a1. \u5269\u4f59\u8d44\u6e90\u662f\u5426\u80fd\u591f\u6ee1\u8db3\u8fdb\u7a0b\u7684\u9700\u6c42\uff1b2.\u82e5\u5206\u914d\uff0c\u5206\u914d\u540e\u7684\u5269\u4f59\u8d44\u6e90\u662f\u5426\u53ef\u4ee5\u4f7f\u81f3\u5c11\u4e00\u4e2a\u5de5\u4f5c\u4e2d\u7684\u8fdb\u7a0b\u6267\u884c\u5b8c\u6bd5\u3002<\/p>\n<h1>17. IO\u6a21\u578b\u548cIO\u591a\u8def\u590d\u7528<\/h1>\n<h2>17.1. Linux IO\u6a21\u578b\u5206\u7c7b<\/h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">IO\u6a21\u578b<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<th style=\"text-align: center;\">\u9002\u7528\u573a\u666f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">\u963b\u585eIO(Blocking IO)<\/td>\n<td style=\"text-align: center;\">\u8c03\u7528<code>recvfrom<\/code>\u540e\u963b\u585e\uff0c\u7b49\u5f85\u6570\u636e\u5230\u8fbe\u5185\u6838\u3001\u5e76\u4ece\u5185\u6838\u62f7\u8d1d\u5230\u7528\u6237\u7a7a\u95f4\u540e\u8fd4\u56de<\/td>\n<td style=\"text-align: center;\">\u8fde\u63a5\u5c11\u4e14\u56fa\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u975e\u963b\u585eIO(Non-blocking IO)<\/td>\n<td style=\"text-align: center;\">\u8c03\u7528<code>recvfrom<\/code>\u540e\uff0c\u82e5\u5185\u6838\u672a\u51c6\u5907\u597d\u6570\u636e\uff0c\u5219\u7acb\u523b\u8fd4\u56de\uff1b\u82e5\u5185\u6838\u5df2\u51c6\u5907\u597d\u6570\u636e\uff0c\u5219\u963b\u585e\u7b49\u5f85\u5185\u6838\u62f7\u8d1d\u6570\u636e\u5230\u7528\u6237\u7a7a\u95f4<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u4fe1\u53f7\u9a71\u52a8IO<\/td>\n<td style=\"text-align: center;\">\u5728\u7528\u6237\u6001\u7a0b\u5e8f\u6ce8\u518c<code>SIGIO<\/code>\u4fe1\u53f7\u5904\u7406\u51fd\u6570\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5728\u6570\u636e\u5230\u8fbe\u5185\u6838\u7f13\u51b2\u533a\u540e\u4ee5\u4fe1\u53f7\u7684\u65b9\u5f0f\u901a\u77e5\u7528\u6237\uff0c\u5728\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u4e2d\u8c03\u7528<code>recvfrom<\/code>\u5c06\u6570\u636e\u4ece\u5185\u6838\u62f7\u8d1d\u5230\u7528\u6237\u7a7a\u95f4<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">IO\u591a\u8def\u590d\u7528(IO Multiplexing)<\/td>\n<td style=\"text-align: center;\">\u5355\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u76d1\u542c\u591a\u4e2asocket\u3002\u5206select, poll, epoll\uff0c\u673a\u5236\u6709\u6240\u4e0d\u540c\uff0c\u4f46\u662f\u5728\u5185\u6838\u62f7\u8d1d\u6570\u636e\u5230\u7528\u6237\u7a7a\u95f4\u65f6\u90fd\u9700\u8981\u963b\u585e\u3002<\/td>\n<td style=\"text-align: center;\">\uff08NIO+IO\u591a\u8def\u590d\u7528\uff09\u8fde\u63a5\u591a\u4e14\u64cd\u4f5c\u8f7b\u91cf\u7ea7\uff0c\u4f8b\u5982\u804a\u5929\u670d\u52a1\u5668\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u5f02\u6b65IO(Asynchronous IO)<\/td>\n<td style=\"text-align: center;\">\u6ce8\u518c\u4fe1\u53f7\u5904\u7406\u51fd\u6570\uff0c\u5b8c\u5168\u4e0d\u963b\u585e\u3002\u64cd\u4f5c\u7cfb\u7edf\u5b8c\u6210\u5230\u7528\u6237\u7a7a\u95f4\u7684\u6570\u636e\u62f7\u8d1d\u540e\u7528\u4fe1\u53f7\u65b9\u5f0f\u901a\u77e5\u8fdb\u7a0b\u5904\u7406\u3002<\/td>\n<td style=\"text-align: center;\">\u8fde\u63a5\u591a\u4e14\u64cd\u4f5c\u91cd\u91cf\u7ea7\uff0c\u4f8b\u5982\u76f8\u518c\u670d\u52a1\u5668<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>17.2. IO\u591a\u8def\u590d\u7528<\/h2>\n<ul>\n<li>select<br \/>\n\u8c03\u7528select\u540e\u963b\u585e\u3002select\u4e2d\u5305\u542b\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u7ec4\uff0c\u6700\u591a1024\u4e2a\u3002select\u8fd4\u56de\u540e\u8fd8\u9700\u8981\u904d\u5386\u8fd9\u4e2a\u6570\u7ec4\u5224\u65ad\u54ea\u4e9bsocket\u6709\u6570\u636e\uff0c\u518d\u8c03\u7528<code>recvfrom<\/code>\u4ece\u5185\u6838\u62f7\u8d1d\u6570\u636e\u5230\u7528\u6237\u63a7\u4ef6\uff0c\u6b64\u8fc7\u7a0b\u963b\u585e\u3002<\/li>\n<li>poll<br \/>\n\u89e3\u51b3\u4e86select\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u91cf\u4e0a\u9650\u95ee\u9898\uff0c\u5176\u4ed6\u57fa\u672c\u4e00\u81f4<\/li>\n<li>epoll<br \/>\n<code>epoll_create<\/code>\u521b\u5efa\u53e5\u67c4\uff0c<code>epoll_ctl<\/code>\u5411\u5185\u6838\u6ce8\u518c\u76d1\u542c\u7684\u7aef\u53e3\uff0c\u7136\u540e<code>epoll_wait<\/code>\u963b\u585e\u7b49\u5f85\uff0c\u8fd4\u56de\u540e\u518d<code>recvfrom<\/code>\u3002<code>epoll_wait<\/code>\u53ea\u4f1a\u8fd4\u56de\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u6545\u4e0d\u9700\u8981\u904d\u5386\uff0c\u6548\u7387\u66f4\u9ad8<\/li>\n<\/ul>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000003063859#articleHeader14\">https:\/\/segmentfault.com\/a\/1190000003063859#articleHeader14<\/a><br \/>\n<a href=\"https:\/\/www.jianshu.com\/p\/5ab57182af89\">https:\/\/www.jianshu.com\/p\/5ab57182af89<\/a><\/p>\n<h1>18. \u4e2d\u65ad\u548c\u5f02\u5e38<\/h1>\n<p>\u4e2d\u65ad\u5305\u62ec\u4e86\u5f02\u5e38\u3002\u4e2d\u65ad\u5206\u4e3a2\u7c7b\uff1a<\/p>\n<ul>\n<li>\u5916\u4e2d\u65ad<br \/>\nI\/O\u5b8c\u6210\u4e2d\u65ad\uff0cCtrl+C\u786c\u4ef6\u4e2d\u65ad<\/li>\n<li>\u5f02\u5e38<br \/>\nCPU\u8fd0\u7b97\u65f6\u5185\u90e8\u5f02\u5e38\uff0c\u4f8b\u5982\u8d8a\u754c\u3001\u96640\u3001\u7f3a\u9875\u4e2d\u65ad\u3001\u8c03\u8bd5\u65f6\u7684\u7279\u6b8a\u6c47\u7f16\u4ee3\u7801INT3<\/li>\n<\/ul>\n<h1>19. \u78c1\u76d8\uff08\u79fb\u81c2\u8c03\u5ea6\uff09\u8c03\u5ea6\u7b97\u6cd5<\/h1>\n<p>a. FCFS\uff1a\u6309\u8bf7\u6c42\u5230\u8fbe\u7684\u987a\u5e8f\u6267\u884c<br \/>\nb. \u6700\u77ed\u5bfb\u627e\u65f6\u95f4\u4f18\u5148\uff1a\u6c38\u8fdc\u9009\u62e9\u8ddd\u79bb\u76ee\u524d\u67f1\u9762\u6700\u8fd1\u7684<br \/>\nc. \u7535\u68af\u8c03\u5ea6\u7b97\u6cd5\uff1a\u6c38\u8fdc\u9009\u62e9\u5728\u5f53\u524d\u79fb\u52a8\u65b9\u5411\u4e0a\u6700\u8fd1\u7684\uff0c\u82e5\u5f53\u524d\u65b9\u5411\u4e0a\u65e0\u65b0\u7684\u8bf7\u6c42\uff0c\u5219\u53cd\u5411\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u54cd\u5e94\u6027\u80fd\u53ef\u80fd\u4e0d\u5982\u6700\u77ed\u5bfb\u627e\u65f6\u95f4\u7b97\u6cd5\uff0c\u4f46\u662f\u5176\u7a33\u5b9a\u6027\u5927\u5927\u5f3a\u4e8e\u524d\u8005\uff0c\u5f88\u5c11\u51fa\u73b0\u201c\u997f\u6b7b\u201d\u7684\u73b0\u8c61<br \/>\n<a href=\"https:\/\/blog.csdn.net\/juliefish\/article\/details\/4766787\">https:\/\/blog.csdn.net\/juliefish\/article\/details\/4766787<\/a><\/p>\n<h1>20. \u6587\u4ef6\u7cfb\u7edf\u6781\u7b80\u63cf\u8ff0<\/h1>\n<h2>20.1. Ext2 \/ Ext3 \u6587\u4ef6\u7cfb\u7edf<\/h2>\n<p>\u7d22\u5f15\u8282\u70b9(index node, inode)\u5b58\u653e\u6587\u4ef6\u7c7b\u578b\u3001\u6743\u9650\u7b49\u5143\u6570\u636e\uff0c\u5e76\u4fdd\u5b58\u6307\u5411\u8be5\u6587\u4ef6\u7684\u7d22\u5f15\u5757\u6216\u662f\u7269\u7406\u78c1\u76d8\u5757\u7684\u6307\u9488\u3002<br \/>\n\u5bf9\u4e8e\u5f88\u5c0f\u7684\u6587\u4ef6\uff0c\u4e0d\u9700\u8981\u5f15\u5165\u7d22\u5f15\u5757\uff0c\u6b64\u65f6inode\u4e2d\u76f4\u63a5\u5b58\u653e\u78c1\u76d8\u5757\u6307\u9488\uff1b\u800c\u5bf9\u4e8e\u8f83\u5927\u7684\u6587\u4ef6\uff0c\u9700\u8981\u5f15\u5165\u7d22\u5f15\u5757\u3002\u7d22\u5f15\u5757\u91cc\u5305\u542b\u5b9e\u9645\u5b58\u653e\u8be5\u6587\u4ef6\u7684\u78c1\u76d8\u5757\u6307\u9488\uff0c\u5bf9\u4e8e\u5f88\u5927\u7684\u6587\u4ef6\u5219\u9700\u8981\u8fdb\u884c\u591a\u7ea7\u7d22\u5f15\u3002<br \/>\n\u6587\u4ef6\u6240\u5360\u7528\u7684\u78c1\u76d8\u5757\u662f\u968f\u673a\u5206\u5e03\u7684\uff0c\u8fd9\u6837\u53ef\u4ee5\u6700\u5927\u5316\u5229\u7528\u6587\u4ef6\u5220\u9664\u540e\u7684\u788e\u7247\u3002<\/p>\n<h2>20.2. Ext4\u7684\u91cd\u8981\u6539\u8fdb<\/h2>\n<ul>\n<li>extents:<br \/>\nExt2\/3\u7684\u7d22\u5f15\u673a\u5236\u5728\u63cf\u8ff0\u5927\u6587\u4ef6\u65f6\uff0c\u9700\u8981\u5f15\u5165\u591a\u5c42\u7d22\u5f15\uff0c\u5bfc\u81f4\u8bbf\u95ee\u6027\u80fd\u964d\u4f4e\u3002Ext4\u5f15\u5165\u4e86\u533a\u5757(extent)\u6982\u5ff5\uff0c\u662f\u4e00\u4e2a\u8fde\u7eed\u7684\u7269\u7406\u5757\uff0c\u53ef\u4ee5\u4e00\u6b21\u6027\u5206\u914d\u548c\u5bfb\u5740\uff1b\u4e14\u4e00\u4e2aextent\u7684\u5927\u5c0f\u53ef\u8fbe128MB\uff0c\u663e\u8457\u9ad8\u4e8e\u78c1\u76d8\u5757\u76844KB\uff0c\u6545\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u7d22\u5f15\u5c42\u6570\u548c\u4e2a\u6570\u3002<\/li>\n<\/ul>\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/183238194\">https:\/\/zhuanlan.zhihu.com\/p\/183238194<\/a><br \/>\n<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/44267768\">https:\/\/zhuanlan.zhihu.com\/p\/44267768<\/a><\/p>\n<h1>21. \u8f6f\u786c\u94fe\u63a5<\/h1>\n<ul>\n<li>\u8f6f\u94fe\u63a5: \u76f8\u5f53\u4e8e\u4fdd\u5b58\u94fe\u63a5\u5bf9\u8c61\u7684\u7edd\u5bf9\u8def\u5f84\u3002\u8f6f\u94fe\u63a5\u6587\u4ef6\u6709\u81ea\u5df1\u7684inode\uff0c\u6545\u94fe\u63a5\u5bf9\u8c61\u7684inode\u5f15\u7528\u8ba1\u6570\u4e0d\u589e\u52a0\u3002<\/li>\n<li>\u786c\u94fe\u63a5\uff1a\u4e0e\u94fe\u63a5\u5bf9\u8c61\u62e5\u6709\u540c\u6837\u7684inode\uff0c\u6b64\u65f6\u8be5inode\u5f15\u7528\u8ba1\u6570+1\u3002<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.jianshu.com\/p\/dde6a01c4094\">https:\/\/www.jianshu.com\/p\/dde6a01c4094<\/a><\/p>\n<h1>22. LINUX\u7cfb\u7edf\u542f\u52a8<\/h1>\n<ol>\n<li>\u5f00\u673a\u786c\u4ef6\u81ea\u68c0<\/li>\n<li>\u52a0\u8f7dBIOS<\/li>\n<li>BIOS\u63a5\u7ba1\u63a7\u5236\uff0c\u786e\u5b9a\u542f\u52a8\u8bbe\u5907\uff0c\u4ece\u4e2d\u8bfb\u53d6Boot Loader\u5230\u4e3b\u5b58<br \/>\n\u9898\u5916\u8bdd\uff1a\u76ee\u524d\u5e38\u7528\u7684BL GRUB2\u7684\u5168\u79f0\u662fGRand Unified Bootloader,Version 2<\/li>\n<li>Boot Loader\u63a5\u7ba1\u63a7\u5236\uff0c\u4ece\u78c1\u76d8\u8bfb\u53d6\u5185\u6838\u5230\u4e3b\u5b58<\/li>\n<li>\u5185\u6838\u63a5\u7ba1\u63a7\u5236\uff0c\u542f\u52a8\u7b2c\u4e00\u4e2a\u7528\u6237\u8fdb\u7a0binit<br \/>\n<a href=\"https:\/\/cloud.tencent.com\/developer\/article\/1114481\">https:\/\/cloud.tencent.com\/developer\/article\/1114481<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>1. Linux \u8fdb\u7a0b\u7a7a\u95f4 \uff08\u4ece\u4e0a\u5230\u4e0b\u662f\u4ece\u9ad8\u5730\u5740\u5230\u4f4e\u5730\u5740\uff09\uff1a \u6bb5\u540d \u63cf\u8ff0 \u5185\u6838(kernel space) \u2026 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[29],"class_list":["post-256","post","type-post","status-publish","format-standard","hentry","category-3","tag-29"],"_links":{"self":[{"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/posts\/256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":0,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"wp:attachment":[{"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}