{"id":46873,"date":"2023-12-11T15:10:05","date_gmt":"2023-12-11T07:10:05","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=46873"},"modified":"2023-12-11T15:10:05","modified_gmt":"2023-12-11T07:10:05","slug":"c%e7%b3%bb%e7%bb%9f%e8%b0%83%e7%94%a8%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%8c%e4%bd%a0%e7%94%a8%e8%bf%87%e5%93%aa%e4%ba%9b%e7%b3%bb%e7%bb%9f%e8%b0%83%e7%94%a8-3","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/c%e7%b3%bb%e7%bb%9f%e8%b0%83%e7%94%a8%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%8c%e4%bd%a0%e7%94%a8%e8%bf%87%e5%93%aa%e4%ba%9b%e7%b3%bb%e7%bb%9f%e8%b0%83%e7%94%a8-3\/","title":{"rendered":"C++\u7cfb\u7edf\u8c03\u7528\u662f\u4ec0\u4e48\uff0c\u4f60\u7528\u8fc7\u54ea\u4e9b\u7cfb\u7edf\u8c03\u7528"},"content":{"rendered":"<p>&#8220;`&#8221;                    \u53c2\u8003\u56de\u7b54\uff1a<\/p>\n<p>1\uff09\u6982\u5ff5\uff1a<\/p>\n<p>\u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u7cfb\u7edf\u8c03\u7528\uff08\u82f1\u8bed\uff1asystem call\uff09\uff0c\u53c8\u79f0\u4e3a\u7cfb\u7edf\u547c\u53eb\uff0c\u6307\u8fd0\u884c\u5728\u4f7f\u7528\u8005\u7a7a\u95f4\u7684\u7a0b\u5e8f\u5411\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u8bf7\u6c42\u9700\u8981\u66f4\u9ad8\u6743\u9650\u8fd0\u884c\u7684\u670d\u52a1\u3002\u7cfb\u7edf\u8c03\u7528\u63d0\u4f9b\u4e86\u7528\u6237\u7a0b\u5e8f\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u95f4\u7684\u63a5\u53e3\uff08\u5373\u7cfb\u7edf\u8c03\u7528\u662f\u7528\u6237\u7a0b\u5e8f\u548c\u5185\u6838\u4ea4\u4e92\u7684\u63a5\u53e3\uff09\u3002<\/p>\n<p>\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u72b6\u6001\u5206\u4e3a\u7ba1\u6001\uff08\u6838\u5fc3\u6001\uff09\u548c\u76ee\u6001\uff08\u7528\u6237\u6001\uff09\u3002\u5927\u591a\u6570\u7cfb\u7edf\u4ea4\u4e92\u5f0f\u64cd\u4f5c\u9700\u6c42\u5728\u5185\u6838\u6001\u6267\u884c\u3002\u5982\u8bbe\u5907IO\u64cd\u4f5c\u6216\u8005\u8fdb\u7a0b\u95f4\u901a\u4fe1\u3002\u7279\u6743\u6307\u4ee4\uff1a\u4e00\u7c7b\u53ea\u80fd\u5728\u6838\u5fc3\u6001\u4e0b\u8fd0\u884c\u800c\u4e0d\u80fd\u5728\u7528\u6237\u6001\u4e0b\u8fd0\u884c\u7684\u7279\u6b8a\u6307\u4ee4\u3002\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u7279\u6743\u6307\u4ee4\u4f1a\u6709\u6240\u5dee\u5f02\uff0c\u4f46\u662f\u4e00\u822c\u6765\u8bf4\u4e3b\u8981\u662f\u548c\u786c\u4ef6\u76f8\u5173\u7684\u4e00\u4e9b\u6307\u4ee4\u3002\u7528\u6237\u7a0b\u5e8f\u53ea\u5728\u7528\u6237\u6001\u4e0b\u8fd0\u884c\uff0c\u6709\u65f6\u9700\u8981\u8bbf\u95ee\u7cfb\u7edf\u6838\u5fc3\u529f\u80fd\uff0c\u8fd9\u65f6\u901a\u8fc7\u7cfb\u7edf\u8c03\u7528\u63a5\u53e3\u4f7f\u7528\u7cfb\u7edf\u8c03\u7528\u3002<\/p>\n<p>\u5e94\u7528\u7a0b\u5e8f\u6709\u65f6\u4f1a\u9700\u8981\u4e00\u4e9b\u5371\u9669\u7684\u3001\u6743\u9650\u5f88\u9ad8\u7684\u6307\u4ee4\uff0c\u5982\u679c\u628a\u8fd9\u4e9b\u6743\u9650\u653e\u5fc3\u5730\u4ea4\u7ed9\u7528\u6237\u7a0b\u5e8f\u662f\u5f88\u5371\u9669\u7684(\u6bd4\u5982\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u80fd\u4fee\u6539\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u533a\uff0c\u5bfc\u81f4\u5176\u4e0d\u80fd\u8fd0\u884c)\uff0c\u4f46\u662f\u53c8\u4e0d\u80fd\u5b8c\u5168\u4e0d\u7ed9\u8fd9\u4e9b\u6743\u9650\u3002\u4e8e\u662f\u6709\u4e86\u7cfb\u7edf\u8c03\u7528\uff0c\u5371\u9669\u7684\u6307\u4ee4\u88ab\u5305\u88c5\u6210\u7cfb\u7edf\u8c03\u7528\uff0c\u7528\u6237\u7a0b\u5e8f\u53ea\u80fd\u8c03\u7528\u800c\u65e0\u6743\u81ea\u5df1\u8fd0\u884c\u90a3\u4e9b\u5371\u9669\u7684\u6307\u4ee4\u3002\u53e6\u5916\uff0c\u8ba1\u7b97\u673a\u786c\u4ef6\u7684\u8d44\u6e90\u662f\u6709\u9650\u7684\uff0c\u4e3a\u4e86\u66f4\u597d\u7684\u7ba1\u7406\u8fd9\u4e9b\u8d44\u6e90\uff0c\u6240\u6709\u7684\u8d44\u6e90\u90fd\u7531\u64cd\u4f5c\u7cfb\u7edf\u63a7\u5236\uff0c\u8fdb\u7a0b\u53ea\u80fd\u5411\u64cd\u4f5c\u7cfb\u7edf\u8bf7\u6c42\u8fd9\u4e9b\u8d44\u6e90\u3002\u64cd\u4f5c\u7cfb\u7edf\u662f\u8fd9\u4e9b\u8d44\u6e90\u7684\u552f\u4e00\u5165\u53e3\uff0c\u8fd9\u4e2a\u5165\u53e3\u5c31\u662f\u7cfb\u7edf\u8c03\u7528\u3002<\/p>\n<p>2\uff09\u7cfb\u7edf\u8c03\u7528\u4e3e\u4f8b\uff1a<\/p>\n<p>\u5bf9\u6587\u4ef6\u8fdb\u884c\u5199\u64cd\u4f5c\uff0c\u7a0b\u5e8f\u5411\u6253\u5f00\u7684\u6587\u4ef6\u5199\u5165\u5b57\u7b26\u4e32\u201chello world\u201d\uff0copen\u548cwrite\u90fd\u662f\u7cfb\u7edf\u8c03\u7528\u3002\u5982\u4e0b\uff1a<\/p>\n<p>&lt;pre&gt;&lt;code class=&quot;&quot;language-c++&quot;&quot; lang=&quot;&quot;c++&quot;&quot;&gt;#include&lt;stdio.h&gt;<br \/>\n#include&lt;stdlib.h&gt;<br \/>\n#include&lt;string.h&gt;<br \/>\n#include&lt;errno.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\n#include&lt;sys\/types.h&gt;<br \/>\n#include&lt;sys\/stat.h&gt;<br \/>\n#include&lt;fcntl.h&gt;<br \/>\nint main(int argc, char *argv[])<br \/>\n{<br \/>\n    if (argc&lt;2)<br \/>\n        return 0;<br \/>\n    \/\/\u7528\u8bfb\u5199\u8ffd\u52a0\u65b9\u5f0f\u6253\u5f00\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684\u6587\u4ef6<br \/>\n    int fd = open(argv[1], O_RDWR | O_APPEND);<br \/>\n    if (fd == -1)<br \/>\n    {<br \/>\n        printf(&quot;&quot;error is %s\\n&quot;&quot;, strerror(errno));<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        \/\/\u6253\u5370\u6587\u4ef6\u63cf\u8ff0\u7b26\u53f7<br \/>\n        printf(&quot;&quot;success fd = %d\\n&quot;&quot;, fd);<br \/>\n        char buf[100];<br \/>\n        memset(buf, 0, sizeof(buf));<br \/>\n        strcpy(buf, &quot;&quot;hello world\\n&quot;&quot;);<br \/>\n        write(fd, buf, strlen(buf));<br \/>\n        close(fd);<br \/>\n    }<br \/>\n    return 0;<br \/>\n}<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u8fd8\u6709\u5199\u6570\u636ewrite\uff0c\u521b\u5efa\u8fdb\u7a0bfork\uff0cvfork\u7b49\u90fd\u662f\u7cfb\u7edf\u8c03\u7528\u3002<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u53c2\u8003\u56de\u7b54\uff1a 1\uff09\u6982\u5ff5\uff1a \u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u7cfb\u7edf\u8c03\u7528\uff08\u82f1\u8bed\uff1asystem call\uff09\uff0c [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-46873","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/46873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=46873"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/46873\/revisions"}],"predecessor-version":[{"id":46874,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/46873\/revisions\/46874"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=46873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=46873"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=46873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}