{"id":96601,"date":"2026-08-28T00:24:42","date_gmt":"2026-08-27T16:24:42","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/96601.html"},"modified":"2026-08-28T00:24:42","modified_gmt":"2026-08-27T16:24:42","slug":"%e5%85%b1%e4%ba%ab%e5%86%85%e5%ad%98%e7%9a%84%e7%bd%91%e7%bb%9c%e8%81%8a%e5%a4%a9%e5%ae%a4","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/96601.html","title":{"rendered":"\u5171\u4eab\u5185\u5b58\u7684\u7f51\u7edc\u804a\u5929\u5ba4"},"content":{"rendered":"<h2>\u5f15\u8a00<\/h2>\n<p>\u672c\u7bc7\u53c2\u8003\u4e66\u76ee\u300aLinux\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u7f16\u7a0b\u300b&#xff0c;\u8fd9\u662f\u6211\u7b2c\u4e09\u6b21\u5b9e\u73b0\u7f51\u7edc\u804a\u5929\u5ba4&#xff0c;\u8fd9\u4e00\u6b21\u662f\u5728\u5185\u5b58\u7684\u65b9\u9762\u8fdb\u884c\u4e86\u6781\u5927\u7684\u6539\u8fdb&#xff0c;\u5e76\u4e14\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f7f\u7528c&#043;&#043;11\u6765\u5b9e\u73b0\u7684&#xff0c;\u5c06\u4e66\u672c\u91cc\u9762\u7684c\u8bed\u8a00\u91cd\u5199\u4e86\u4e00\u904d\u3002<\/p>\n<p>\u4ee3\u7801\u5df2\u7ecf\u4e0a\u4f20\u5230\u4e86github\u4e0a\u9762&#xff0c;fengyue05\/Linux-: \u672c\u4ed3\u5e93\u91cc\u9762\u4f1a\u6709\u5173\u4e8e\u300aLinux\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u7f16\u7a0b\u300b\u7684\u4e00\u4e9b\u4e3b\u8981\u4ee3\u7801\u5b9e\u73b0<\/p>\n<h2>\u4ee3\u7801<\/h2>\n<p>\u5728\u5f00\u59cb\u771f\u6b63\u4ee3\u7801\u7684\u5b9e\u73b0\u524d\u9762&#xff0c;\u6211\u4eec\u9700\u8981\u51c6\u5907\u4e00\u4e9b\u53d8\u91cf&#xff0c;\u9996\u5148\u662f\u7f13\u5b58\u7684\u5927\u5c0f&#xff0c;\u7528\u6237\u7684\u9650\u5236&#xff0c;\u4e8b\u4ef6\u7684\u9650\u5236&#xff0c;\u8fdb\u7a0b\u6570\u91cf\u7684\u9650\u5236\u3002\u6211\u4eec\u8fd9\u91cc\u4e3b\u8981\u662f\u901a\u8fc7\u4e3b\u8fdb\u7a0b\u6765\u63a5\u53d7\u8fde\u63a5&#xff0c;\u5e7f\u64ad\u6d88\u606f&#xff0c;\u5176\u5b9e\u76f8\u5f53\u4e8e\u6211\u4eec\u7684\u670d\u52a1\u5668\u7aef&#xff0c;\u800c\u4e3b\u8fdb\u7a0b\u521b\u5efa\u51fa\u6765\u7684\u5b50\u8fdb\u7a0b\u4f5c\u7528\u662f\u548c\u5ba2\u6237\u7aef\u8fde\u63a5\u3002\u6240\u4ee5\u6211\u4eec\u5ba2\u6237\u7aef\u7684\u6570\u636e\u7ed3\u6784\u4f53\u91cc\u9762\u5305\u542b\u4e86\u5176\u5730\u5740&#xff0c;\u5bf9\u5e94\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u5bf9\u5e94\u7684\u8fdb\u7a0b&#xff0c;\u8fd8\u6709\u6700\u91cd\u8981\u7684\u5c31\u662f\u4e00\u4e2a\u7ba1\u9053&#xff0c;\u6211\u4eec\u7684\u5b50\u8fdb\u7a0b\u53ea\u80fd\u548c\u7236\u8fdb\u7a0b\u901a\u4fe1&#xff0c;\u6240\u4ee5\u6211\u4eec\u901a\u8fc7\u7ba1\u9053\u6765\u901a\u4fe1&#xff0c;\u6211\u4eec\u901a\u8fc7socketpair\u628a\u7ba1\u9053\u4e24\u8fb9\u5c01\u88c5socket&#xff0c;\u7136\u540e\u7236\u8fdb\u7a0b\u4f7f\u7528pipefd[0]&#xff0c;\u5b50\u8fdb\u7a0b\u4f7f\u7528pipefd[1]<\/p>\n<p>\u7136\u540e\u7236\u8fdb\u7a0b\u4f5c\u4e3a\u670d\u52a1\u5668\u8fd8\u9700\u8981\u5904\u7406\u4fe1\u53f7\u7684\u5230\u6765&#xff0c;\u8fd9\u91cc\u6211\u4eec\u4e5f\u4f7f\u7528\u7ba1\u9053\u6765\u901a\u4fe1\u5904\u7406\u3002\u6700\u540e\u6211\u4eec\u662f\u901a\u8fc7\u5171\u4eab\u5185\u5b58\u7684\u65b9\u5f0f\u8fdb\u884c\u4fe1\u606f\u7684\u4ea4\u6d41&#xff0c;\u9700\u8981\u4e00\u4e2a\u6307\u9488\u3002<\/p>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u6211\u4eec\u7684\u4ee3\u7801&#xff0c;\u6211\u4eec\u7279\u610f\u5f00\u8f9f\u4e86\u4e24\u4e2a\u6570\u7ec4&#xff0c;\u4e00\u4e2a\u6570\u7ec4\u662f\u5b58\u7528\u6237\u7684\u6570\u636e&#xff0c;\u4e00\u4e2a\u6570\u7ec4\u662f\u5b58\u8fdb\u7a0b&#xff0c;\u65b9\u4fbf\u540e\u9762\u4f7f\u7528\u3002<\/p>\n<p>\u6700\u540e\u6211\u4eec\u9700\u8981\u5f3a\u8c03\u4e00\u4e2avolatile&#xff0c;\u8fd9\u4e2a\u53d8\u91cf\u7684\u503c\u53ef\u80fd\u5728\u7a0b\u5e8f\u201c\u770b\u4e0d\u5230\u7684\u5730\u65b9\u201d\u88ab\u6539\u53d8&#xff0c;\u6240\u4ee5\u6bcf\u6b21\u4f7f\u7528\u5b83\u65f6&#xff0c;\u90fd\u5e94\u8be5\u91cd\u65b0\u4ece\u5185\u5b58\u8bfb\u53d6&#xff0c;\u4e0d\u8981\u8fc7\u5ea6\u4f18\u5316\u3002<\/p>\n<p>sig_atomic_t \u5f3a\u8c03\u7684\u662f\u539f\u5b50\u6027&#xff0c;\u7279\u522b\u662f\u4e0d\u4f1a\u88ab\u4fe1\u53f7\u6253\u65ad\u3002<\/p>\n<p>constexpr int USER_LIMIT &#061; 5;<br \/>\nconstexpr int BUFFER_SIZE &#061; 1024;<br \/>\nconstexpr int FD_LIMIT &#061; 65535;<br \/>\nconstexpr int MAX_EVENT_NUMBER &#061; 1024;<br \/>\nconstexpr int PROCESS_LIMIT &#061; 65535;<br \/>\nconstexpr const char* SHM_NAME &#061; &#034;\/my_shm&#034;;<\/p>\n<p>struct ClientData {<br \/>\n    sockaddr_in address;<br \/>\n    int connfd;<br \/>\n    pid_t pid; \/\/ \u5904\u7406\u8fd9\u4e2a\u8fde\u63a5\u7684\u5b50\u8fdb\u7a0b\u7684PID<br \/>\n    std::array&lt;int, 2&gt; pipefd; \/\/ \u548c\u7236\u8fdb\u7a0b\u901a\u4fe1\u7684\u7ba1\u9053<br \/>\n};<\/p>\n<p>std::array&lt;int, 2&gt; m_signalPipe{{-1, -1}};<br \/>\nint m_epollfd &#061; -1;<br \/>\nint m_listened &#061; -1;<br \/>\nchar* m_sharedMemory &#061; nullptr;<\/p>\n<p>\/\/ \u5ba2\u6237\u8fde\u63a5\u6570\u7ec4\u3002\u8fdb\u7a0b\u7528\u5ba2\u6237\u8fde\u63a5\u7684\u7f16\u53f7\u6765\u7d22\u5f15\u8fd9\u4e2a\u6570\u7ec4&#xff0c;\u5373\u53ef\u53d6\u5f97\u76f8\u5173\u7684\u5ba2\u6237\u8fde\u63a5\u6570\u636e<br \/>\nstd::array&lt;ClientData, USER_LIMIT &#043; 1&gt; m_users;<br \/>\nstd::array&lt;int, PROCESS_LIMIT&gt; m_subProcess;<br \/>\nint m_userCount &#061; 0;<\/p>\n<p>\/\/ \u5f53\u7a0b\u5e8f\u6b63\u5728\u6b63\u5e38\u6267\u884c\u65f6&#xff0c;\u5373\u4f7f\u7a81\u7136\u88ab\u4fe1\u53f7\u6253\u65ad&#xff0c;\u8bfb\u53d6\u6216\u5199\u5165\u8fd9\u4e2a\u53d8\u91cf\u4e5f\u4e0d\u4f1a\u51fa\u73b0\u201c\u5199\u5230\u4e00\u534a\u201d\u7684\u60c5\u51b5\u3002<br \/>\nvolatile sig_atomic_t m_stopChild &#061; 0; <\/p>\n<p>\u63a5\u4e0b\u6765\u662f\u4e00\u4e2a\u6bd4\u8f83\u5e38\u89c4\u7684\u64cd\u4f5c&#xff1a;&#xff08;\u5982\u679c\u6709\u7591\u95ee&#xff0c;\u53ef\u4ee5\u770b\u4e00\u4e0b\u6211\u4e4b\u524d\u7684\u535a\u5ba2&#xff09;<\/p>\n<p>int setNoBlocking(int fd) {<br \/>\n    const int old_option &#061; ::fcntl(fd, F_GETFL);<br \/>\n    const int new_option &#061; old_option | O_NONBLOCK;<br \/>\n    fcntl(fd, F_SETFL, new_option);<br \/>\n    return old_option;<br \/>\n}<\/p>\n<p>void addFd (int epollfd, int fd) {<br \/>\n    epoll_event event;<br \/>\n    event.data.fd &#061; fd;<br \/>\n    event.events &#061; EPOLLIN | EPOLLET;<br \/>\n    assert(::epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &amp;event) !&#061; -1);<br \/>\n    setNoBlocking(fd);<br \/>\n}<\/p>\n<p>void removeFd(int epollfd, int fd) {<br \/>\n    if (fd &lt; 0) {<br \/>\n        return;<br \/>\n    }<br \/>\n    ::epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, nullptr);<br \/>\n    ::close(fd);<br \/>\n}<\/p>\n<p>void signalHandler(int sig) {<br \/>\n    const int saveErrno &#061; errno;<br \/>\n    const char message &#061; static_cast&lt;char&gt;(sig);<br \/>\n    ::send(m_signalPipe[1], &amp;message, 1, 0);<br \/>\n    errno &#061; saveErrno;<br \/>\n}<\/p>\n<p>void addSignal (int sig, void (*handler)(int), bool restart &#061; true) {<br \/>\n    struct sigaction sa;<br \/>\n    sa.sa_handler &#061; handler;<br \/>\n    if (restart) {<br \/>\n        sa.sa_flags &#061; SA_RESTART;<br \/>\n    }<br \/>\n    ::sigfillset(&amp;sa.sa_mask);<br \/>\n    assert (::sigaction(sig, &amp;sa, nullptr) !&#061; -1);<br \/>\n}<\/p>\n<p>\/\/ \u505c\u6b62\u4e00\u4e2a\u5b50\u8fdb\u7a0b<br \/>\nvoid childTermHandler(int) {<br \/>\n    m_stopChild &#061; 1;<br \/>\n}<\/p>\n<p>void closeFd(int&amp; fd) {<br \/>\n    if (fd &gt;&#061; 0) {<br \/>\n        ::close(fd);<br \/>\n        fd &#061; -1;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd9\u4e2a\u51fd\u6570\u662f\u4e3b\u8fdb\u7a0b\u91cc\u9762\u6700\u540e\u9500\u6bc1\u6240\u6709\u5185\u5b58\u7684\u51fd\u6570&#xff0c;\u9996\u5148\u6211\u4eec\u9700\u8981\u5173\u95ed\u6240\u6709\u5b58\u50a8\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26&#xff0c;\u5176\u5b9e\u4e3b\u8981\u5c31\u662f\u5173\u95ed[0]\u53f7\u7ba1\u9053&#xff0c;\u56e0\u4e3a\u4e3b\u8fdb\u7a0b\u53ea\u9760[0]\u53f7\u7ba1\u9053\u6765\u548c\u5bf9\u5e94\u7684\u8fdb\u7a0b\u901a\u4fe1&#xff0c;\u800c[1]\u53f7\u7ba1\u9053\u662f\u5728\u8fdb\u7a0b\u521b\u5efa\u7684\u65f6\u5019\u5c31\u5728\u4e3b\u8fdb\u7a0b\u91cc\u9762\u5173\u95ed\u4e86\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u91cd\u8981\u7684\u5c31\u662f\u6211\u4eec\u91ca\u653e\u5171\u4eab\u5185\u5b58\u7684\u51fd\u6570munmap&#xff0c;\u8fd9\u4e2a\u548cmmap\u662f\u4e00\u5bf9\u51fd\u6570&#xff0c;\u4e00\u4e2a\u662f\u521b\u5efa\u5171\u4eab\u5185\u5b58&#xff0c;\u4e00\u4e2a\u662f\u91ca\u653e\u5185\u5b58\u3002<\/p>\n<p>\u6700\u540e\u56e0\u4e3a\u6211\u4eec\u662f\u901a\u8fc7shm_open\u6253\u5f00POSIX\u5171\u4eab\u5185\u5b58\u7684\u5bf9\u8c61&#xff0c;\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5173\u95edunlink<\/p>\n<p>void cleanResouces() {<br \/>\n    for (int i &#061; 0; i &lt; m_userCount; i&#043;&#043;) {<br \/>\n        \/\/ \u662f\u5728\u7236\u8fdb\u7a0b\u4e2d\u6267\u884c\u7684&#xff0c;\u800c\u7236\u8fdb\u7a0b\u4fdd\u5b58\u7684\u662f\u6bcf\u4e2a socketpair \u7684 pipefd[0]&#xff08;\u4e0e\u5bf9\u5e94\u5b50\u8fdb\u7a0b\u901a\u4fe1&#xff09;<br \/>\n        closeFd(m_users[i].pipefd[0]);<br \/>\n    }<\/p>\n<p>    closeFd(m_signalPipe[0]);<br \/>\n    closeFd(m_signalPipe[1]);<br \/>\n    closeFd(m_listened);<br \/>\n    closeFd(m_epollfd);<\/p>\n<p>    if (m_sharedMemory !&#061; nullptr &amp;&amp; m_sharedMemory !&#061; MAP_FAILED) {<br \/>\n        ::munmap(m_sharedMemory, USER_LIMIT * BUFFER_SIZE);<br \/>\n        m_sharedMemory &#061; nullptr;<br \/>\n    }<br \/>\n    ::shm_unlink(SHM_NAME);<br \/>\n} <\/p>\n<p>\u6211\u4eec\u5b50\u8fdb\u7a0b\u7684\u4f5c\u7528\u662f\u548c\u5ba2\u6237\u7aef\u5efa\u7acb\u8054\u7cfb\u5e76\u4e14\u901a\u4fe1&#xff0c;\u6240\u4ee5\u6211\u4eec\u6709\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u4e13\u95e8\u8fd0\u884c\u7684\u51fd\u6570\u3002\u6211\u4eec\u4f20\u5165\u7684\u53c2\u6570\u662f\u5ba2\u6237\u7aef\u5bf9\u5e94\u7684index&#xff0c;\u4ece\u800c\u901a\u8fc7\u6211\u4eec\u5b58\u50a8\u7684\u6570\u636e\u7d22\u5f15index&#xff0c;\u627e\u5230\u5bf9\u5e94\u7684socket\u7b49\u3002\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u6709\u4e00\u4e2aepollfd&#xff0c;\u56e0\u4e3a\u8fd9\u4e2a\u662f\u4e13\u95e8\u548c\u7528\u6237\u8fdb\u884c\u76d1\u542c\u7684&#xff0c;\u540c\u65f6\u52a0\u5165\u4e86\u4e00\u4e2a\u9000\u51fa\u7684\u4fe1\u53f7&#xff0c;\u4ee5\u4fbf\u540e\u9762\u7ec8\u7aef\u7684\u9000\u51fa\u3002<\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6765\u8bf4&#xff0c;\u7ee7\u627f\u4e86\u7236\u8fdb\u7a0b\u7684\u8d44\u6e90&#xff0c;\u6240\u4ee5\u4e5f\u4f1a\u6709users\u7684\u6570\u636e<\/p>\n<p>\u5728while&#xff08;&#xff09;\u5faa\u73af\u91cc\u9762&#xff0c;\u5f53\u76d1\u542c\u5230\u4e86\u4e8b\u4ef6\u4e4b\u540e&#xff0c;\u5faa\u73af\u5904\u7406\u6bcf\u4e00\u4e2a\u4e8b\u4ef6&#xff0c;\u6211\u4eec\u5bf9\u6bcf\u4e00\u4e2a\u4e8b\u4ef6\u6709\u5206\u7c7b\u5904\u7406&#xff1a;<\/p>\n<p>\u5f53\u4e8b\u4ef6\u7684sockfd\u548c\u5b58\u50a8\u7684connfd\u76f8\u540c\u7684\u65f6\u5019&#xff0c;\u5c31\u8bf4\u660e\u662f\u8be5\u8fdb\u7a0b\u5bf9\u5e94\u7684\u5ba2\u6237\u6765\u6d88\u606f\u4e86&#xff0c;\u8fd9\u4e2a\u65f6\u5019\u5c31\u8981recv\u6d88\u606f&#xff0c;\u4e0d\u8fc7\u6211\u4eec\u662f\u4e00\u4e2a\u5171\u4eab\u5185\u5b58&#xff0c;\u6240\u4ee5\u6211\u4eec\u4e0d\u662f\u5f00\u8f9f\u5185\u5b58&#xff0c;\u800c\u662f\u76f4\u63a5\u5229\u7528\u5171\u4eab\u5185\u5b58&#xff0c;\u6bcf\u4e2a\u8fdb\u7a0b\u5bf9\u5e94\u7684\u5171\u4eab\u5185\u5b58\u7684\u5730\u65b9\u662f\u786e\u5b9a\u7684&#xff0c;\u5730\u5740\u662fm_sharedMemory &#043; index * BUFFER_SIZE&#xff0c;\u7136\u540e\u628a\u63a5\u53d7\u5230\u7684\u6570\u636e\u653e\u5728\u8fd9\u91cc\u9762\u3002\u5728\u63a5\u53d7\u5b8c\u4fe1\u606f\u4e86\u4e4b\u540e&#xff0c;\u53d1\u9001\u6d88\u606f\u7ed9\u4e3b\u8fdb\u7a0b&#xff08;\u670d\u52a1\u5668\u7aef&#xff09;&#xff0c;send\u7684\u662fclient\u7684\u7f16\u53f7&#xff0c;\u8fd9\u6837\u5b50\u4e3b\u8fdb\u7a0b&#xff08;\u670d\u52a1\u5668\u7aef&#xff09;\u5c31\u53ef\u4ee5\u77e5\u9053\u662f\u54ea\u4e00\u4e2a\u8fdb\u7a0b&#xff08;\u4e5f\u5c31\u662f\u5bf9\u5e94\u7684\u5ba2\u6237\u7aef&#xff09;\u3002\u53ef\u80fd\u6709\u4eba\u4f1a\u7591\u95ee&#xff0c;\u90a3\u4e3a\u4ec0\u4e48\u4e0d\u53d1\u9001\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u7684\u6d88\u606f\u5462&#xff1f;\u539f\u56e0\u5c31\u662f\u8fd9\u4e2a\u662f\u5171\u4eab\u5185\u5b58&#xff0c;\u6211\u4eec\u53ea\u9700\u8981\u77e5\u9053\u53d1\u6d88\u606f\u5bf9\u5e94\u8fdb\u7a0b\u6240\u5c5e\u7684\u5730\u5740&#xff0c;\u8fd9\u4e2a\u6837\u5b50\u76f4\u63a5\u53ef\u4ee5\u53d6\u6570\u636e\u4e86&#xff0c;\u6240\u4ee5\u6211\u4eec\u4f20\u9012\u7684\u90fd\u662findex\u3002<\/p>\n<p>\u5f53\u4e8b\u4ef6\u7684sockfd\u548c\u7236\u8fdb\u7a0b\u901a\u4fe1\u7684\u7ba1\u9053\u4e00\u6837\u7684\u65f6\u5019&#xff0c;\u8bf4\u660e\u662f\u63a5\u6536\u5230\u4e86\u7236\u8fdb\u7a0b\u7684\u6d88\u606f&#xff0c;\u4e5f\u5c31\u662f\u5e7f\u64ad&#xff0c;\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u63a5\u53d7\u5230\u4e86client\u7684index&#xff0c;\u7136\u540e\u5c31\u53ef\u4ee5\u627e\u5230\u5bf9\u5e94\u7684\u5171\u4eab\u5185\u5b58\u4f4d\u7f6e&#xff0c;\u7136\u540e\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\/\/ \u5b50\u8fdb\u7a0b\u8fd0\u884c\u7684\u51fd\u6570&#xff0c;\u53c2\u6570index\u6307\u51fa\u8be5\u5b50\u8fdb\u7a0b\u5904\u7406\u7684\u5ba2\u6237\u8fde\u63a5\u7684\u7f16\u53f7<br \/>\nvoid runChild(int index) {<br \/>\n    std::array&lt;epoll_event, MAX_EVENT_NUMBER&gt; events;<br \/>\n    const int childEpollfd &#061; ::epoll_create(1);<br \/>\n    assert(childEpollfd !&#061; -1);<\/p>\n<p>    const int connfd &#061; m_users[index].connfd;<br \/>\n    const int pipefd &#061; m_users[index].pipefd[1]; \/\/ \u5b50\u8fdb\u7a0b\u7684socket<\/p>\n<p>    addSignal(SIGTERM, childTermHandler, false);<\/p>\n<p>    while(!m_stopChild) {<br \/>\n        const int number &#061; ::epoll_wait(childEpollfd, events.data(), MAX_EVENT_NUMBER, -1);<\/p>\n<p>        if (number &lt; 0 &amp;&amp; errno !&#061; EINTR) {<br \/>\n            std::cerr &lt;&lt; &#034;child epoll_wait failed:&#034; &lt;&lt; std::strerror(errno) &lt;&lt; std::endl;<br \/>\n            break;<br \/>\n        }<\/p>\n<p>        for (int i &#061; 0; i &lt; number; i&#043;&#043;) {<br \/>\n            const int sockfd &#061; events[i].data.fd;<br \/>\n            \/\/ \u672c\u5b50\u8fdb\u7a0b\u8d1f\u8d23\u7684\u5ba2\u6237\u8fde\u63a5\u6709\u6570\u636e\u5230\u8fbe&#xff0c;\u5199\u5230\u672c\u5ba2\u6237\u7aef\u5bf9\u5e94\u7684\u5171\u4eab\u5185\u5b58\u64cd\u4f5c<br \/>\n            \/\/ \u518d\u628a\u5ba2\u6237\u7f16\u53f7\u901a\u77e5\u7ed9\u7236\u8fdb\u7a0b<br \/>\n            if (sockfd &#061;&#061; connfd &amp;&amp; (events[i].events &amp; EPOLLIN)) {<br \/>\n                char* buffer &#061; m_sharedMemory &#043; index * BUFFER_SIZE;<br \/>\n                std::memset(buffer, 0, BUFFER_SIZE);<\/p>\n<p>                int received &#061; ::recv(connfd, buffer, BUFFER_SIZE &#8211; 1, 0);<br \/>\n                if (received &lt; 0) {<br \/>\n                    if (errno !&#061; EAGAIN &amp;&amp; errno !&#061; EWOULDBLOCK) {<br \/>\n                        m_stopChild &#061; 1;<br \/>\n                    }<br \/>\n                }<br \/>\n                else if(received &#061;&#061; 0) {<br \/>\n                    m_stopChild &#061; 1;<br \/>\n                }<br \/>\n                else {<br \/>\n                    \/\/ \u4f20\u9012\u7b2c\u51e0\u4e2a\u5ba2\u6237<br \/>\n                    ::send(pipefd, &amp;index, sizeof(index), 0);<br \/>\n                }<br \/>\n            }<br \/>\n            \/\/ \u7236\u8fdb\u7a0b\u901a\u77e5\u672c\u8fdb\u7a0b&#xff08;\u901a\u8fc7\u7ba1\u9053&#xff09;\u5c06\u7b2cclient\u4e2a\u5ba2\u6237\u7684\u6570\u636e\u53d1\u9001\u5230\u672c\u8fdb\u7a0b\u8d1f\u8d23\u7684\u5ba2\u6237\u7aef<br \/>\n            else if (sockfd &#061;&#061; pipefd &amp;&amp; (events[i].events &amp; EPOLLIN)) {<br \/>\n                int client &#061; -1;<br \/>\n                int received &#061; ::recv(pipefd, &amp;client, sizeof(client), 0);<\/p>\n<p>                if (received &lt; 0) {<br \/>\n                    if (errno !&#061; EAGAIN &amp;&amp; errno !&#061; EWOULDBLOCK) {<br \/>\n                        m_stopChild &#061; 1;<br \/>\n                    }<br \/>\n                }<br \/>\n                else if(received &#061;&#061; 0) {<br \/>\n                    m_stopChild &#061; 1;<br \/>\n                }<br \/>\n                else if (received &#061;&#061; static_cast&lt;ssize_t&gt;(sizeof(client)) &amp;&amp; client &gt;&#061; 0 &amp;&amp; client &lt; USER_LIMIT) {<br \/>\n                    \/\/ \u76f4\u63a5\u4f7f\u7528\u5171\u4eab\u5185\u5b58&#xff0c;\u53d1\u9001\u7ed9\u5bf9\u5e94\u7684\u5ba2\u6237\u7aef<br \/>\n                    ::send(connfd, m_sharedMemory &#043; client * BUFFER_SIZE, BUFFER_SIZE, 0);<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    ::close(connfd);<br \/>\n    ::close(pipefd);<br \/>\n    ::close(childEpollfd);<br \/>\n} <\/p>\n<p>\u5f53\u5ba2\u6237\u7aef\u5173\u95ed\u4e86\u4e4b\u540e&#xff0c;\u6211\u4eec\u5220\u9664\u5ba2\u6237\u7aef\u7684\u4e00\u5207\u6570\u636e\u3002\u8fd9\u4e2a\u662f\u5728\u7236\u8fdb\u7a0b\u91cc\u9762\u8c03\u7528\u7684&#xff0c;\u6240\u4ee5\u8981\u79fb\u9664\u4e0e\u5b50\u8fdb\u7a0b\u7684\u901a\u4fe1socket\u3002\u5e76\u4e14\u6211\u4eec\u7684\u6570\u7ec4\u6392\u5217\u4e00\u5b9a\u8981\u662f\u8fde\u7eed\u7684&#xff0c;\u5426\u5219\u591a\u6b21\u5173\u95ed\u8fde\u63a5\u4e4b\u540e\u4f1a\u6d6a\u8d39\u5f88\u591a\u7684\u5185\u5b58\u3002\u6240\u4ee5\u5f53\u6211\u4eec\u5220\u9664\u4e86\u4e2d\u95f4\u4e00\u4e2aindex&#xff0c;\u90a3\u4e48\u6211\u4eec\u8981\u628a\u6700\u540e\u4e00\u4e2a\u586b\u8865\u5230\u6211\u4eec\u5220\u9664\u7684\u5730\u65b9&#xff0c;\u5305\u62ecpid<\/p>\n<p>void eraseUser (int index) {<br \/>\n    if (index &lt; 0 || index &gt;&#061; m_userCount) {<br \/>\n        return;<br \/>\n    }<\/p>\n<p>    \/\/ \u79fb\u9664\u7236\u8fdb\u7a0b\u4e3a\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u4fdd\u7559\u7684\u901a\u4fe1\u7ba1\u9053<br \/>\n    removeFd(m_epollfd, m_users[index].pipefd[0]);<\/p>\n<p>    const int last &#061; m_userCount &#8211; 1;<br \/>\n    if (index !&#061; last) {<br \/>\n        m_users[index] &#061; m_users[last];<br \/>\n        const pid_t movedPid &#061; m_users[index].pid;<br \/>\n        if (movedPid &gt;&#061; 0 &amp;&amp; movedPid &lt; PROCESS_LIMIT) {<br \/>\n            m_subProcess[static_cast&lt;int&gt;(movedPid)] &#061; index;<br \/>\n        }<br \/>\n    }<br \/>\n    m_userCount&#8211;;<br \/>\n} <\/p>\n<p>\u5bf9\u4e8e\u5171\u4eab\u5185\u5b58&#xff0c;\u6211\u4eec\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\u5c31\u662f&#xff1a;<\/p>\n<p>\u5148shm_open\u6253\u5f00\u5171\u4eab\u5185\u5b58\u7684\u5bf9\u8c61&#xff0c;\u5176\u8fd4\u56de\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5f88\u5173\u952e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\u91cd\u6784\u5185\u5b58\u7684\u5927\u5c0f&#xff0c;\u901a\u8fc7ftruncate&#xff08;&#xff09;\u51fd\u6570&#xff0c;\u6700\u540e\u901a\u8fc7mmap&#xff08;&#xff09;\u521b\u5efa\u6211\u4eec\u7684\u5171\u4eab\u5185\u5b58\u5e76\u8fd4\u56de\u8fd9\u5757\u5185\u5b58\u7684\u6307\u9488\u3002\u4e00\u5207\u7ed3\u675f\u4e86\u4e4b\u540e\u5c31\u53ef\u4ee5\u5173\u95ed\u8fd9\u4e2a\u6253\u5f00\u5171\u4eab\u5185\u5b58\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26<\/p>\n<p>    std::array&lt;epoll_event, MAX_EVENT_NUMBER&gt; events;<br \/>\n    m_epollfd &#061; epoll_create(1);<br \/>\n    assert(m_epollfd &#061;&#061; -1);<br \/>\n    addFd(m_epollfd, m_listened);<\/p>\n<p>    assert (::socketpair(AF_UNIX, SOCK_STREAM, 0, m_signalPipe.data()));<br \/>\n    setNoBlocking(m_signalPipe[1]);<br \/>\n    addFd(m_epollfd, m_signalPipe[0]);<\/p>\n<p>    addSignal(SIGCHLD, signalHandler);<br \/>\n    addSignal(SIGTERM, signalHandler);<br \/>\n    addSignal(SIGINT, signalHandler);<br \/>\n    addSignal(SIGPIPE, SIG_IGN);<\/p>\n<p>    bool stopServer &#061; false;<br \/>\n    bool terminating &#061; false;<\/p>\n<p>    const int shmfd &#061; ::shm_open(SHM_NAME, O_CREAT | O_RDWR, 0666);<br \/>\n    assert(shmfd !&#061; -1);<br \/>\n    \/\/ \u901a\u8fc7\u6587\u4ef6\u63cf\u8ff0\u7b26\u4fee\u6539\u6587\u4ef6\u6216\u5171\u4eab\u5185\u5b58\u5bf9\u8c61\u7684\u5927\u5c0f<br \/>\n    assert(::ftruncate(shmfd, USER_LIMIT * BUFFER_SIZE) !&#061; -1);<\/p>\n<p>    m_sharedMemory &#061; static_cast&lt;char*&gt;(::mmap(nullptr, USER_LIMIT * BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0));<br \/>\n    ::close(shmfd); <\/p>\n<p>\u5728while&#xff08;&#xff09;\u91cc\u9762&#xff0c;\u6211\u4eec\u89e3\u51b3\u7684\u5c31\u662f\u51e0\u4e2a\u95ee\u9898&#xff1a;<\/p>\n<p>1\u3001\u5982\u679c\u6709\u8fde\u63a5\u53d1\u6765&#xff0c;\u5b58\u50a8\u5bf9\u5e94\u7684\u6570\u636e&#xff0c;\u521b\u5efa\u5bf9\u5e94\u7684\u7ba1\u9053&#xff0c;\u7136\u540e\u521b\u5efa\u5bf9\u5e94\u7684\u5b50\u8fdb\u7a0b&#xff0c;\u5728\u5b50\u8fdb\u7a0b\u91cc\u9762\u53ea\u4fdd\u7559\u548c\u7236\u8fdb\u7a0b\u901a\u4fe1\u7684socket\u548c\u5ba2\u6237\u7aef\u901a\u4fe1\u7684socket&#xff0c;\u5176\u4ed6\u5168\u90e8\u5173\u95ed&#xff0c;\u5982\u679c\u7ed3\u675f\u4e86\u5b50\u8fdb\u7a0b&#xff0c;\u5c31\u8981munmap\u5176\u5171\u4eab\u5185\u5b58\u7684\u90e8\u5206\u3002\u800c\u7236\u8fdb\u7a0b\u8981\u505a\u7684\u4e8b\u60c5\u5c31\u662f\u5b58\u50a8\u5b50\u8fdb\u7a0b\u7684\u4fe1\u606f&#xff0c;\u4e0d\u8fc7\u6211\u4eec\u8fdb\u7a0b\u6570\u91cf\u90fd\u662f\u6709\u9650\u7684&#xff0c;\u6240\u4ee5\u5f53\u6211\u4eec\u521b\u5efa\u4e86\u5b50\u8fdb\u7a0b\u4e4b\u540e\u8981\u5224\u65ad\u5982\u679c\u8d85\u8fc7\u4e86\u8fd9\u4e2a\u4e0a\u9650&#xff0c;\u90a3\u4e48\u5c31\u8981\u5173\u95ed\u3002<\/p>\n<p>2\u3001\u5f53\u6709\u4fe1\u53f7\u5230\u6765\u7684\u65f6\u5019&#xff0c;\u5982\u679c\u662f\u5b50\u8fdb\u7a0b\u9000\u51fa\u7684\u4fe1\u53f7&#xff0c;\u7236\u8fdb\u7a0b\u975e\u963b\u585e\u56de\u6536&#xff0c;\u56e0\u4e3a\u6709\u4fe1\u53f7\u6765\u4e86\u4e00\u5b9a\u662f\u53ef\u4ee5\u56de\u6536\u7684&#xff0c;\u800c\u975e\u963b\u585e\u56de\u6536\u7684\u7279\u70b9\u5c31\u662f\u9ad8\u6548\u3002\u5982\u679c\u662f\u7236\u8fdb\u7a0b\u88ab\u5173\u95ed\u7684\u4fe1\u53f7\u6765\u4e86&#xff0c;\u90a3\u4e48\u8981\u5173\u95ed\u6240\u6709\u7684\u5b50\u8fdb\u7a0b\u3002<\/p>\n<p>3\u3001\u901a\u8fc7\u5e7f\u64ad\u53d1\u9001\u4fe1\u606f&#xff0c;\u5176\u5b9e\u5c31\u662f\u4f20\u9012\u5bf9\u5e94\u7684index&#xff0c;\u8ba9\u5b50\u8fdb\u7a0b\u91cc\u9762\u8fd0\u884c\u7684\u51fd\u6570\u63a5\u53d7index&#xff0c;\u81ea\u5df1\u8bfb\u53d6\u5171\u4eab\u5185\u5b58\u91cc\u9762\u7684\u6570\u636e\u3002<\/p>\n<p>    while (!stopServer) {<br \/>\n        const int number &#061; epoll_wait(m_epollfd, events.data(), MAX_EVENT_NUMBER, -1);<br \/>\n        if (number &lt; 0 &amp;&amp; errno !&#061; EINTR) {<br \/>\n            std::cerr &lt;&lt; &#034;epoll_wait failed: &#034;<br \/>\n                      &lt;&lt; std::strerror(errno) &lt;&lt; &#039;\\\\n&#039;;<br \/>\n            break;<br \/>\n        }<\/p>\n<p>        for (int i &#061; 0; i &lt; number; i&#043;&#043;) {<br \/>\n            const int sockfd &#061; events[i].data.fd;<br \/>\n            if (sockfd &#061;&#061; m_listened &amp;&amp; (events[i].events &amp; EPOLLIN)) {<br \/>\n                sockaddr_in clientAddress;<br \/>\n                socklen_t len &#061; sizeof(clientAddress);<br \/>\n                const int connfd &#061; ::accept(m_listened, (sockaddr*)&amp;clientAddress, &amp;len);<br \/>\n                if (connfd &lt; 0) {<br \/>\n                    if (errno !&#061; EAGAIN &amp;&amp; errno !&#061; EWOULDBLOCK) {<br \/>\n                        std::cerr &lt;&lt; &#034;accept failed:&#034; &lt;&lt; std::strerror(errno) &lt;&lt; std::endl;<br \/>\n                    }<br \/>\n                    continue;<br \/>\n                } <\/p>\n<p>                if (m_userCount &gt;&#061; USER_LIMIT) {<br \/>\n                    const std::string message &#061; &#034;too many users\\\\n&#034;;<br \/>\n                    std::cerr &lt;&lt; message;<br \/>\n                    ::send(connfd, message.data(), message.size(), 0);<br \/>\n                    ::close(connfd);<br \/>\n                    continue;<br \/>\n                }<\/p>\n<p>                const int index &#061; m_userCount;<br \/>\n                m_users[index].address &#061; clientAddress;<br \/>\n                m_users[index].connfd &#061; connfd;<br \/>\n                assert(::socketpair(AF_UNIX, SOCK_STREAM, 0, m_users[index].pipefd.data()) !&#061; -1);<\/p>\n<p>                const pid_t pid &#061; ::fork();<br \/>\n                \/\/ fork\u5931\u8d25\u5566<br \/>\n                if (pid &lt; 0) {<br \/>\n                    ::close(connfd);<br \/>\n                    ::close(m_users[index].pipefd[0]);<br \/>\n                    ::close(m_users[index].pipefd[1]);<br \/>\n                    continue;<br \/>\n                }<\/p>\n<p>                if (pid &#061;&#061; 0) {<br \/>\n                    ::close(m_epollfd);<br \/>\n                    ::close(m_listened);<br \/>\n                    ::close(m_users[index].pipefd[0]);<br \/>\n                    ::close(m_signalPipe[0]);<br \/>\n                    ::close(m_signalPipe[1]);<\/p>\n<p>                    runChild(index);<br \/>\n                    ::munmap(m_sharedMemory, USER_LIMIT * BUFFER_SIZE);<br \/>\n                    _exit(EXIT_SUCCESS);<br \/>\n                }<\/p>\n<p>                ::close(connfd);<br \/>\n                ::close(m_users[index].pipefd[1]);<br \/>\n                m_users[index].pipefd[1] &#061; -1;<br \/>\n                addFd (m_epollfd, m_users[index].pipefd[0]);<\/p>\n<p>                m_users[index].pid &#061; pid;<br \/>\n                if (pid &gt;&#061; PROCESS_LIMIT) {<br \/>\n                    std::cerr &lt;&lt; &#034;child PID exceeds PROCESS_LIMIT\\\\n&#034;;<br \/>\n                    ::kill(pid, SIGTERM);<br \/>\n                    removeFd(m_epollfd, m_users[index].pipefd[0]);<br \/>\n                    continue;<br \/>\n                }<br \/>\n                m_subProcess[static_cast&lt;int&gt;(pid)] &#061; index;<br \/>\n                m_userCount&#043;&#043;;<br \/>\n            }<br \/>\n            \/\/ \u7edf\u4e00\u4fe1\u53f7\u6e90&#xff0c;\u4ece\u4fe1\u53f7\u7ba1\u9053\u8bfb\u53d6\u4fe1\u53f7\u7f16\u53f7<br \/>\n            else if (sockfd &#061;&#061; m_signalPipe[0] &amp;&amp; (events[i].events &amp; EPOLLIN)) {<br \/>\n                std::array&lt;char, 1024&gt; signals;<br \/>\n                int received &#061; ::recv(m_signalPipe[0], signals.data(), signals.size(), 0);<br \/>\n                if (received &lt;&#061; 0) {<br \/>\n                    continue;<br \/>\n                }<\/p>\n<p>                for (int j &#061; 0; j &lt; received; j&#043;&#043;) {<br \/>\n                    switch (signals[j])<br \/>\n                    {<br \/>\n                    case SIGCHLD:<br \/>\n                        while(true) {<br \/>\n                            int status &#061; 0;<br \/>\n                            const pid_t pid &#061; ::waitpid(-1, &amp;status, WNOHANG);<br \/>\n                            if (pid &lt;&#061; 0) {<br \/>\n                                break;<br \/>\n                            }<br \/>\n                            if (pid &lt; PROCESS_LIMIT) {<br \/>\n                                const int index &#061; m_subProcess[pid];<br \/>\n                                m_subProcess[pid] &#061; -1;<br \/>\n                                eraseUser(index);<br \/>\n                            }<br \/>\n                        }<br \/>\n                        if (terminating &amp;&amp; m_userCount &#061;&#061; 0) {<br \/>\n                            stopServer &#061; true;<br \/>\n                        }<br \/>\n                        break;<br \/>\n                    case SIGTERM:<br \/>\n                    case SIGINT:<br \/>\n                        if (m_userCount &#061;&#061; 0) {<br \/>\n                            stopServer &#061; true;<br \/>\n                        }<br \/>\n                        else {<br \/>\n                            for (int k &#061; 0; k &lt; m_userCount; k&#043;&#043;) {<br \/>\n                                ::kill(m_users[k].pid, SIGTERM);<br \/>\n                            }<br \/>\n                            terminating &#061; true;<br \/>\n                        }<br \/>\n                        break;<br \/>\n                    default:<br \/>\n                        break;<br \/>\n                    }<br \/>\n                }<br \/>\n            }<br \/>\n            \/\/ \u67d0\u4e2a\u5b50\u8fdb\u7a0b\u5199\u5165\u4e86\u5171\u4eab\u5185\u5b58&#xff1b;\u901a\u8fc7\u5e7f\u64ad\u5e7f\u64ad\u7ed9\u5176\u4ed6\u5b50\u8fdb\u7a0b<br \/>\n            else if (events[i].events &amp; EPOLLIN) {<br \/>\n                int child &#061; -1;<br \/>\n                const int received &#061; ::recv(sockfd, &amp;child, sizeof(child), 0);<br \/>\n                if (received &lt;&#061; 0) {<br \/>\n                    continue;<br \/>\n                }<\/p>\n<p>                for (int j &#061; 0; j &lt; m_userCount; j&#043;&#043;) {<br \/>\n                    if (m_users[j].pipefd[0] &#061;&#061; sockfd) {<br \/>\n                        continue;<br \/>\n                    }<br \/>\n                    ::send(m_users[j].pipefd[0], &amp;child, sizeof(child), 0);<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n    cleanResouces(); <\/p>\n<p>\u6240\u4ee5\u5171\u4eab\u5185\u5b58\u7684\u804a\u5929\u5ba4\u6700\u5927\u7684\u4f18\u70b9\u5c31\u662f\u4e0d\u9700\u8981send\u4fe1\u606f&#xff0c;\u51cf\u5c11\u4e86\u62f7\u8d1d\u7684\u5f00\u9500&#xff0c;\u800c\u662f\u4ec5\u4ec5\u8bfb\u53d6\u5171\u4eab\u5185\u5b58\u7684\u6570\u636e&#xff0c;\u8fd9\u4e2a\u5bf9\u4e8e\u6027\u80fd\u6709\u5f88\u5927\u7684\u63d0\u9ad8\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u672c\u7bc7\u6587\u7ae0\u5230\u8fd9\u91cc\u5c31\u7ed3\u675f\u4e86&#xff01;&#xff01;&#xff01;\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5927\u5bb6\u7406\u89e3~~~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00<br \/>\n\u672c\u7bc7\u53c2\u8003\u4e66\u76ee\u300aLinux\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u7f16\u7a0b\u300b&#xff0c;\u8fd9\u662f\u6211\u7b2c\u4e09\u6b21\u5b9e\u73b0\u7f51\u7edc\u804a\u5929\u5ba4&#xff0c;\u8fd9\u4e00\u6b21\u662f\u5728\u5185\u5b58\u7684\u65b9\u9762\u8fdb\u884c\u4e86\u6781\u5927\u7684\u6539\u8fdb&#xff0c;\u5e76\u4e14\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f7f\u7528c11\u6765\u5b9e\u73b0\u7684&#xff0c;\u5c06\u4e66\u672c\u91cc\u9762\u7684c\u8bed\u8a00\u91cd\u5199\u4e86\u4e00\u904d\u3002<br \/>\n\u4ee3\u7801\u5df2\u7ecf\u4e0a\u4f20\u5230\u4e86github\u4e0a\u9762&#xff0c;fengyue05\/Linux-: \u672c\u4ed3\u5e93\u91cc\u9762\u4f1a\u6709\u5173\u4e8e\u300aLinux\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u7f16\u7a0b\u300b\u7684\u4e00\u4e9b\u4e3b\u8981\u4ee3\u7801\u5b9e\u73b0<br \/>\n\u4ee3\u7801<br \/>\n\u5728\u5f00\u59cb\u771f\u6b63\u4ee3\u7801\u7684\u5b9e\u73b0\u524d\u9762&#xff0c;\u6211\u4eec\u9700\u8981\u51c6\u5907\u4e00\u4e9b\u53d8\u91cf&amp;#xff0c<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,58,43,78,396],"topic":[],"class_list":["post-96601","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-linux","tag-43","tag-78","tag-396"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5171\u4eab\u5185\u5b58\u7684\u7f51\u7edc\u804a\u5929\u5ba4 - \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\/96601.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5171\u4eab\u5185\u5b58\u7684\u7f51\u7edc\u804a\u5929\u5ba4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5f15\u8a00 \u672c\u7bc7\u53c2\u8003\u4e66\u76ee\u300aLinux\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u7f16\u7a0b\u300b&#xff0c;\u8fd9\u662f\u6211\u7b2c\u4e09\u6b21\u5b9e\u73b0\u7f51\u7edc\u804a\u5929\u5ba4&#xff0c;\u8fd9\u4e00\u6b21\u662f\u5728\u5185\u5b58\u7684\u65b9\u9762\u8fdb\u884c\u4e86\u6781\u5927\u7684\u6539\u8fdb&#xff0c;\u5e76\u4e14\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f7f\u7528c11\u6765\u5b9e\u73b0\u7684&#xff0c;\u5c06\u4e66\u672c\u91cc\u9762\u7684c\u8bed\u8a00\u91cd\u5199\u4e86\u4e00\u904d\u3002 \u4ee3\u7801\u5df2\u7ecf\u4e0a\u4f20\u5230\u4e86github\u4e0a\u9762&#xff0c;fengyue05\/Linux-: \u672c\u4ed3\u5e93\u91cc\u9762\u4f1a\u6709\u5173\u4e8e\u300aLinux\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u7f16\u7a0b\u300b\u7684\u4e00\u4e9b\u4e3b\u8981\u4ee3\u7801\u5b9e\u73b0 \u4ee3\u7801 \u5728\u5f00\u59cb\u771f\u6b63\u4ee3\u7801\u7684\u5b9e\u73b0\u524d\u9762&#xff0c;\u6211\u4eec\u9700\u8981\u51c6\u5907\u4e00\u4e9b\u53d8\u91cf&amp;#xff0c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/96601.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-27T16:24:42+00:00\" \/>\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=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/96601.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/96601.html\",\"name\":\"\u5171\u4eab\u5185\u5b58\u7684\u7f51\u7edc\u804a\u5929\u5ba4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-27T16:24:42+00:00\",\"dateModified\":\"2026-08-27T16:24:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/96601.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/96601.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/96601.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5171\u4eab\u5185\u5b58\u7684\u7f51\u7edc\u804a\u5929\u5ba4\"}]},{\"@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":"\u5171\u4eab\u5185\u5b58\u7684\u7f51\u7edc\u804a\u5929\u5ba4 - \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\/96601.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5171\u4eab\u5185\u5b58\u7684\u7f51\u7edc\u804a\u5929\u5ba4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5f15\u8a00 \u672c\u7bc7\u53c2\u8003\u4e66\u76ee\u300aLinux\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u7f16\u7a0b\u300b&#xff0c;\u8fd9\u662f\u6211\u7b2c\u4e09\u6b21\u5b9e\u73b0\u7f51\u7edc\u804a\u5929\u5ba4&#xff0c;\u8fd9\u4e00\u6b21\u662f\u5728\u5185\u5b58\u7684\u65b9\u9762\u8fdb\u884c\u4e86\u6781\u5927\u7684\u6539\u8fdb&#xff0c;\u5e76\u4e14\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f7f\u7528c11\u6765\u5b9e\u73b0\u7684&#xff0c;\u5c06\u4e66\u672c\u91cc\u9762\u7684c\u8bed\u8a00\u91cd\u5199\u4e86\u4e00\u904d\u3002 \u4ee3\u7801\u5df2\u7ecf\u4e0a\u4f20\u5230\u4e86github\u4e0a\u9762&#xff0c;fengyue05\/Linux-: \u672c\u4ed3\u5e93\u91cc\u9762\u4f1a\u6709\u5173\u4e8e\u300aLinux\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u7f16\u7a0b\u300b\u7684\u4e00\u4e9b\u4e3b\u8981\u4ee3\u7801\u5b9e\u73b0 \u4ee3\u7801 \u5728\u5f00\u59cb\u771f\u6b63\u4ee3\u7801\u7684\u5b9e\u73b0\u524d\u9762&#xff0c;\u6211\u4eec\u9700\u8981\u51c6\u5907\u4e00\u4e9b\u53d8\u91cf&amp;#xff0c","og_url":"https:\/\/www.wsisp.com\/helps\/96601.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-27T16:24:42+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/96601.html","url":"https:\/\/www.wsisp.com\/helps\/96601.html","name":"\u5171\u4eab\u5185\u5b58\u7684\u7f51\u7edc\u804a\u5929\u5ba4 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-27T16:24:42+00:00","dateModified":"2026-08-27T16:24:42+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/96601.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/96601.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/96601.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5171\u4eab\u5185\u5b58\u7684\u7f51\u7edc\u804a\u5929\u5ba4"}]},{"@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\/96601","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=96601"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/96601\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=96601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=96601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=96601"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=96601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}