{"id":267708,"date":"2023-03-21T22:06:22","date_gmt":"2023-03-21T14:06:22","guid":{"rendered":"https:\/\/lrxjmw.cn\/ldxcyyzbxaqd.html"},"modified":"2023-03-21T22:06:22","modified_gmt":"2023-03-21T14:06:22","slug":"ldxcyyzbxaqd","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ldxcyyzbxaqd.html","title":{"rendered":"Linux\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\u7f16\u5199\u5b89\u5168\u7684\u5f02\u6b65\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u7684\u4e00\u4e9b\u89c4\u5219"},"content":{"rendered":"

(),\u8f6f\u4ef6\u5de5\u7a0b\u5e08,IBM\u4e2d\u56fd\u8f6f\u4ef6\u5f00\u53d1\u6280\u672f\u5b9e\u9a8c\u5ba4<\/p>\n

(),\u8f6f\u4ef6\u5de5\u7a0b\u5e08,EMC<\/p>\n

(),\u8d44\u6df1\u8f6f\u4ef6\u5de5\u7a0b\u5e08,IBM<\/p>\n

\u7b80\u4ecb\uff1a\u5173\u4e8e\u4ee3\u7801\u7684\u53ef\u91cd\u5165\u6027\uff0c\u8bbe\u8ba1\u5f00\u53d1\u4eba\u5458\u901a\u5e38\u53ea\u8003\u8651\u5230\u7ebf\u7a0b\u5b89\u5168\uff0c\u5f02\u6b65\u8baf\u53f7\u5904\u7406\u51fd\u6570\u7684\u5b89\u5168\u5374\u5e38\u5e38\u88ab\u5ffd\u89c6\u3002\u672c\u6587\u9996\u5148\u4ecb\u7ecd\u600e\u4e48\u7f16\u64b0\u5b89\u5168\u7684\u5f02\u6b65\u8baf\u53f7\u5904\u7406\u51fd\u6570\uff1b\u4e4b\u540e\u4e3e\u4f8b\u8bf4\u660e\u5728\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\u600e\u6837\u5efa\u7acb\u6a21\u578b\u8ba9\u5f02\u6b65\u8baf\u53f7\u5728\u6307\u5b9a\u7684\u7ebf\u7a0b\u4e2d\u4ee5\u540c\u6b65\u7684\u65b9\u6cd5\u5904\u7406\u3002<\/p>\n

Linux<\/a>\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\u7f16\u64b0\u5b89\u5168\u7684\u8baf\u53f7\u5904\u7406\u51fd\u6570<\/p>\n

\u5728\u5f00\u53d1\u591a\u7ebf\u7a0b\u5e94\u7528\u65f6\uff0c\u5f00\u53d1\u4eba\u5458\u901a\u5e38\u8fd8\u4f1a\u8003\u8651\u7ebf\u7a0b\u5b89\u5168\uff0c\u4f1a\u4f7f\u7528pthread_mutex\u53bb\u4fdd\u62a4\u5168\u5c40\u53d8\u91cf\u3002\u5018\u82e5\u5e94\u7528\u4e2d\u4f7f\u7528\u4e86\u8baf\u53f7\uff0c\u5e76\u4e14\u8baf\u53f7\u7684\u5f62\u6210\u4e0d\u662f\u7531\u4e8e\u7a0b\u5e8f\u8fd0\u884c\u51fa\u9519\uff0c\u800c\u662f\u7a0b\u5e8f\u903b\u8f91\u987b\u8981\uff0c\u4f8b\u5982SIGUSR1\u3001SIGRTMIN\u7b49\uff0c\u8baf\u53f7\u5728\u88ab\u5904\u7406\u540e\u5e94\u7528\u7a0b\u5e8f\u8fd8\u5c06\u6b63\u5e38\u8fd0\u884c\u3002\u5728\u7f16\u64b0\u8fd9\u7c7b\u8baf\u53f7\u5904\u7406\u51fd\u6570\u65f6\uff0c\u5e94\u7528\u5c42\u9762\u7684\u5f00\u53d1\u4eba\u5458\u5374\u5e38\u5e38\u5ffd\u89c6\u4e86\u8baf\u53f7\u5904\u7406\u51fd\u6570\u6267\u884c\u7684\u4e0a\u4e0b\u6587\u80cc\u666f\uff0c\u6ca1\u6709\u8003\u8651\u7f16\u64b0\u5b89\u5168\u7684\u8baf\u53f7\u5904\u7406\u51fd\u6570\u7684\u4e00\u4e9b\u89c4\u5219\u3002\u672c\u6587\u9996\u5148\u4ecb\u7ecd\u7f16\u64b0\u8baf\u53f7\u5904\u7406\u51fd\u6570\u65f6\u987b\u8981\u8003\u8651\u7684\u4e00\u4e9b\u89c4\u5219\uff1b\u4e4b\u540e\u4e3e\u4f8b\u8bf4\u660e\u5728\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\u600e\u6837\u5efa\u7acb\u6a21\u578b\u8ba9\u7531\u4e8e\u7a0b\u5e8f\u903b\u8f91\u987b\u8981\u800c\u5f62\u6210\u7684\u5f02\u6b65\u8baf\u53f7\u5728\u6307\u5b9a\u7684\u7ebf\u7a0b\u4e2d\u4ee5\u540c\u6b65\u7684\u65b9\u6cd5\u5904\u7406\u3002<\/p>\n

\u7ebf\u7a0b\u548c\u8baf\u53f7<\/p>\n

Linux\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\uff0c\u6bcf\u4f4d\u7ebf\u7a0b\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528pthread_sigmask()\u8bbe\u7f6e\u672c\u7ebf\u7a0b\u7684\u8baf\u53f7\u7f51\u6bb5\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u88ab\u963b\u585e\u7684\u8baf\u53f7\u5c06\u4e0d\u80fd\u4e2d\u65ad\u6b64\u7ebf\u7a0b\u7684\u6267\u884c\uff0c\u9664\u975e\u6b64\u8baf\u53f7\u7684\u5f62\u6210\u662f\u7531\u4e8e\u7a0b\u5e8f\u8fd0\u884c\u51fa\u9519\u5982SIGSEGV\uff1b\u53e6\u5916\u4e0d\u80fd\u88ab\u5ffd\u89c6\u5904\u7406\u7684\u8baf\u53f7SIGKILL\u548cSIGSTOP\u4e5f\u96be\u4ee5\u88ab\u963b\u585e\u3002<\/p>\n

\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u8c03\u7528pthread_create()\u521b\u5efa\u65b0\u7684\u7ebf\u7a0b\u65f6\uff0c\u6b64\u7ebf\u7a0b\u7684\u8baf\u53f7\u7f51\u6bb5\u4f1a\u88ab\u65b0\u521b\u5efa\u7684\u7ebf\u7a0b\u627f\u7ee7\u3002<\/p>\n

POSIX.1\u6807\u51c6\u5b9a\u4e49\u4e86\u4e00\u7cfb\u5217\u7ebf\u7a0b\u51fd\u6570\u7684\u63d2\u53e3\uff0c\u5373POSIXthreads(Pthreads)\u3002LinuxC\u5e93\u63d0\u4f9b\u4e86\u4e24\u79cd\u5173\u4e8e\u7ebf\u7a0b\u7684\u5b9e\u73b0\uff1aLinuxThreads\u548cNPTL(NativePOSIXThreadsLibrary)\u3002LinuxThreads\u65e9\u5df2\u8fc7\u65f6\uff0c\u4e00\u4e9b\u51fd\u6570\u7684\u5b9e\u73b0\u4e0d\u9075\u5b88POSIX.1\u89c4\u8303\u3002NPTL\u4f9d\u8d56Linux2.6\u5185\u6838\uff0c\u6108\u53d1\u9075\u5b88POSIX..1\u89c4\u8303\uff0c\u4f46\u4e5f\u4e0d\u662f\u5b8c\u5168\u9075\u7167\u3002<\/p>\n

socket\u8fde\u63a5\u6c60\u548c\u7ebf\u7a0b\u6c60_linux socket \u7f16\u7a0b\u5b9e\u4f8b_linux socket \u591a\u7ebf\u7a0b<\/p>\n

\u57fa\u4e8eNPTL\u7684\u7ebf\u7a0b\u5e93linux\u600e\u4e48\u8bfb\uff0c\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\u7684\u6bcf\u4f4d\u7ebf\u7a0b\u6709\u81ea\u5df1\u72ec\u5230\u7684\u7ebf\u7a0bID\uff0c\u5e76\u5171\u4eab\u540c\u4e00\u4e2a\u8fdb\u7a0bID\u3002\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528kill(getpid(),signo)\u5c06\u8baf\u53f7\u53d1\u9001\u5230\u8fdb\u7a0b\uff0c\u5047\u5982\u8fdb\u7a0b\u4e2d\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u7ebf\u7a0b\u6ca1\u6709\u59a8\u788d\u6b64\u8baf\u53f7\uff0c\u5219\u4f1a\u88ab\u4e2d\u65ad\uff0c\u7ebf\u53f7\u5904\u7406\u51fd\u6570\u4f1a\u5728\u6b64\u7ebf\u7a0b\u7684\u4e0a\u4e0b\u6587\u80cc\u666f\u4e2d\u6267\u884c\u3002\u5e94\u7528\u7a0b\u5e8f\u4e5f\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528pthread_kill(pthread_tthread,intsig)\u5c06\u8baf\u53f7\u53d1\u9001\u7ed9\u6307\u5b9a\u7684\u7ebf\u7a0b\uff0c\u5219\u7ebf\u53f7\u5904\u7406\u51fd\u6570\u4f1a\u5728\u6b64\u6307\u5b9a\u7ebf\u7a0b\u7684\u4e0a\u4e0b\u6587\u80cc\u666f\u4e2d\u6267\u884c\u3002<\/p>\n

\u57fa\u4e8eLinuxThreads\u7684\u7ebf\u7a0b\u5e93\uff0c\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\u7684\u6bcf\u4f4d\u7ebf\u7a0b\u62e5\u6709\u81ea\u5df1\u72ec\u5230\u7684\u8fdb\u7a0bID\uff0cgetpid\uff08\uff09\u5728\u4e0d\u540c\u7684\u7ebf\u7a0b\u4e2d\u8c03\u7528\u4f1a\u8fd4\u56de\u4e0d\u540c\u7684\u503clinux socket \u591a\u7ebf\u7a0b<\/strong>\uff0c\u6240\u4ee5\u672a\u80fd\u901a\u8fc7\u8c03\u7528kill(getpid(),signo)\u5c06\u8baf\u53f7\u53d1\u9001\u5230\u6574\u4e2a\u8fdb\u7a0b\u3002<\/p>\n

\u4e0b\u6587\u4ecb\u7ecd\u7684\u5728\u6307\u5b9a\u7684\u7ebf\u7a0b\u4e2d\u4ee5\u540c\u6b65\u7684\u65b9\u6cd5\u5904\u7406\u5f02\u6b65\u8baf\u53f7\u662f\u57fa\u4e8e\u4f7f\u7528\u4e86NPTL\u7684LinuxC\u5e93\u3002\u8bf7\u53c2\u8003\u201cLinux\u7ebf\u7a0b\u6a21\u578b\u7684\u6bd4\u8f83\uff1aLinuxThreads\u548cNPTL\u201d\u548c\u201cpthreads(7)-Linuxmanpage\u201d\u8fdb\u4e00\u6b65\u4e86\u89e3Linux\u7684\u7ebf\u7a0b\u6a21\u578b\uff0c\u4ee5\u53ca\u4e0d\u540c\u7248\u672c\u7684LinuxC\u5e93\u5bf9NPTL\u7684\u652f\u6301\u3002<\/p>\n

\u7f16\u64b0\u5b89\u5168\u7684\u5f02\u6b65\u8baf\u53f7\u5904\u7406\u51fd\u6570<\/p>\n

\u8baf\u53f7\u7684\u5f62\u6210\u53ef\u4ee5\u662f\uff1a<\/p>\n

\u7531\u4e8e\u8baf\u53f7\u662f\u5f02\u6b65\u98ce\u6ce2\uff0c\u5373\u8baf\u53f7\u5904\u7406\u51fd\u6570\u6267\u884c\u7684\u4e0a\u4e0b\u6587\u80cc\u666f\u662f\u4e0d\u786e\u5b9a\u7684\uff0c\u4f8b\u5982\u4e00\u4e2a\u7ebf\u7a0b\u5728\u8c03\u7528\u67d0\u4e2a\u5e93\u51fd\u6570\u65f6\u53ef\u80fd\u4f1a\u88ab\u8baf\u53f7\u4e2d\u65ad\uff0c\u5e93\u51fd\u6570\u63d0\u65e9\u51fa\u9519\u8fd4\u56de\uff0c\u8f6c\u800c\u53bb\u6267\u884c\u8baf\u53f7\u5904\u7406\u51fd\u6570\u3002\u5bf9\u4e8e\u4e0a\u8ff0\u7b2c\u4e09\u79cd\u8baf\u53f7\u7684\u5f62\u6210linux\u5165\u95e8\uff0c\u8baf\u53f7\u5728\u5f62\u6210\u3001\u5904\u7406\u540e\uff0c\u5e94\u7528\u7a0b\u5e8f\u4e0d\u4f1a\u4e2d\u6b62\uff0c\u8fd8\u662f\u4f1a\u7ee7\u7eed\u6b63\u5e38\u8fd0\u884clinux socket \u591a\u7ebf\u7a0b<\/strong>\uff0c\u5728\u7f16\u64b0\u8fd9\u79cd\u8baf\u53f7\u5904\u7406\u51fd\u6570\u65f6\u5c24\u5176\u987b\u8981\u7559\u795e\uff0c\u4ee5\u514d\u7834\u574f\u5e94\u7528\u7a0b\u5e8f\u7684\u6b63\u5e38\u8fd0\u884c\u3002\u5173\u4e8e\u7f16\u64b0\u5b89\u5168\u7684\u8baf\u53f7\u5904\u7406\u51fd\u6570\u4e3b\u8981\u6709\u4ee5\u4e0b\u4e00\u4e9b\u89c4\u5219\uff1a<\/p>\n

\u4ece\u6574\u4e2aLinux\u5e94\u7528\u7684\u89d2\u5ea6\u51fa\u53d1\uff0c\u7531\u4e8e\u5e94\u7528\u4e2d\u4f7f\u7528\u4e86\u5f02\u6b65\u8baf\u53f7\uff0c\u7a0b\u5e8f\u4e2d\u4e00\u4e9b\u5e93\u51fd\u6570\u5728\u8c03\u7528\u65f6\u53ef\u80fd\u88ab\u5f02\u6b65\u8baf\u53f7\u4e2d\u65ad\uff0c\u6b64\u65f6\u5fc5\u987b\u4f9d\u7167errno\u7684\u503c\u8003\u8651\u8fd9\u79cd\u5e93\u51fd\u6570\u8c03\u7528\u88ab\u8baf\u53f7\u4e2d\u65ad\u540e\u7684\u51fa\u9519\u6062\u590d\u5904\u7406\uff0c\u4f8b\u5982socket\u7f16\u7a0b\u4e2d\u7684\u8bfb\u64cd\u4f5c\uff1a<\/p>\n

rlen=recv(sock_fd,buf,len,MSG_WAITALL);<\/p>\n

linux socket \u591a\u7ebf\u7a0b_linux socket \u7f16\u7a0b\u5b9e\u4f8b_socket\u8fde\u63a5\u6c60\u548c\u7ebf\u7a0b\u6c60<\/p>\n

if((rlen==-1)&&(errno==EINTR)){<\/p>\n

\/\/thiskindoferrorisrecoverable,wecansettheoffsetchange<\/p>\n

\/\/\u2018rlen\u2019as0andcontinuetorecv<\/p>\n

}<\/p>\n

\u5728\u6307\u5b9a\u7684\u7ebf\u7a0b\u4e2d\u4ee5\u540c\u6b65\u7684\u65b9\u6cd5\u5904\u7406\u5f02\u6b65\u8baf\u53f7<\/p>\n

\u5982\u4e0a\u6587\u6240\u8ff0\uff0c\u9664\u4e86\u7f16\u64b0\u5b89\u5168\u7684\u5f02\u6b65\u8baf\u53f7\u5904\u7406\u51fd\u6570\u672c\u8eab\u6709\u597d\u591a\u7684\u89c4\u5219\u7981\u9522\uff1b\u5e94\u7528\u4e2d\u5176\u5b83\u5730\u65b9\u5728\u8c03\u7528\u53ef\u88ab\u8baf\u53f7\u4e2d\u65ad\u7684\u5e93\u51fd\u6570\u65f6\u8fd8\u9700\u8003\u8651\u88ab\u4e2d\u65ad\u540e\u7684\u51fa\u9519\u6062\u590d\u5904\u7406\u3002\u8fd9\u8ba9\u7a0b\u5e8f\u7684\u7f16\u64b0\u663e\u5f97\u590d\u6742\uff0c\u8f9b\u8fd0\u7684\u662f\uff0cPOSIX.1\u89c4\u8303\u5b9a\u4e49\u4e86sigwait()\u3001sigwaitinfo()\u548cpthread_sigmask()\u7b49\u63d2\u53e3\uff0c\u53ef\u4ee5\u5b9e\u73b0\uff1a<\/p>\n

\u8fd9\u4e9b\u5728\u6307\u5b9a\u7684\u7ebf\u7a0b\u4e2d\u4ee5\u540c\u6b65\u65b9\u6cd5\u5904\u7406\u8baf\u53f7\u7684\u6a21\u578b\u53ef\u4ee5\u9632\u6b62\u7531\u4e8e\u5904\u7406\u5f02\u6b65\u8baf\u53f7\u800c\u7ed9\u7a0b\u5e8f\u8fd0\u884c\u5e26\u6765\u7684\u4e0d\u786e\u5b9a\u6027\u548c\u6f5c\u5728\u5371\u9669\u3002<\/p>\n

sigwait<\/p>\n

sigwait()\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b49\u5f85\u8baf\u53f7\u7684\u5230\u6765\uff0c\u4ee5\u4e32\u884c\u7684\u5f62\u5f0f\u4ece\u8baf\u53f7\u961f\u5217\u4e2d\u53d6\u51fa\u8baf\u53f7\u8fdb\u884c\u5904\u7406\u7684\u673a\u5236\u3002sigwait\uff08\uff09\u53ea\u7b49\u5f85\u51fd\u6570\u53c2\u6570\u624b\u6307\u5b9a\u7684\u8baf\u53f7\u96c6\uff0c\u5373\u82e5\u679c\u65b0\u5f62\u6210\u7684\u8baf\u53f7\u4e0d\u5728\u6307\u5b9a\u7684\u8baf\u53f7\u96c6\u5185\uff0c\u5219sigwait\uff08\uff09\u7ee7\u7eed\u7b49\u5f85\u3002\u5bf9\u4e8e\u4e00\u4e2a\u7a33\u5b9a\u53ef\u9760\u7684\u7a0b\u5e8f\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u6709\u4e00\u4e9b\u7591\u60d1\uff1a<\/p>\n

\u7b14\u8005\u5199\u4e86\u4e00\u5c0f\u6bb5\u6d4b\u8bd5\u7a0b\u5e8f\u6765\u6d4b\u8bd5sigwait\u5728\u8baf\u53f7\u5904\u7406\u65f6\u7684\u4e00\u4e9b\u89c4\u5219\u3002<\/p>\n

\u6e05\u53551.sigwait_test.c<\/p>\n","protected":false},"excerpt":{"rendered":"

\u7b80\u4ecb\uff1a\u5173\u4e8e\u4ee3\u7801\u7684\u53ef\u91cd\u5165\u6027\uff0c\u8bbe\u8ba1\u5f00\u53d1\u4eba\u5458\u4e00\u822c\u53ea\u8003\u8651\u5230\u7ebf\u7a0b\u5b89\u5168\uff0c\u5f02\u6b65\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u7684\u5b89\u5168\u5374\u5f80\u5f80\u88ab\u5ffd\u7565\u3002\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\u7f16\u5199\u5b89\u5168\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u591a\u7ebf\u7a0b\u5e94\u7528\u4e2d\uff0c\u6bcf\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528pthread_sigmask()\u8bbe\u7f6e\u672c\u7ebf\u7a0b\u7684\u4fe1\u53f7\u63a9\u7801\u3002sig)\u5c06\u4fe1\u53f7\u53d1\u9001\u7ed9\u6307\u5b9a\u7684\u7ebf\u7a0b\uff0c\u5219\u7ebf\u53f7\u5904\u7406\u51fd\u6570\u4f1a\u5728\u6b64\u6307\u5b9a\u7ebf\u7a0b\u7684\u4e0a\u4e0b\u6587\u80cc\u666f\u4e2d\u6267\u884c\u3002\u5728\u6307\u5b9a\u7684\u7ebf\u7a0b\u4e2d\u4ee5\u540c\u6b65\u7684\u65b9\u5f0f\u5904\u7406\u5f02\u6b65\u4fe1\u53f7<\/p>\n","protected":false},"author":1,"featured_media":267709,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-267708","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/267708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=267708"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/267708\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/267709"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=267708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=267708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=267708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}