{"id":19809,"date":"2025-04-19T02:22:36","date_gmt":"2025-04-18T18:22:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/19809.html"},"modified":"2025-04-19T02:22:36","modified_gmt":"2025-04-18T18:22:36","slug":"%e7%bd%91%e7%bc%96%ef%bc%88%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/19809.html","title":{"rendered":"\u7f51\u7f16\uff08\u670d\u52a1\u5668\uff09"},"content":{"rendered":"<h2 style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">1.\u00a0 <span style=\"color:#333333\">IO\u591a\u8def\u590d\u7528<\/span><\/span><\/h2>\n<h3 style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">1.1poll<\/span><\/span><\/h3>\n<p style=\"margin-left:0;text-align:justify\">\n<p> <span style=\"color:#000000\"><span style=\"background-color:#fafafa\"><span style=\"color:#000000\">int poll(struct pollfd *fds, nfds_t nfds, int timeout);<\/span><br \/>\n<span style=\"color:#000000\">   \u53c2\u6570&#xff1a;<\/span><br \/>\n<span style=\"color:#000000\">   struct pollfd *fds<\/span><br \/>\n<span style=\"color:#000000\">     \u5173\u5fc3\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\u7ec4struct pollfd fds[N];<\/span><br \/>\n<span style=\"color:#000000\">   nfds:\u4e2a\u6570<\/span><br \/>\n<span style=\"color:#000000\">   timeout&#xff1a; \u8d85\u65f6\u68c0\u6d4b<\/span><br \/>\n<span style=\"color:#000000\">    \u6beb\u79d2\u7ea7\u7684&#xff1a;\u5982\u679c\u586b1000&#xff0c;1\u79d2<\/span><br \/>\n<span style=\"color:#000000\">     \u5982\u679c-1&#xff0c;\u963b\u585e<\/span><\/p>\n<p><span style=\"color:#000000\"> struct pollfd {<\/span><br \/>\n<span style=\"color:#000000\">     int   fd;         \/* \u68c0\u6d4b\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26 *\/<\/span><br \/>\n<span style=\"color:#000000\">     short events;     \/* \u68c0\u6d4b\u4e8b\u4ef6 *\/<\/span><br \/>\n<span style=\"color:#000000\">     short revents;    \/* \u8c03\u7528poll\u51fd\u6570\u8fd4\u56de\u586b\u5145\u7684\u4e8b\u4ef6&#xff0c;poll\u51fd\u6570\u4e00\u65e6\u8fd4\u56de&#xff0c;\u5c06\u5bf9\u5e94\u4e8b\u4ef6\u81ea\u52a8\u586b\u5145\u7ed3\u6784\u4f53\u8fd9\u4e2a\u6210\u5458\u3002\u53ea\u9700\u8981\u5224\u65ad\u8fd9\u4e2a\u6210\u5458\u7684\u503c\u5c31\u53ef\u4ee5\u786e\u5b9a\u662f\u5426\u4ea7\u751f\u4e8b\u4ef6 *\/<\/span><br \/>\n<span style=\"color:#000000\"> };<\/span><br \/>\n<span style=\"color:#000000\"> \u4e8b\u4ef6&#xff1a;     POLLIN &#xff1a;\u8bfb\u4e8b\u4ef6<\/span><br \/>\n<span style=\"color:#000000\">           POLLOUT : \u5199\u4e8b\u4ef6<\/span><br \/>\n<span style=\"color:#000000\">           POLLERR&#xff1a;\u5f02\u5e38\u4e8b\u4ef6<\/span><br \/>\n<\/span><\/span> <\/p>\n<p style=\"margin-left:0;text-align:justify\">\n<table cellspacing=\"0\">\n<tbody>\n<tr>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:189.133px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u6d41\u7a0b<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:111px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">select<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:167.867px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">poll<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:189.133px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">1.\u5efa\u7acb\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u8868<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:111px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">fd_set\u7ebf\u6027\u8868<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:167.867px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">struct pollfd <\/span><span style=\"color:#333333\">fds[n]<\/span><span style=\"color:#333333\">\u7ed3\u6784\u4f53\u6570\u7ec4<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:189.133px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">2.\u5c06\u5173\u5fc3\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u52a0\u5230\u8868\u4e2d<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:111px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">FD_SET(fd,&amp;readfds)<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:167.867px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u7ed3\u6784\u4f53\u5185\u5bb9\u586b\u5145fds[m].fd&#061; fd<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">fds[m].events&#061;POLLIN<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:189.133px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">3.<\/span><span style=\"color:#333333\"> \u7136\u540e\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u3002 select <\/span><span style=\"color:#333333\">\/<\/span><span style=\"color:#333333\"> poll<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">4.<\/span><span style=\"color:#333333\"> \u5f53\u8fd9\u4e9b\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2d\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u5df2\u51c6\u5907\u597d\u8fdb\u884cI<\/span><span style=\"color:#333333\">\/<\/span><span style=\"color:#333333\">O\u64cd\u4f5c\u7684\u65f6\u5019<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u8be5\u51fd\u6570\u624d\u8fd4\u56de<\/span><span style=\"color:#333333\">(<\/span><span style=\"color:#333333\">\u963b\u585e<\/span><span style=\"color:#333333\">)<\/span><span style=\"color:#333333\">\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\">\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:111px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">select<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:167.867px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">poll<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:189.133px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">5.\u5224\u65ad<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:111px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">FD_ISSET<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:167.867px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">revents&#061;&#061;POLLIN<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:189.133px\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">6.\u76f8\u5173\u64cd\u4f5c<\/span><\/span><\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:111px\">\n<p style=\"margin-left:0;text-align:justify\">\n<\/td>\n<td colspan=\"1\" rowspan=\"1\" style=\"border-color:#cbcdd1;vertical-align:middle;width:167.867px\">\n<p style=\"margin-left:0;text-align:justify\">\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u7279\u70b9&#xff1a;<\/span><\/span><\/h4>\n<p style=\"margin-left:0;text-align:left\"><span style=\"color:#000000\"><span style=\"color:#000000\">1. \u4f18\u5316\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e2a\u6570\u7684\u9650\u5236;(\u6839\u636epoll\u51fd\u6570\u7b2c\u4e00\u4e2a\u53c2\u6570\u6765\u5b9a&#xff0c;\u5982\u679c\u76d1\u542c\u7684\u4e8b\u4ef6\u4e3a1\u4e2a&#xff0c;\u5219\u7ed3\u6784\u4f53\u6570\u7ec4\u5143\u7d20\u4e2a\u6570\u4e3a1&#xff0c;\u5982\u679c\u60f3\u76d1\u542c100\u4e2a&#xff0c;\u90a3\u4e48\u8fd9\u4e2a\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u5143\u7d20\u4e2a\u6570\u5c31\u4e3a100&#xff0c;\u7531\u7a0b\u5e8f\u5458\u81ea\u5df1\u6765\u51b3\u5b9a)<\/span><\/span><\/p>\n<p style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">2.\u00a0 <span style=\"color:#000000\">poll\u88ab\u5524\u9192\u4e4b\u540e\u9700\u8981\u91cd\u65b0\u8f6e\u8be2\u4e00\u904d\u9a71\u52a8\u7684poll\u51fd\u6570&#xff0c;\u6548\u7387\u6bd4\u8f83\u4f4e<\/span><\/span><\/p>\n<p style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">3.\u00a0 <span style=\"color:#000000\">poll\u4e0d\u9700\u8981\u91cd\u65b0\u6784\u9020\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868&#xff0c;\u53ea\u9700\u8981\u4ece\u7528\u6237\u7a7a\u95f4\u5411\u5185\u6838\u7a7a\u95f4\u62f7\u8d1d\u4e00\u6b21\u6570\u636e\u5373\u53ef<\/span><\/span><\/p>\n<h3 style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">1.2epoll<\/span><\/span><\/h3>\n<p style=\"margin-left:0;text-align:justify\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"618\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418182234-6802986aec0a1.png\" width=\"1200\" \/><\/p>\n<h4 style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u7279\u70b9&#xff1a;<\/span><\/span><\/h4>\n<p style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">1.\u00a0 <span style=\"color:#000000\">\u76d1\u542c\u7684\u6700\u5927\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6ca1\u6709\u4e2a\u6570\u9650\u5236&#xff08;\u7406\u8bba\u4e0a&#xff0c;\u53d6\u51b3\u4e0e\u4f60\u81ea\u5df1\u7684\u7cfb\u7edf&#xff09;<\/span><\/span><\/p>\n<p style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">2.\u00a0 <span style=\"color:#000000\">\u5f02\u6b65I\/O&#xff0c;Epoll\u5f53\u6709\u4e8b\u4ef6\u4ea7\u751f\u88ab\u5524\u9192\u4e4b\u540e&#xff0c;\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3b\u52a8\u8c03\u7528callback(\u56de\u8c03\u51fd\u6570)\u51fd\u6570\u76f4\u63a5\u62ff\u5230\u5524\u9192\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u4e0d\u9700\u8981\u8f6e\u8be2&#xff0c;\u6548\u7387\u9ad8<\/span><\/span><\/p>\n<p style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">3.\u00a0 <span style=\"color:#000000\">epoll\u4e0d\u9700\u8981\u91cd\u65b0\u6784\u9020\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868&#xff0c;\u53ea\u9700\u8981\u4ece\u7528\u6237\u7a7a\u95f4\u5411\u5185\u6838\u7a7a\u95f4\u62f7\u8d1d\u4e00\u6b21\u6570\u636e\u5373\u53ef.<\/span><\/span><\/p>\n<h2 style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">2.\u00a0 <span style=\"color:#333333\">\u670d\u52a1\u5668\u6a21\u578b<\/span><\/span><\/h2>\n<h3 style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">2.1\u5faa\u73af\u670d\u52a1\u5668\u6a21\u578b<\/span><\/span><\/h3>\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u540c\u4e00\u65f6\u523b\u53ea\u80fd\u54cd\u5e94\u4e00\u4e2a\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\">\n<p> <span style=\"color:#000000\"><span style=\"background-color:#fafafa\"><span style=\"color:#000000\">socket();<\/span><br \/>\n<span style=\"color:#000000\">bind();<\/span><br \/>\n<span style=\"color:#000000\">listen();<\/span><br \/>\n<span style=\"color:#000000\">while(1)<\/span><br \/>\n<span style=\"color:#000000\">{<\/span><br \/>\n<span style=\"color:#000000\">        accept();<\/span><br \/>\n<span style=\"color:#000000\">        while(1)<\/span><br \/>\n<span style=\"color:#000000\">        {<\/span><br \/>\n<span style=\"color:#000000\">            \/\/\u5904\u7406<\/span><br \/>\n<span style=\"color:#000000\">        }<\/span><br \/>\n<span style=\"color:#000000\">        close();<\/span><br \/>\n<span style=\"color:#000000\">}<\/span><\/p>\n<p><\/span><\/span> <\/p>\n<h3 style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">2.2\u5e76\u53d1\u670d\u52a1\u5668\u6a21\u578b<\/span><\/span><\/h3>\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u540c\u4e00\u65f6\u523b\u80fd\u591f\u54cd\u5e94\u591a\u4e2a\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42,\u5e38\u7528\u6a21\u578b&#xff1a;\u591a\u8fdb\u7a0b\u3001\u591a\u7ebf\u7a0b\u3001IO\u591a\u8def\u590d\u7528<\/span><\/span><\/p>\n<h4 style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u591a\u8fdb\u7a0b\u6a21\u578b<\/span><\/span><\/h4>\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u6bcf\u6765\u4e00\u4e2a\u5ba2\u6237\u7aef\u8fde\u63a5&#xff0c;\u5f00\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6765\u4e13\u95e8\u5904\u7406\u5ba2\u6237\u7aef\u7684\u6570\u636e&#xff0c;\u5b9e\u73b0\u7b80\u5355&#xff0c;\u4f46\u662f\u7cfb\u7edf\u5f00\u9500\u76f8\u5bf9\u8f83\u5927&#xff0c;\u66f4\u63a8\u8350\u4f7f\u7528\u7ebf\u7a0b\u6a21\u578b\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\">\n<p> <span style=\"color:#000000\"><span style=\"background-color:#fafafa\"><span style=\"color:#000000\">socket();<\/span><br \/>\n<span style=\"color:#000000\">bind();<\/span><br \/>\n<span style=\"color:#000000\">listen();<\/span><br \/>\n<span style=\"color:#000000\">while(1)<\/span><br \/>\n<span style=\"color:#000000\">{<\/span><br \/>\n<span style=\"color:#000000\">    accept();<\/span><br \/>\n<span style=\"color:#000000\">    if(fork()&#061;&#061;0)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n    <span style=\"color:#000000\">    while(1)<\/span><br \/>\n<span style=\"color:#000000\">        {<\/span><br \/>\n        <span style=\"color:#000000\">    \/\/\u5904\u7406<\/span><br \/>\n<span style=\"color:#000000\">        }<\/span><span style=\"color:#000000\">        close();<\/span><br \/>\n<span style=\"color:#000000\">        exit();<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">    else<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">}<\/span><br \/>\n<\/span><\/span> <\/p>\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"background-color:#ffff00\"><span style=\"color:#ff0000\">\u591a\u8fdb\u7a0b\u7279\u70b9 &#xff1a;<\/span><\/span><\/span><\/p>\n<p style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">1.\u00a0 <span style=\"color:#ff0000\">fork\u4e4b\u524d\u7684\u4ee3\u7801\u88ab\u590d\u5236&#xff0c;\u4f46\u662f\u4e0d\u4f1a\u91cd\u65b0\u6267\u884c\u4e00\u904d&#xff1b;fork\u4e4b\u540e\u7684\u4ee3\u7801\u88ab\u590d\u5236&#xff0c;\u5e76\u4e14\u88ab\u518d\u6b21\u6267\u884c\u4e00\u904d<\/span><\/span><\/p>\n<p style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">2.\u00a0 <span style=\"color:#ff0000\">fork\u4e4b\u540e\u4e24\u4e2a\u8fdb\u7a0b\u76f8\u4e92\u72ec\u7acb&#xff0c;\u5b50\u8fdb\u7a0b\u62f7\u8d1d\u4e86\u7236\u8fdb\u7a0b\u7684\u6240\u6709\u4ee3\u7801&#xff0c;\u4f46\u662f\u5185\u5b58\u7a7a\u95f4\u72ec\u7acb<\/span><\/span><\/p>\n<p style=\"margin-left:16.8pt;text-align:justify\"><span style=\"color:#000000\">3.\u00a0 <span style=\"color:#ff0000\">fork\u4e4b\u524d\u6253\u5f00\u7684\u6587\u4ef6&#xff0c;fork\u4e4b\u540e\u62ff\u5230\u7684\u662f\u540c\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u64cd\u4f5c\u7684\u662f\u540c\u4e00\u4e2a\u6587\u4ef6\u6307\u9488<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\">\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u591a\u8fdb\u7a0b\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:left\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u6ce8\u610f&#xff1a;\u6536\u5230\u5ba2\u6237\u7aef\u6d88\u606f\u540e&#xff0c;\u6253\u5370\u4e0b\u662f\u6765\u81ea\u54ea\u4e2a\u5ba2\u6237\u7aef\u7684\u6570\u636e&#xff08;\u6765\u7535\u663e\u793a&#xff09;<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:left\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u4f7f\u7528<\/span><span style=\"color:#0563c1\">SIGCHLD<\/span><span style=\"color:#333333\">\u6765\u5904\u7406\u5b50\u8fdb\u7a0b\u7ed3\u675f\u7684\u4fe1\u53f7&#xff0c;\u4fe1\u53f7\u51fd\u6570\u4e2d\u56de\u6536\u8fdb\u7a0b\u8d44\u6e90\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\">\n<p> <span style=\"color:#000000\"><span style=\"background-color:#fafafa\"><span style=\"color:#000000\">#include &lt;sys\/types.h&gt; \/* See NOTES *\/<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;sys\/socket.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;sys\/socket.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;netinet\/in.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;netinet\/ip.h&gt; \/* superset of previous *\/<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;arpa\/inet.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;stdio.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;unistd.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;stdlib.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;string.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;signal.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;sys\/wait.h&gt;<\/span><\/p>\n<p><span style=\"color:#000000\">void handler(int arg)<\/span><br \/>\n<span style=\"color:#000000\">{<\/span><br \/>\n<span style=\"color:#000000\">    waitpid(-1, NULL, WNOHANG);<\/span><br \/>\n<span style=\"color:#000000\">}<\/span><br \/>\n<span style=\"color:#000000\">int main(int argc, char const *argv[])<\/span><br \/>\n<span style=\"color:#000000\">{<\/span><br \/>\n<span style=\"color:#000000\">    if (argc !&#061; 2)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        printf(&#034;please input %s ,port!!!\\\\n&#034;, argv[0]);<\/span><br \/>\n<span style=\"color:#000000\">        return -1;<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><\/p>\n<p><span style=\"color:#000000\">    \/\/ 1.\u521b\u5efa\u6d41\u5f0f\u5957\u63a5\u5b57<\/span><br \/>\n<span style=\"color:#000000\">    int sockfd &#061; socket(AF_INET, SOCK_STREAM, 0);<\/span><br \/>\n<span style=\"color:#000000\">    if (sockfd &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        perror(&#034;socket err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">        return -1;<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">    printf(&#034;socket success\\\\n&#034;);<\/span><br \/>\n<span style=\"color:#000000\">    \/\/ 2.\u586b\u5145\u7ed3\u6784\u4f53<\/span><br \/>\n<span style=\"color:#000000\">    struct sockaddr_in addr, caddr;<\/span><br \/>\n<span style=\"color:#000000\">    addr.sin_family &#061; AF_INET;            \/\/ \u534f\u8bae\u65cf<\/span><br \/>\n<span style=\"color:#000000\">    addr.sin_port &#061; htons(atoi(argv[1])); \/\/ \u7aef\u53e3\u53f7(\u7f51\u7edc\u5b57\u8282\u5e8f)<\/span><br \/>\n<span style=\"color:#000000\">    \/\/ addr.sin_addr.s_addr &#061; inet_addr(argv[1]); \/\/ ip\u5730\u5740(32\u4f4d\u65e0\u7b26\u53f7\u6574\u6570)<\/span><br \/>\n<span style=\"color:#000000\">    addr.sin_addr.s_addr &#061; inet_addr(&#034;192.168.50.201&#034;);<\/span><\/p>\n<p><span style=\"color:#000000\">    socklen_t len &#061; sizeof(caddr);<\/span><\/p>\n<p><span style=\"color:#000000\">    \/\/ 3.\u7ed1\u5b9a<\/span><br \/>\n<span style=\"color:#000000\">    if (bind(sockfd, (struct sockaddr *)&amp;addr, sizeof(addr)) &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        perror(&#034;bind err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">        return -1;<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">    printf(&#034;bind success\\\\n&#034;);<\/span><\/p>\n<p><span style=\"color:#000000\">    \/\/ 4.\u76d1\u542c<\/span><\/p>\n<p><span style=\"color:#000000\">    if (listen(sockfd, 5) &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        perror(&#034;listen err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">        return -1;<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><\/p>\n<p><span style=\"color:#000000\">    signal(SIGCHLD, handler);<\/span><br \/>\n<span style=\"color:#000000\">    while (1)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        \/\/ 5.\u7b49\u5f85\u5ba2\u6237\u7aef\u94fe\u63a5&#xff0c;\u4ea7\u751f\u7528\u4e8e\u901a\u4fe1\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<\/span><br \/>\n<span style=\"color:#000000\">        int acceptfd &#061; accept(sockfd, (struct sockaddr *)&amp;caddr, &amp;len);<\/span><br \/>\n<span style=\"color:#000000\">        if (acceptfd &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">        {<\/span><br \/>\n<span style=\"color:#000000\">            perror(&#034;accept err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">            return -1;<\/span><br \/>\n<span style=\"color:#000000\">        }<\/span><br \/>\n<span style=\"color:#000000\">        printf(&#034;acceptfd &#061; %d \\\\n&#034;, acceptfd);<\/span><br \/>\n<span style=\"color:#000000\">        \/\/ \u6253\u5370\u5ba2\u6237\u7aefip\u548c\u7aef\u53e3\u53f7<\/span><br \/>\n<span style=\"color:#000000\">        printf(&#034;client ip:%s , port : %d\\\\n&#034;, inet_ntoa(caddr.sin_addr), ntohs(caddr.sin_port));<\/span><\/p>\n<p><span style=\"color:#000000\">        \/\/ \u521b\u5efa\u8fdb\u7a0b<\/span><br \/>\n<span style=\"color:#000000\">        pid_t pid &#061; fork();<\/span><br \/>\n<span style=\"color:#000000\">        if (pid &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">        {<\/span><br \/>\n<span style=\"color:#000000\">            perror(&#034;fork err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">            return -1;<\/span><br \/>\n<span style=\"color:#000000\">        }<\/span><br \/>\n<span style=\"color:#000000\">        else if (pid &#061;&#061; 0) \/\/ \u5b50\u8fdb\u7a0b<\/span><br \/>\n<span style=\"color:#000000\">        {<\/span><br \/>\n<span style=\"color:#000000\">            close(sockfd);<\/span><br \/>\n<span style=\"color:#000000\">            while (1) \/\/ \u8fde\u63a5\u6210\u529f\u540e\u5faa\u73af\u63a5\u6536\u4fe1\u606f<\/span><br \/>\n<span style=\"color:#000000\">            {<\/span><br \/>\n<span style=\"color:#000000\">                \/\/ 6.\u63a5\u53d7\u6570\u636e<\/span><br \/>\n<span style=\"color:#000000\">                char buf[128] &#061; {};<\/span><br \/>\n<span style=\"color:#000000\">                int ret &#061; recv(acceptfd, buf, 128, 0);<\/span><br \/>\n<span style=\"color:#000000\">                if (ret &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">                {<\/span><br \/>\n<span style=\"color:#000000\">                    perror(&#034;recv err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">                    return -1;<\/span><br \/>\n<span style=\"color:#000000\">                }<\/span><br \/>\n<span style=\"color:#000000\">                else if (ret &#061;&#061; 0)<\/span><br \/>\n<span style=\"color:#000000\">                {<\/span><br \/>\n<span style=\"color:#000000\">                    printf(&#034;client exit\\\\n&#034;);<\/span><br \/>\n<span style=\"color:#000000\">                    break;<\/span><br \/>\n<span style=\"color:#000000\">                }<\/span><br \/>\n<span style=\"color:#000000\">                printf(&#034;recv :%s\\\\n&#034;, buf);<\/span><br \/>\n<span style=\"color:#000000\">            }<\/span><br \/>\n<span style=\"color:#000000\">            \/\/ 7.\u5173\u95ed\u6587\u4ef6\u63cf\u8ff0\u7b26<\/span><br \/>\n<span style=\"color:#000000\">            close(acceptfd);<\/span><br \/>\n<span style=\"color:#000000\">            exit(0);<\/span><br \/>\n<span style=\"color:#000000\">        }<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">    close(sockfd);<\/span><\/p>\n<p><span style=\"color:#000000\">    return 0;<\/span><br \/>\n<span style=\"color:#000000\">}<\/span><\/p>\n<p><\/span><\/span> <\/p>\n<h4 style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u591a\u7ebf\u7a0b\u6a21\u578b<\/span><\/span><\/h4>\n<p style=\"margin-left:0;text-align:left\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u6bcf\u6765\u4e00\u4e2a\u5ba2\u6237\u7aef\u8fde\u63a5&#xff0c;\u5f00\u4e00\u4e2a\u5b50\u7ebf\u7a0b\u6765\u4e13\u95e8\u5904\u7406\u5ba2\u6237\u7aef\u7684\u6570\u636e&#xff0c;\u5b9e\u73b0\u7b80\u5355&#xff0c;\u5360\u7528\u8d44\u6e90\u8f83\u5c11&#xff0c;\u5c5e\u4e8e\u4f7f\u7528\u6bd4\u8f83\u5e7f\u6cdb\u7684\u6a21\u578b&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\">\n<p> <span style=\"color:#000000\"><span style=\"background-color:#fafafa\"><span style=\"color:#000000\">socket();<\/span><br \/>\n<span style=\"color:#000000\">bind();<\/span><br \/>\n<span style=\"color:#000000\">listen()<\/span><br \/>\n<span style=\"color:#000000\">while(1)<\/span><br \/>\n<span style=\"color:#000000\">{<\/span><br \/>\n<span style=\"color:#000000\">    accept();<\/span><br \/>\n<span style=\"color:#000000\">    pthread_create();<\/span><\/p>\n<p><span style=\"color:#000000\">}<\/span><br \/>\n<\/span><\/span> <\/p>\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u591a\u7ebf\u7a0b\u5b9e\u73b0\u5e76\u53d1\u670d\u52a1\u5668&#xff1a;<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\">\n<p> <span style=\"color:#000000\"><span style=\"background-color:#fafafa\"><span style=\"color:#000000\">#include &lt;sys\/types.h&gt; \/* See NOTES *\/<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;sys\/socket.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;sys\/socket.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;netinet\/in.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;netinet\/ip.h&gt; \/* superset of previous *\/<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;arpa\/inet.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;stdio.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;unistd.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;stdlib.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;string.h&gt;<\/span><br \/>\n<span style=\"color:#000000\">#include &lt;pthread.h&gt;<\/span><\/p>\n<p><span style=\"color:#000000\">void *mythread(void *arg)<\/span><br \/>\n<span style=\"color:#000000\">{<\/span><br \/>\n<span style=\"color:#000000\">    int acceptfd &#061; *(int *)arg;<\/span><br \/>\n<span style=\"color:#000000\">    while (1) \/\/ \u8fde\u63a5\u6210\u529f\u540e\u5faa\u73af\u63a5\u6536\u4fe1\u606f<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        \/\/ 6.\u63a5\u53d7\u6570\u636e<\/span><br \/>\n<span style=\"color:#000000\">        char buf[128] &#061; {};<\/span><br \/>\n<span style=\"color:#000000\">        int ret &#061; recv(acceptfd, buf, 128, 0);<\/span><br \/>\n<span style=\"color:#000000\">        if (ret &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">        {<\/span><br \/>\n<span style=\"color:#000000\">            perror(&#034;recv err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">            return NULL;<\/span><br \/>\n<span style=\"color:#000000\">        }<\/span><br \/>\n<span style=\"color:#000000\">        else if (ret &#061;&#061; 0)<\/span><br \/>\n<span style=\"color:#000000\">        {<\/span><br \/>\n<span style=\"color:#000000\">            printf(&#034;client exit\\\\n&#034;);<\/span><br \/>\n<span style=\"color:#000000\">            break;<\/span><br \/>\n<span style=\"color:#000000\">        }<\/span><br \/>\n<span style=\"color:#000000\">        printf(&#034;recv :%s\\\\n&#034;, buf);<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">    \/\/ 7.\u5173\u95ed\u6587\u4ef6\u63cf\u8ff0\u7b26<\/span><br \/>\n<span style=\"color:#000000\">    close(acceptfd);<\/span><br \/>\n<span style=\"color:#000000\">    pthread_exit(NULL);<\/span><br \/>\n<span style=\"color:#000000\">}<\/span><br \/>\n<span style=\"color:#000000\">int main(int argc, char const *argv[])<\/span><br \/>\n<span style=\"color:#000000\">{<\/span><br \/>\n<span style=\"color:#000000\">    if (argc !&#061; 2)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        printf(&#034;please input %s ,port!!!\\\\n&#034;, argv[0]);<\/span><br \/>\n<span style=\"color:#000000\">        return -1;<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><\/p>\n<p><span style=\"color:#000000\">    \/\/ 1.\u521b\u5efa\u6d41\u5f0f\u5957\u63a5\u5b57<\/span><br \/>\n<span style=\"color:#000000\">    int sockfd &#061; socket(AF_INET, SOCK_STREAM, 0);<\/span><br \/>\n<span style=\"color:#000000\">    if (sockfd &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        perror(&#034;socket err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">        return -1;<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">    printf(&#034;socket success\\\\n&#034;);<\/span><br \/>\n<span style=\"color:#000000\">    \/\/ 2.\u586b\u5145\u7ed3\u6784\u4f53<\/span><br \/>\n<span style=\"color:#000000\">    struct sockaddr_in addr, caddr;<\/span><br \/>\n<span style=\"color:#000000\">    addr.sin_family &#061; AF_INET;            \/\/ \u534f\u8bae\u65cf<\/span><br \/>\n<span style=\"color:#000000\">    addr.sin_port &#061; htons(atoi(argv[1])); \/\/ \u7aef\u53e3\u53f7(\u7f51\u7edc\u5b57\u8282\u5e8f)<\/span><br \/>\n<span style=\"color:#000000\">    \/\/ addr.sin_addr.s_addr &#061; inet_addr(argv[1]); \/\/ ip\u5730\u5740(32\u4f4d\u65e0\u7b26\u53f7\u6574\u6570)<\/span><br \/>\n<span style=\"color:#000000\">    addr.sin_addr.s_addr &#061; inet_addr(&#034;192.168.50.201&#034;);<\/span><\/p>\n<p><span style=\"color:#000000\">    socklen_t len &#061; sizeof(caddr);<\/span><\/p>\n<p><span style=\"color:#000000\">    \/\/ 3.\u7ed1\u5b9a<\/span><br \/>\n<span style=\"color:#000000\">    if (bind(sockfd, (struct sockaddr *)&amp;addr, sizeof(addr)) &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        perror(&#034;bind err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">        return -1;<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">    printf(&#034;bind success\\\\n&#034;);<\/span><\/p>\n<p><span style=\"color:#000000\">    \/\/ 4.\u76d1\u542c<\/span><\/p>\n<p><span style=\"color:#000000\">    if (listen(sockfd, 5) &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        perror(&#034;listen err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">        return -1;<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">    while (1)<\/span><br \/>\n<span style=\"color:#000000\">    {<\/span><br \/>\n<span style=\"color:#000000\">        \/\/ 5.\u7b49\u5f85\u5ba2\u6237\u7aef\u94fe\u63a5&#xff0c;\u4ea7\u751f\u7528\u4e8e\u901a\u4fe1\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<\/span><br \/>\n<span style=\"color:#000000\">        int acceptfd &#061; accept(sockfd, (struct sockaddr *)&amp;caddr, &amp;len);<\/span><br \/>\n<span style=\"color:#000000\">        if (acceptfd &lt; 0)<\/span><br \/>\n<span style=\"color:#000000\">        {<\/span><br \/>\n<span style=\"color:#000000\">            perror(&#034;accept err&#034;);<\/span><br \/>\n<span style=\"color:#000000\">            return -1;<\/span><br \/>\n<span style=\"color:#000000\">        }<\/span><br \/>\n<span style=\"color:#000000\">        printf(&#034;acceptfd &#061; %d \\\\n&#034;, acceptfd);<\/span><br \/>\n<span style=\"color:#000000\">        \/\/ \u6253\u5370\u5ba2\u6237\u7aefip\u548c\u7aef\u53e3\u53f7<\/span><br \/>\n<span style=\"color:#000000\">        printf(&#034;client ip:%s , port : %d\\\\n&#034;, inet_ntoa(caddr.sin_addr), ntohs(caddr.sin_port));<\/span><\/p>\n<p><span style=\"color:#000000\">        \/\/ \u521b\u5efa\u7ebf\u7a0b<\/span><br \/>\n<span style=\"color:#000000\">        pthread_t tid;<\/span><br \/>\n<span style=\"color:#000000\">        pthread_create(&amp;tid, NULL, mythread, &amp;acceptfd);<\/span><br \/>\n<span style=\"color:#000000\">        pthread_detach(tid);<\/span><br \/>\n<span style=\"color:#000000\">    }<\/span><br \/>\n<span style=\"color:#000000\">    close(sockfd);<\/span><\/p>\n<p><span style=\"color:#000000\">    return 0;<\/span><br \/>\n<span style=\"color:#000000\">}<\/span><\/p>\n<p><\/span><\/span> <\/p>\n<h4 style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">IO\u591a\u8def\u590d\u7528\u6a21\u578b<\/span><\/span><\/h4>\n<p style=\"margin-left:0;text-align:justify\"><span style=\"color:#000000\"><span style=\"color:#333333\">\u501f\u52a9<\/span><span style=\"color:#333333\">select\u3001poll\u3001epoll<\/span><span style=\"color:#333333\">\u673a\u5236&#xff0c;\u5c06\u65b0\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u63cf\u8ff0\u7b26\u589e\u52a0\u5230\u63cf\u8ff0\u7b26\u8868\u4e2d&#xff0c;\u53ea\u9700\u8981\u4e00\u4e2a\u7ebf\u7a0b\u5373\u53ef\u5904\u7406\u6240\u6709\u7684\u5ba2\u6237\u7aef\u8fde\u63a5&#xff0c;\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u4e2d\u5e94\u7528\u5e7f\u6cdb&#xff0c;\u4e0d\u8fc7\u4ee3\u7801\u5199\u8d77\u6765\u7a0d\u663e\u7e41\u7410\u3002<\/span><\/span><\/p>\n<p style=\"margin-left:0;text-align:justify\">\n<p style=\"margin-left:0;text-align:justify\">\n<p style=\"margin-left:0;text-align:justify\">\n<p style=\"margin-left:0;text-align:justify\">\n<p style=\"margin-left:0;text-align:justify\">\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb807\u6b21\uff0c\u70b9\u8d5e18\u6b21\uff0c\u6536\u85cf6\u6b21\u3002(\u6839\u636epoll\u51fd\u6570\u7b2c\u4e00\u4e2a\u53c2\u6570\u6765\u5b9a\uff0c\u5982\u679c\u76d1\u542c\u7684\u4e8b\u4ef6\u4e3a1\u4e2a\uff0c\u5219\u7ed3\u6784\u4f53\u6570\u7ec4\u5143\u7d20\u4e2a\u6570\u4e3a1\uff0c\u5982\u679c\u60f3\u76d1\u542c100\u4e2a\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u5143\u7d20\u4e2a\u6570\u5c31\u4e3a100\uff0c\u7531\u7a0b\u5e8f\u5458\u81ea\u5df1\u6765\u51b3\u5b9a)\u5f02\u6b65I\/O\uff0cEpoll\u5f53\u6709\u4e8b\u4ef6\u4ea7\u751f\u88ab\u5524\u9192\u4e4b\u540e\uff0c\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3b\u52a8\u8c03\u7528callback(\u56de\u8c03\u51fd\u6570)\u51fd\u6570\u76f4\u63a5\u62ff\u5230\u5524\u9192\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u4e0d\u9700\u8981\u8f6e\u8be2\uff0c\u6548\u7387\u9ad8\u3002\u673a\u5236\uff0c\u5c06\u65b0\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u63cf\u8ff0\u7b26\u589e\u52a0\u5230\u63cf\u8ff0\u7b26\u8868\u4e2d\uff0c\u53ea\u9700\u8981\u4e00\u4e2a\u7ebf\u7a0b\u5373\u53ef\u5904\u7406\u6240\u6709\u7684\u5ba2\u6237\u7aef\u8fde\u63a5\uff0c\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u4e2d\u5e94\u7528\u5e7f\u6cdb\uff0c\u4e0d\u8fc7\u4ee3\u7801\u5199\u8d77\u6765\u7a0d\u663e\u7e41\u7410\u3002\u76d1\u542c\u7684\u6700\u5927\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6ca1\u6709\u4e2a\u6570\u9650\u5236\uff08\u7406\u8bba\u4e0a\uff0c\u53d6\u51b3\u4e0e\u4f60\u81ea\u5df1\u7684\u7cfb\u7edf\uff09<\/p>\n","protected":false},"author":2,"featured_media":19808,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,78],"topic":[],"class_list":["post-19809","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-linux","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7f51\u7f16\uff08\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/19809.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7f51\u7f16\uff08\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb807\u6b21\uff0c\u70b9\u8d5e18\u6b21\uff0c\u6536\u85cf6\u6b21\u3002(\u6839\u636epoll\u51fd\u6570\u7b2c\u4e00\u4e2a\u53c2\u6570\u6765\u5b9a\uff0c\u5982\u679c\u76d1\u542c\u7684\u4e8b\u4ef6\u4e3a1\u4e2a\uff0c\u5219\u7ed3\u6784\u4f53\u6570\u7ec4\u5143\u7d20\u4e2a\u6570\u4e3a1\uff0c\u5982\u679c\u60f3\u76d1\u542c100\u4e2a\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u5143\u7d20\u4e2a\u6570\u5c31\u4e3a100\uff0c\u7531\u7a0b\u5e8f\u5458\u81ea\u5df1\u6765\u51b3\u5b9a)\u5f02\u6b65I\/O\uff0cEpoll\u5f53\u6709\u4e8b\u4ef6\u4ea7\u751f\u88ab\u5524\u9192\u4e4b\u540e\uff0c\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3b\u52a8\u8c03\u7528callback(\u56de\u8c03\u51fd\u6570)\u51fd\u6570\u76f4\u63a5\u62ff\u5230\u5524\u9192\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u4e0d\u9700\u8981\u8f6e\u8be2\uff0c\u6548\u7387\u9ad8\u3002\u673a\u5236\uff0c\u5c06\u65b0\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u63cf\u8ff0\u7b26\u589e\u52a0\u5230\u63cf\u8ff0\u7b26\u8868\u4e2d\uff0c\u53ea\u9700\u8981\u4e00\u4e2a\u7ebf\u7a0b\u5373\u53ef\u5904\u7406\u6240\u6709\u7684\u5ba2\u6237\u7aef\u8fde\u63a5\uff0c\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u4e2d\u5e94\u7528\u5e7f\u6cdb\uff0c\u4e0d\u8fc7\u4ee3\u7801\u5199\u8d77\u6765\u7a0d\u663e\u7e41\u7410\u3002\u76d1\u542c\u7684\u6700\u5927\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6ca1\u6709\u4e2a\u6570\u9650\u5236\uff08\u7406\u8bba\u4e0a\uff0c\u53d6\u51b3\u4e0e\u4f60\u81ea\u5df1\u7684\u7cfb\u7edf\uff09\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/19809.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T18:22:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418182234-6802986aec0a1.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/19809.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/19809.html\",\"name\":\"\u7f51\u7f16\uff08\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T18:22:36+00:00\",\"dateModified\":\"2025-04-18T18:22:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/19809.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/19809.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/19809.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7f51\u7f16\uff08\u670d\u52a1\u5668\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7f51\u7f16\uff08\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/19809.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7f51\u7f16\uff08\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb807\u6b21\uff0c\u70b9\u8d5e18\u6b21\uff0c\u6536\u85cf6\u6b21\u3002(\u6839\u636epoll\u51fd\u6570\u7b2c\u4e00\u4e2a\u53c2\u6570\u6765\u5b9a\uff0c\u5982\u679c\u76d1\u542c\u7684\u4e8b\u4ef6\u4e3a1\u4e2a\uff0c\u5219\u7ed3\u6784\u4f53\u6570\u7ec4\u5143\u7d20\u4e2a\u6570\u4e3a1\uff0c\u5982\u679c\u60f3\u76d1\u542c100\u4e2a\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u5143\u7d20\u4e2a\u6570\u5c31\u4e3a100\uff0c\u7531\u7a0b\u5e8f\u5458\u81ea\u5df1\u6765\u51b3\u5b9a)\u5f02\u6b65I\/O\uff0cEpoll\u5f53\u6709\u4e8b\u4ef6\u4ea7\u751f\u88ab\u5524\u9192\u4e4b\u540e\uff0c\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3b\u52a8\u8c03\u7528callback(\u56de\u8c03\u51fd\u6570)\u51fd\u6570\u76f4\u63a5\u62ff\u5230\u5524\u9192\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u4e0d\u9700\u8981\u8f6e\u8be2\uff0c\u6548\u7387\u9ad8\u3002\u673a\u5236\uff0c\u5c06\u65b0\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\u63cf\u8ff0\u7b26\u589e\u52a0\u5230\u63cf\u8ff0\u7b26\u8868\u4e2d\uff0c\u53ea\u9700\u8981\u4e00\u4e2a\u7ebf\u7a0b\u5373\u53ef\u5904\u7406\u6240\u6709\u7684\u5ba2\u6237\u7aef\u8fde\u63a5\uff0c\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u4e2d\u5e94\u7528\u5e7f\u6cdb\uff0c\u4e0d\u8fc7\u4ee3\u7801\u5199\u8d77\u6765\u7a0d\u663e\u7e41\u7410\u3002\u76d1\u542c\u7684\u6700\u5927\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u6ca1\u6709\u4e2a\u6570\u9650\u5236\uff08\u7406\u8bba\u4e0a\uff0c\u53d6\u51b3\u4e0e\u4f60\u81ea\u5df1\u7684\u7cfb\u7edf\uff09","og_url":"https:\/\/www.wsisp.com\/helps\/19809.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T18:22:36+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418182234-6802986aec0a1.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/19809.html","url":"https:\/\/www.wsisp.com\/helps\/19809.html","name":"\u7f51\u7f16\uff08\u670d\u52a1\u5668\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T18:22:36+00:00","dateModified":"2025-04-18T18:22:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/19809.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/19809.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/19809.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7f51\u7f16\uff08\u670d\u52a1\u5668\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/19809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=19809"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/19809\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/19808"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=19809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=19809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=19809"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=19809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}