{"id":169,"date":"2025-10-18T17:48:45","date_gmt":"2025-10-18T09:48:45","guid":{"rendered":"http:\/\/47.99.178.170\/?p=169"},"modified":"2025-10-18T18:26:15","modified_gmt":"2025-10-18T10:26:15","slug":"%e3%80%90%e6%93%8d%e4%bd%9c%e7%b3%bb%e7%bb%9f%e3%80%91%e3%80%90linux%e3%80%91%e6%96%87%e4%bb%b6%e6%8f%8f%e8%bf%b0%e7%ac%a6%e3%80%81%e6%96%87%e4%bb%b6%e5%8f%a5%e6%9f%84","status":"publish","type":"post","link":"https:\/\/www.garfield-blog.top\/?p=169","title":{"rendered":"\u3010\u64cd\u4f5c\u7cfb\u7edf\u3011\u3010Linux\u3011\u6587\u4ef6\u63cf\u8ff0\u7b26\u3001\u6587\u4ef6\u53e5\u67c4"},"content":{"rendered":"\n<p>\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u53e5\u67c4\uff0c\u6807\u51c6\u8f93\u5165\uff0c\u6807\u51c6\u8f93\u51fa\uff0c\u6807\u51c6\u9519\u8bef\u8fd9\u4e9b\u5176\u5b9e\u662f\u76f8\u540c\u7684\u4e1c\u897f<\/p>\n\n\n\n<p>\u53e5\u67c4\u662f\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u4e00\u4e2a\u522b\u540d\uff0c\u6807\u51c6\u8f93\u5165\u3001\u8f93\u51fa\u3001\u9519\u8bef\u662f\u4e09\u4e2a\u7279\u6b8a\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6587\u4ef6\u63cf\u8ff0\u7b26<\/h2>\n\n\n\n<p>\u6587\u4ef6\u63cf\u8ff0\u7b26\u662f\u8ba1\u7b97\u673a\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7528\u4e8e\u6807\u8bc6\u548c\u8bbf\u95ee\u6253\u5f00\u7684\u6587\u4ef6\u6216\u8bbe\u5907\u7684\u6574\u6570\u503c\u3002\u5b83\u662f\u64cd\u4f5c\u7cfb\u7edf\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u7ef4\u62a4\u7684\u4e00\u79cd\u8868\u683c\u6570\u636e\u7ed3\u6784\u7684\u7d22\u5f15\uff0c\u7528\u4e8e\u8ddf\u8e2a\u6587\u4ef6\u6216\u8bbe\u5907\u7684\u72b6\u6001\u548c\u5c5e\u6027<\/p>\n\n\n\n<p>\u5728<code>Linux<\/code>\u7cfb\u5217\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u7531\u4e8e<code>Linux<\/code>\u7684\u8bbe\u8ba1\u601d\u60f3\u4fbf\u662f\u628a\u4e00\u5207\u8bbe\u5907\u90fd\u89c6\u4f5c\u6587\u4ef6\u3002\u5f53\u7a0b\u5e8f\u6253\u5f00\u4e00\u4e2a\u73b0\u6709\u6587\u4ef6\u6216\u8005\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\u65f6\uff0c\u5185\u6838\u5411\u8fdb\u7a0b\u8fd4\u56de\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u3002\u6587\u4ef6\u63cf\u8ff0\u7b26\u5728\u5f62\u5f0f\u4e0a\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u3002\u5b9e\u9645\u4e0a\uff0c\u5b83\u662f\u4e00\u4e2a\u7d22\u5f15\u503c\uff0c\u6307\u5411\u5185\u6838\u4e3a\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u6240\u7ef4\u62a4\u7684\u8be5\u8fdb\u7a0b\u6253\u5f00\u6587\u4ef6\u7684\u8bb0\u5f55\u8868\u3002<\/p>\n\n\n\n<p>\u5728<code>Linux<\/code>\u5185\u6838\u4e2d\u4f1a\u7ef4\u62a4\u4e00\u4e2a<code>struct task_struct<\/code>\u7c7b\u578b\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u5bf9\u5e94\u6570\u7ec4\u4e2d\u7684\u4e00\u4e2a\u5143\u7d20<\/p>\n\n\n\n<p>\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u672c\u8d28\u662f\u4e00\u4e2a\u6570\u7ec4\u4e0b\u6807\uff0c\u5176\u4e2d<code>struct file * filp[NR_OPEN]<\/code>\u5143\u7d20\u7684\u6570\u7ec4\u4e0b\u6807<code>NR_OPEN<\/code>\u5c31\u662f\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5728<code>Linux 0.11<\/code>\u7248\u672c\u4e2d\u8fd9\u4e2a\u503c\u6700\u5927\u4e3a<code>20<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4ee5Linux 0.11\u4e3a\u4f8bstruct task_struct\u5185\u5bb9\u5982\u4e0b<br>\u200b<br>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\">\u6807\u51c6\u8f93\u5165\u3001\u8f93\u51fa\u3001\u9519\u8bef<\/h2>\n\n\n\n<p>\u6807\u51c6\u8f93\u5165\u3001\u8f93\u51fa\u3001\u9519\u8bef\u662f\u4e09\u4e2a\u7279\u6b8a\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<\/p>\n\n\n\n<p>\u6587\u4ef6\u63cf\u8ff0\u7b26\u5728\u5f62\u5f0f\u4e0a\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c\u6807\u51c6\u8f93\u5165\u3001\u8f93\u51fa\u3001\u9519\u8bef\u5219\u5206\u522b\u5bf9\u5e940\u30011\u30012<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u6574\u6570\u503c<\/th><th>\u540d\u79f0<\/th><th><strong>&lt;<\/strong>unistd.h<strong>&gt;<\/strong>\u7b26\u53f7\u5e38\u91cf<\/th><th>&lt;stdio.h&gt;\u6587\u4ef6\u6d41<\/th><\/tr><\/thead><tbody><tr><td>0<\/td><td>Standard input<\/td><td>STDIN_FILENO<\/td><td>stdin<\/td><\/tr><tr><td>1<\/td><td>Standard output<\/td><td>STDOUT_FILENO<\/td><td>stdout<\/td><\/tr><tr><td>2<\/td><td>Standard error<\/td><td>STDERR_FILENO<\/td><td>stderr<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5728<code>stdio.h<\/code>\u6587\u4ef6\u4e2d\u7684\u63cf\u8ff0\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* Standard streams.  *\/<br>extern FILE *stdin; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/* Standard input stream.  *\/<br>extern FILE *stdout; &nbsp; &nbsp; &nbsp; &nbsp;\/* Standard output stream.  *\/<br>extern FILE *stderr; &nbsp; &nbsp; &nbsp; &nbsp;\/* Standard error output stream.  *\/<br>\/* C89\/C99 say they're macros.  Make them happy.  *\/<br>#define stdin stdin<br>#define stdout stdout<br>#define stderr stderr<\/code><\/pre>\n\n\n\n<p>\u5728<code>unistd.h<\/code>\u6587\u4ef6\u4e2d\u63cf\u8ff0\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* Standard file descriptors.  *\/<br>#define &nbsp;  STDIN_FILENO &nbsp;  0 &nbsp; &nbsp;\/* Standard input.  *\/<br>#define &nbsp;  STDOUT_FILENO &nbsp;  1 &nbsp; &nbsp;\/* Standard output.  *\/<br>#define &nbsp;  STDERR_FILENO &nbsp;  2 &nbsp; &nbsp;\/* Standard error output.  *\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6587\u4ef6\u53e5\u67c4<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">FILE\u53e5\u67c4<\/h3>\n\n\n\n<p>\u5bf9\u4e8e<code>C\/C++<\/code>\u6765\u8bf4\u53ef\u4ee5\u4f7f\u7528<code>FILE<\/code>\u7ed3\u6784\u4f53\u6307\u9488\u64cd\u4f5c\u6587\u4ef6\u53e5\u67c4\uff0c\u7531\u4e8e<code>FILE<\/code>\u7ed3\u6784\u4f53\u901a\u5e38\u88ab\u8ba4\u4e3a\u662f\u4e00\u4e2a\u4e0d\u900f\u660e\u7c7b\u578b\uff0c\u610f\u5473\u7740\u5176\u5185\u90e8\u7ec6\u8282\u88ab\u9690\u85cf\u8d77\u6765\uff0c\u7528\u6237\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u3002FILE\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u548c\u5b9e\u73b0\u7ec6\u8282\u901a\u5e38\u7531C\u5e93\u63d0\u4f9b\u3002\u5728\u5927\u591a\u6570C\u5e93\u4e2d\uff0c\u5305\u62ec<code>GNU C\u5e93\uff08glibc\uff09<\/code>\uff0c<code>FILE<\/code>\u7ed3\u6784\u4f53\u4ec5\u5728\u6807\u51c6\u5934\u6587\u4ef6<code>stdio.h<\/code>\u4e2d\u8fdb\u884c\u4e86\u58f0\u660e\uff0c\u800c\u6ca1\u6709\u63d0\u4f9b\u5b9e\u9645\u7684\u5b9a\u4e49\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u67e5\u770b<code>FILE.h<\/code>\u6587\u4ef6\u4ec5\u80fd\u770b\u5230<code>FILE<\/code>\u7ed3\u6784\u4f53\u7684\u58f0\u660e\uff0c\u65e0\u6cd5\u770b\u5230\u5bf9\u5e94\u7684\u7ec6\u8282<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#ifndef __FILE_defined<br>#define __FILE_defined 1<br>\u200b<br>struct _IO_FILE;<br>\u200b<br>\/* The opaque type of streams.  This is the definition used elsewhere.  *\/<br>typedef struct _IO_FILE FILE;<br>\u200b<br>#endif<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7<code>gcc -E<\/code>\u547d\u4ee4\u76f4\u63a5\u5bf9<code>stdio.h<\/code>\u6587\u4ef6\u5c55\u5f00\u53ef\u4ee5\u770b\u5230<code>FILE<\/code>\u7ed3\u6784\u4f53\u7684\u5185\u90e8\u7ec6\u8282<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef struct _IO_FILE FILE;<br>struct _IO_FILE<br>{<br> &nbsp;int _flags;<br> &nbsp;char *_IO_read_ptr;<br> &nbsp;char *_IO_read_end;<br> &nbsp;char *_IO_read_base;<br> &nbsp;char *_IO_write_base;<br> &nbsp;char *_IO_write_ptr;<br> &nbsp;char *_IO_write_end;<br> &nbsp;char *_IO_buf_base;<br> &nbsp;char *_IO_buf_end;<br> &nbsp;char *_IO_save_base;<br> &nbsp;char *_IO_backup_base;<br> &nbsp;char *_IO_save_end;<br>\u200b<br> &nbsp;struct _IO_marker *_markers;<br>\u200b<br> &nbsp;struct _IO_FILE *_chain;<br>\u200b<br> &nbsp;int _fileno;<br> &nbsp;int _flags2;<br> &nbsp;__off_t _old_offset;<br>\u200b<br> &nbsp;unsigned short _cur_column;<br> &nbsp;signed char _vtable_offset;<br> &nbsp;char _shortbuf&#91;1];<br>\u200b<br> &nbsp;_IO_lock_t *_lock;<br>\u200b<br> &nbsp;__off64_t _offset;<br>\u200b<br> &nbsp;struct _IO_codecvt *_codecvt;<br> &nbsp;struct _IO_wide_data *_wide_data;<br> &nbsp;struct _IO_FILE *_freeres_list;<br> &nbsp;void *_freeres_buf;<br> &nbsp;size_t __pad5;<br> &nbsp;int _mode;<br>\u200b<br> &nbsp;char _unused2&#91;15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];<br>};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Socket\u53e5\u67c4<\/h3>\n\n\n\n<p><code>Socket<\/code>\u662f\u7528\u4e8e\u63cf\u8ff0IP\u5730\u5740\u548c\u7aef\u53e3\u7684\u901a\u4fe1\u94fe\u7684\u53e5\u67c4\uff0c\u53ef\u7528\u4e8e\u4e0d\u540c\u4e3b\u673a\u95f4\u7684\u7f51\u7edc\u901a\u4fe1\u4e5f\u53ef\u4ee5\u7528\u4e8e\u4e00\u53f0\u4e3b\u673a\u7684\u8fdb\u7a0b\u95f4\u901a\u4fe1<\/p>\n\n\n\n<p>\u6839\u636e\u901a\u4fe1\u57df\u7684\u4e0d\u540c\u53ef\u4ee5\u5212\u5206\u62102\u79cd\uff1a<strong><code>Unix domain socket<\/code> \u548c <code>Internet domain socket<\/code><\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>Internet domain socket<\/code>\u7528\u4e8e\u5b9e\u73b0\u4e0d\u540c\u4e3b\u673a\u4e0a\u7684\u8fdb\u7a0b\u95f4\u901a\u4fe1<\/li>\n\n\n\n<li><code>Unix domain socket<\/code> \u53c8\u53eb <code>IPC<\/code>(<code>inter-process communication<\/code> \u8fdb\u7a0b\u95f4\u901a\u4fe1) <code>socket<\/code>\uff0c\u7528\u4e8e\u5b9e\u73b0\u540c\u4e00\u4e3b\u673a\u4e0a\u7684\u8fdb\u7a0b\u95f4\u901a\u4fe1<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u53e5\u67c4\uff0c\u6807\u51c6\u8f93\u5165\uff0c\u6807\u51c6\u8f93\u51fa\uff0c\u6807\u51c6\u9519\u8bef\u8fd9\u4e9b\u5176\u5b9e\u662f\u76f8\u540c\u7684\u4e1c\u897f \u53e5\u67c4\u662f\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u4e00\u4e2a\u522b\u540d\uff0c\u6807\u51c6\u8f93\u5165\u3001\u8f93\u51fa [&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-169","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\/169","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=169"}],"version-history":[{"count":2,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":171,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=\/wp\/v2\/posts\/169\/revisions\/171"}],"wp:attachment":[{"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garfield-blog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}