{"id":255588,"date":"2024-05-15T11:21:49","date_gmt":"2024-05-15T03:21:49","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/255588.html"},"modified":"2024-05-15T11:21:57","modified_gmt":"2024-05-15T03:21:57","slug":"%e5%a6%82%e4%bd%95%e4%bb%a3%e7%a0%81%e5%ae%9e%e7%8e%b0%e4%bf%a1%e5%8f%b7%e9%a9%b1%e5%8a%a8i-o%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/255588.html","title":{"rendered":"\u5982\u4f55\u4ee3\u7801\u5b9e\u73b0\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27101048\/24db3393-8d9a-47c2-9c34-82941d5db8e8.webp\" alt=\"\u5982\u4f55\u4ee3\u7801\u5b9e\u73b0\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\" \/><\/p>\n<p><p><strong>\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b<\/strong>\u662f\u4e00\u79cd\u5141\u8bb8\u7a0b\u5e8f\u7ee7\u7eed\u6267\u884c\u76f4\u5230\u67d0\u4e2a\u975e\u963b\u585eI\/O\u64cd\u4f5c\u51c6\u5907\u597d\u518d\u901a\u8fc7\u4fe1\u53f7\u901a\u77e5\u7a0b\u5e8f\u7684I\/O\u5904\u7406\u65b9\u5f0f\u3002\u8fd9\u79cd\u6a21\u578b\u7684\u4f18\u52bf\u5728\u4e8e\u5b83\u53ef\u4ee5\u63d0\u5347\u5e94\u7528\u6027\u80fd\uff0c\u56e0\u4e3a\u7a0b\u5e8f\u4e0d\u5fc5\u5728I\/O\u5b8c\u6210\u4e4b\u524d\u88ab\u963b\u585e\u3002\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u7684\u5b9e\u73b0\u4f9d\u8d56\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u4fe1\u53f7\u5904\u7406\u673a\u5236\uff0c\u5b83\u8981\u6c42\u64cd\u4f5c\u7cfb\u7edf\u5728I\/O\u64cd\u4f5c\u53ef\u8fdb\u884c\u65f6\u53d1\u9001\u4e00\u4e2aSIGIO\u4fe1\u53f7\u7ed9\u5e94\u7528\u7a0b\u5e8f\u3002\u5728UNIX\u7cfb\u5217\u7cfb\u7edf\u4e2d\uff0c\u7a0b\u5e8f\u5458\u901a\u8fc7\u8bbe\u7f6e\u6587\u4ef6\u63cf\u8ff0\u7b26\u4ee5\u4f7f\u7528\u975e\u963b\u585e\u6a21\u5f0f\u5e76\u4e3aSIGIO\u4fe1\u53f7\u6ce8\u518c\u4e00\u4e2a\u5904\u7406\u51fd\u6570\u6765\u5b9e\u73b0\u8fd9\u4e00\u6a21\u578b\u3002<\/p>\n<\/p>\n<p><p>\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u901a\u5e38\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5c06I\/O\u8bbe\u7f6e\u4e3a\u975e\u963b\u585e\u3002<\/li>\n<li>\u4e3aI\/O\u64cd\u4f5c\u6ce8\u518cSIGIO\u4fe1\u53f7\u3002<\/li>\n<li>\u5728\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u4e2d\u8fdb\u884cI\/O\u8bfb\u53d6\u6216\u5199\u5165\u3002<\/li>\n<\/ol>\n<p><p>\u5728\u4f7f\u7528\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u65f6\uff0c<strong>\u6838\u5fc3\u6b65\u9aa4\u662f\u6b63\u786e\u7684\u4fe1\u53f7\u6ce8\u518c\u4ee5\u53ca\u5bf9\u4fe1\u53f7\u7684\u6b63\u786e\u5904\u7406<\/strong>\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e2a\u6a21\u578b\u7684\u5177\u4f53\u5b9e\u65bd\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u8bbe\u7f6e\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3a\u975e\u963b\u585e\u6a21\u5f0f<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u8bbe\u7f6eI\/O\u64cd\u4f5c\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3a\u975e\u963b\u585e\u6a21\u5f0f\u3002\u5728\u4f20\u7edf\u7684I\/O\u64cd\u4f5c\u4e2d\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u662f\u963b\u585e\u6a21\u5f0f\uff0c\u5373\u8c03\u7528\u7ebf\u7a0b\u4f1a\u4e00\u76f4\u7b49\u5f85\u81f3I\/O\u64cd\u4f5c\u5b8c\u6210\u3002\u901a\u8fc7\u975e\u963b\u585e\u6a21\u5f0f\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5728\u6ca1\u6709\u6570\u636e\u53ef\u8bfb\u6216\u8005\u5199\u5165\u65f6\u4e0d\u88ab\u963b\u585e\uff0c\u800c\u662f\u76f4\u63a5\u8fd4\u56de\u4e00\u4e2a\u9519\u8bef\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &lt;fcntl.h&gt;<\/p>\n<p>int setNonBlocking(int fd) {<\/p>\n<p>    int flags;<\/p>\n<p>    flags = fcntl(fd, F_GETFL, 0);<\/p>\n<p>    if (flags == -1) {<\/p>\n<p>        return -1; \/\/ \u83b7\u53d6\u6587\u4ef6\u63cf\u8ff0\u7b26\u65d7\u6807\u5931\u8d25<\/p>\n<p>    }<\/p>\n<p>    flags |= O_NONBLOCK;<\/p>\n<p>    if (fcntl(fd, F_SETFL, flags) == -1) {<\/p>\n<p>        return -1; \/\/ \u8bbe\u7f6e\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3a\u975e\u963b\u585e\u5931\u8d25<\/p>\n<p>    }<\/p>\n<p>    return 0; \/\/ \u8bbe\u7f6e\u6210\u529f<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u6ce8\u518c\u53ca\u5904\u7406SIGIO\u4fe1\u53f7<\/h3>\n<\/p>\n<p><p>\u5728\u5b8c\u6210\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u975e\u963b\u585e\u8bbe\u7f6e\u4e4b\u540e\uff0c\u4e0b\u4e00\u6b65\u5c31\u662f\u6ce8\u518cSIGIO\u4fe1\u53f7\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u8981\u6c42\u4e3aSIGIO\u4fe1\u53f7\u6307\u5b9a\u4e00\u4e2a\u4fe1\u53f7\u5904\u7406\u51fd\u6570\uff0c\u5e76\u901a\u77e5\u5185\u6838\uff0c\u5728\u4efb\u4f55\u9488\u5bf9\u8fd9\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u53ef\u8bfb\u6216\u53ef\u5199\u4e8b\u4ef6\u53d1\u751f\u65f6\u53d1\u9001SIGIO\u4fe1\u53f7\u7ed9\u8fdb\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &lt;signal.h&gt;<\/p>\n<p>void sigio_handler(int sig) {<\/p>\n<p>   \/\/ \u4fe1\u53f7\u5904\u7406\u4ee3\u7801\uff0c\u8fd9\u91cc\u4e00\u822c\u653e\u7f6e\u8bfb\u5199\u64cd\u4f5c<\/p>\n<p>}<\/p>\n<p>void registerSignalHandler() {<\/p>\n<p>    struct sigaction sa;<\/p>\n<p>    \/\/ \u6e05\u7a7a\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u7ed3\u6784\u4f53\u5e76\u8bbe\u7f6e\u4fe1\u53f7\u5904\u7406\u51fd\u6570<\/p>\n<p>    memset(&amp;sa, 0, sizeof(sa));<\/p>\n<p>    sa.sa_handler = sigio_handler;<\/p>\n<p>    sa.sa_flags = 0; \/\/ \u6216\u8005\u4f7f\u7528SA_RESTART\u4f7f\u88ab\u4fe1\u53f7\u6253\u65ad\u7684\u7cfb\u7edf\u8c03\u7528\u81ea\u52a8\u91cd\u542f\u52a8<\/p>\n<p>    sigemptyset(&amp;sa.sa_mask);<\/p>\n<p>    if (sigaction(SIGIO, &amp;sa, NULL) == -1) {<\/p>\n<p>        \/\/ \u6ce8\u518c\u4fe1\u53f7\u5931\u8d25\u5904\u7406\u903b\u8f91<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4fe1\u53f7\u53d1\u9001\u7ed9\u8fdb\u7a0b\u540e\uff0c\u5bf9\u5e94\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u4f1a\u88ab\u8c03\u7528\uff0c\u6b64\u65f6\u6211\u4eec\u53ef\u4ee5\u5728\u5904\u7406\u51fd\u6570\u4e2d\u5b8c\u6210\u76f8\u5173\u7684\u8bfb\u5199\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5173\u8054\u6587\u4ef6\u63cf\u8ff0\u7b26\u548c\u8fdb\u7a0b<\/h3>\n<\/p>\n<p><p>\u5f53\u8bbe\u7f6e\u597d\u975e\u963b\u585e\u548c\u4fe1\u53f7\u5904\u7406\u540e\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u544a\u8bc9\u5185\u6838\u5728\u6709\u4fe1\u53f7\u9a71\u52a8\u7684I\/O\u64cd\u4f5c\u65f6\u5411\u54ea\u4e2a\u8fdb\u7a0b\u53d1\u9001SIGIO\u4fe1\u53f7\u3002\u8fd9\u901a\u8fc7\u4f7f\u7528<code>fcntl<\/code>\u51fd\u6570\u4e0e<code>F_SETOWN<\/code>\u547d\u4ee4\u5b8c\u6210\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &lt;fcntl.h&gt;<\/p>\n<p>#include &lt;unistd.h&gt;<\/p>\n<p>int specifyProcessForSignals(int fd) {<\/p>\n<p>    int result;<\/p>\n<p>    result = fcntl(fd, F_SETOWN, getpid());<\/p>\n<p>    if (result == -1) {<\/p>\n<p>        return -1; \/\/ \u5173\u8054\u6587\u4ef6\u63cf\u8ff0\u7b26\u548c\u8fdb\u7a0b\u5931\u8d25<\/p>\n<p>    }<\/p>\n<p>    return 0; \/\/ \u5173\u8054\u6210\u529f<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5f00\u542f\u4fe1\u53f7\u9a71\u52a8I\/O\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u5728\u6240\u6709\u7684\u8bbe\u7f6e\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u901a\u77e5\u5185\u6838\u6587\u4ef6\u63cf\u8ff0\u7b26\u5df2\u7ecf\u51c6\u5907\u597d\u8fdb\u884c\u4fe1\u53f7\u9a71\u52a8I\/O\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &lt;fcntl.h&gt;<\/p>\n<p>int enableSignalDrivenIO(int fd) {<\/p>\n<p>    int flags;<\/p>\n<p>    flags = fcntl(fd, F_GETFL);<\/p>\n<p>    if (flags == -1) {<\/p>\n<p>        return -1; \/\/ \u83b7\u53d6\u6587\u4ef6\u63cf\u8ff0\u7b26\u65d7\u6807\u5931\u8d25<\/p>\n<p>    }<\/p>\n<p>    flags |= O_ASYNC;<\/p>\n<p>    if (fcntl(fd, F_SETFL, flags) == -1) {<\/p>\n<p>        return -1; \/\/ \u5f00\u542f\u4fe1\u53f7\u9a71\u52a8I\/O\u5931\u8d25<\/p>\n<p>    }<\/p>\n<p>    return 0; \/\/ \u4fe1\u53f7\u9a71\u52a8I\/O\u8bbe\u7f6e\u6210\u529f<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8bbe\u7f6e<code>O_ASYNC<\/code>\u6807\u5fd7\u5141\u8bb8\u5185\u6838\u5728\u6307\u5b9a\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u51c6\u5907\u597d\u8fdb\u884c\u8bfb\u53d6\u6216\u5199\u5165\u65f6\uff0c\u5411\u6307\u5b9a\u8fdb\u7a0b\u53d1\u9001SIGIO\u4fe1\u53f7\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5b8c\u6574\u7684\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u5b9e\u73b0\u8303\u4f8b<\/h3>\n<\/p>\n<p><p>\u7ed3\u5408\u4e0a\u8ff0\u5404\u4e2a\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u7684\u5b9e\u73b0\u8303\u4f8b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &lt;stdio.h&gt;<\/p>\n<p>#include &lt;unistd.h&gt;<\/p>\n<p>#include &lt;fcntl.h&gt;<\/p>\n<p>#include &lt;signal.h&gt;<\/p>\n<p>#include &lt;string.h&gt;<\/p>\n<p>#include &lt;errno.h&gt;<\/p>\n<p>\/\/ \u4fe1\u53f7\u5904\u7406\u51fd\u6570\u5b9e\u73b0<\/p>\n<p>void sigio_handler(int sig) {<\/p>\n<p>    static char buf[1024];<\/p>\n<p>    int bytesRead;<\/p>\n<p>    bytesRead = read(STDIN_FILENO, buf, sizeof(buf)-1);<\/p>\n<p>    if (bytesRead &lt; 0) {<\/p>\n<p>        perror(&quot;read f<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>led&quot;);<\/p>\n<p>        return;<\/p>\n<p>    }<\/p>\n<p>    if (bytesRead == 0) {<\/p>\n<p>        printf(&quot;No data to read\\n&quot;);<\/p>\n<p>        return;<\/p>\n<p>    }<\/p>\n<p>    buf[bytesRead] = &#039;\\0&#039;;<\/p>\n<p>    printf(&quot;Received %d bytes: %s\\n&quot;, bytesRead, buf);<\/p>\n<p>}<\/p>\n<p>int main() {<\/p>\n<p>    \/\/ \u8bbe\u7f6e\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3a\u975e\u963b\u585e\u6a21\u5f0f<\/p>\n<p>    if (setNonBlocking(STDIN_FILENO) == -1) {<\/p>\n<p>        perror(&quot;Could not set non-blocking mode&quot;);<\/p>\n<p>        return 1;<\/p>\n<p>    }<\/p>\n<p>    \/\/ \u6ce8\u518c\u4fe1\u53f7\u5904\u7406\u51fd\u6570<\/p>\n<p>    registerSignalHandler();<\/p>\n<p>    \/\/ \u5173\u8054\u6587\u4ef6\u63cf\u8ff0\u7b26\u548c\u8fdb\u7a0b<\/p>\n<p>    if (specifyProcessForSignals(STDIN_FILENO) == -1) {<\/p>\n<p>        perror(&quot;Could not set process owner for signals&quot;);<\/p>\n<p>        return 2;<\/p>\n<p>    }<\/p>\n<p>    \/\/ \u5f00\u542f\u4fe1\u53f7\u9a71\u52a8I\/O<\/p>\n<p>    if (enableSignalDrivenIO(STDIN_FILENO) == -1) {<\/p>\n<p>        perror(&quot;Could not enable signal driven I\/O&quot;);<\/p>\n<p>        return 3;<\/p>\n<p>    }<\/p>\n<p>    \/\/ \u73b0\u5728\u7a0b\u5e8f\u4f1a\u7ee7\u7eed\u6267\u884c\u4e0d\u4f1a\u88ab\u963b\u585e\uff0c\u76f4\u5230\u952e\u76d8\u8f93\u5165\u5230\u8fbe\uff0c\u89e6\u53d1\u4fe1\u53f7<\/p>\n<p>    printf(&quot;Starting signal-driven I\/O example. Type some text and press Enter.\\n&quot;);<\/p>\n<p>    while (1) {<\/p>\n<p>        pause(); \/\/ \u7b49\u5f85\u4fe1\u53f7\u5230\u6765<\/p>\n<p>    }<\/p>\n<p>    return 0;<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u8303\u4f8b\u4e2d\uff0c\u7a0b\u5e8f\u9996\u5148\u8bbe\u7f6e\u6807\u51c6\u8f93\u5165\uff08\u901a\u5e38\u662f\u952e\u76d8\u8f93\u5165\uff09\u4e3a\u975e\u963b\u585e\u6a21\u5f0f\uff0c\u7136\u540e\u6ce8\u518c\u4e86\u4e00\u4e2a\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u6765\u54cd\u5e94SIGIO\u4fe1\u53f7\u3002\u6700\u540e\uff0c\u5b83\u544a\u8bc9\u5185\u6838\u5f53\u6807\u51c6\u8f93\u5165\u51c6\u5907\u597d\u53ef\u8bfb\u53d6\u6570\u636e\u65f6\u53d1\u9001SIGIO\u4fe1\u53f7\uff0c\u5e76\u4f7f\u7528<code>pause<\/code>\u51fd\u6570\u6302\u8d77\u8fdb\u7a0b\u7b49\u5f85\u4fe1\u53f7\u7684\u5230\u6765\u3002\u5f53\u7528\u6237\u901a\u8fc7\u952e\u76d8\u8f93\u5165\u6587\u672c\u5e76\u6309\u4e0b\u56de\u8f66\u952e\u540e\uff0c\u5185\u6838\u53d1\u51faSIGIO\u4fe1\u53f7\uff0c\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u88ab\u8c03\u7528\u4ee5\u5904\u7406\u952e\u76d8\u8f93\u5165\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u9002\u7528\u4e8e\u5bf9\u5b9e\u65f6\u54cd\u5e94\u6709\u8981\u6c42\u548c\u591a\u8defI\/O\u590d\u7528\u573a\u666f\uff0c\u4f46\u5b83\u7684\u5b9e\u73b0\u548c\u6d4b\u8bd5\u9700\u8981\u5bf9\u7cfb\u7edf\u7684\u4fe1\u53f7\u5904\u7406\u673a\u5236\u548cI\/O\u64cd\u4f5c\u6709\u8f83\u6df1\u7684\u7406\u89e3\u3002\u6b64\u5916\uff0c\u8fd8\u8981\u6ce8\u610f\u4fe1\u53f7\u5904\u7406\u7684\u540c\u6b65\u95ee\u9898\uff0c\u9632\u6b62\u5728\u4fe1\u53f7\u5904\u7406\u8fc7\u7a0b\u4e2d\u5bf9\u5171\u4eab\u8d44\u6e90\u4ea7\u751f\u7ade\u4e89\u6761\u4ef6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q\uff1a\u5982\u4f55\u4f7f\u7528\u4ee3\u7801\u5b9e\u73b0\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\uff1f<\/strong><br \/>\n<strong>A\uff1a\u5728\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u4e2d\uff0c\u5982\u4f55\u5904\u7406\u4fe1\u53f7\uff1f<\/strong><br \/>\n<strong>Q\uff1a\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff1f<\/strong><\/p>\n<p>A\uff1a\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u662f\u4e00\u79cd\u901a\u8fc7\u5f02\u6b65\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u6765\u9a71\u52a8I\/O\u64cd\u4f5c\u7684\u7f16\u7a0b\u6a21\u578b\u3002\u4e0b\u9762\u662f\u5b9e\u73b0\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u7684\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u4f7f\u7528<code>sigaction()<\/code>\u51fd\u6570\u6765\u6ce8\u518c\u4e00\u4e2a\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\uff0c\u7528\u4e8e\u5904\u7406\u6307\u5b9a\u7684\u4fe1\u53f7\u3002\u8fd9\u4e2a\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u4f1a\u5728\u63a5\u6536\u5230\u4fe1\u53f7\u65f6\u88ab\u8c03\u7528\u3002<\/li>\n<li>\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528<code>sigprocmask()<\/code>\u51fd\u6570\u6765\u963b\u585e\u6307\u5b9a\u7684\u4fe1\u53f7\uff0c\u4ee5\u786e\u4fdd\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u53ea\u5728\u8fdb\u884cI\/O\u64cd\u4f5c\u65f6\u624d\u4f1a\u88ab\u89e6\u53d1\u3002<\/li>\n<li>\u7136\u540e\uff0c\u4f7f\u7528<code>fcntl()<\/code>\u51fd\u6570\u5c06\u6587\u4ef6\u63cf\u8ff0\u7b26\u8bbe\u7f6e\u4e3a\u975e\u963b\u585e\u6a21\u5f0f\uff0c\u8fd9\u6837\u5728\u8fdb\u884cI\/O\u64cd\u4f5c\u65f6\u4e0d\u4f1a\u963b\u585e\u6574\u4e2a\u7a0b\u5e8f\u7684\u6267\u884c\u3002<\/li>\n<li>\u6700\u540e\uff0c\u4f7f\u7528<code>select()<\/code>\u6216<code>poll()<\/code>\u51fd\u6570\u6765\u76d1\u89c6\u6587\u4ef6\u63cf\u8ff0\u7b26\u96c6\u5408\u4e2d\u7684\u53ef\u8bfb\u3001\u53ef\u5199\u6216\u9519\u8bef\u4e8b\u4ef6\uff0c\u5e76\u5c06\u5176\u4f20\u9012\u7ed9\u9002\u5f53\u7684\u5904\u7406\u7a0b\u5e8f\u3002<\/li>\n<\/ol>\n<p>\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u7684\u5de5\u4f5c\u539f\u7406\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u9996\u5148\uff0c\u7a0b\u5e8f\u4f1a\u963b\u585e\u7b49\u5f85I\/O\u4e8b\u4ef6\u6216\u4fe1\u53f7\u7684\u53d1\u751f\u3002<\/li>\n<li>\u5f53\u53d1\u751fI\/O\u4e8b\u4ef6\u6216\u6307\u5b9a\u7684\u4fe1\u53f7\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u4e2d\u65ad\u7a0b\u5e8f\u7684\u6267\u884c\uff0c\u5e76\u8c03\u7528\u76f8\u5e94\u7684\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u8fdb\u884c\u5904\u7406\u3002<\/li>\n<li>\u5904\u7406\u5b8c\u4fe1\u53f7\u540e\uff0c\u7a0b\u5e8f\u4f1a\u6062\u590d\u6267\u884c\uff0c\u5e76\u7ee7\u7eed\u76d1\u542c\u4e0b\u4e00\u4e2aI\/O\u4e8b\u4ef6\u6216\u4fe1\u53f7\u7684\u53d1\u751f\u3002<\/li>\n<\/ol>\n<p>\u5728\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u4e2d\uff0c\u5904\u7406\u4fe1\u53f7\u7684\u65b9\u5f0f\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u8fdb\u884c\u5b9a\u5236\uff0c\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u4e2d\u8fdb\u884c\u8bfb\u53d6\u3001\u5199\u5165\u3001\u5173\u95ed\u6587\u4ef6\u63cf\u8ff0\u7b26\u7b49\u64cd\u4f5c\u3002\u53e6\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u4fe1\u53f7\u6765\u5904\u7406\u4e0d\u540c\u7684I\/O\u4e8b\u4ef6\uff0c\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u54cd\u5e94\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4fe1\u53f7\u9a71\u52a8I\/O\u6a21\u578b\u662f\u4e00\u79cd\u5141\u8bb8\u7a0b\u5e8f\u7ee7\u7eed\u6267\u884c\u76f4\u5230\u67d0\u4e2a\u975e\u963b\u585eI\/O\u64cd\u4f5c\u51c6\u5907\u597d\u518d\u901a\u8fc7\u4fe1\u53f7\u901a\u77e5\u7a0b\u5e8f\u7684I\/O\u5904\u7406\u65b9\u5f0f\u3002\u8fd9\u79cd [&hellip;]","protected":false},"author":3,"featured_media":255592,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/255588"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=255588"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/255588\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/255592"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=255588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=255588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=255588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}