{"id":288604,"date":"2023-12-01T04:02:12","date_gmt":"2023-11-30T20:02:12","guid":{"rendered":"https:\/\/lrxjmw.cn\/clnhmkzdyyhk.html"},"modified":"2023-12-01T04:02:12","modified_gmt":"2023-11-30T20:02:12","slug":"clnhmkzdyyhk","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/clnhmkzdyyhk.html","title":{"rendered":"\u4eceLinux\u5185\u6838\u6a21\u5757\u4e2d\u8c03\u7528\u7528\u6237\u7a7a\u95f4\u51fd\u6570"},"content":{"rendered":"

\u6211\u89c9\u5f97\u6700\u7b80\u5355\u7684\u89e3\u51b3\u65b9\u6848\u662f\u5728\u5185\u6838\u9a71\u52a8\u7a0b\u5e8f\u4e2d\u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u8bbe\u5907,\u4f7f\u7528\u60a8\u81ea\u5df1\u7684\u865a\u62df\u6587\u4ef6\u6587\u4ef6\u64cd\u4f5c.\u4e4b\u540e\u7528\u6237\u7a7a\u95f4\u53ef\u4ee5\u6253\u5f00\u6b64\u8bbe\u5907O_RDWR.\u60a8\u5fc5\u987b\u5b9e\u73b0\u4e24\u4e2a\u4e3b\u8981\u6587\u4ef6\u64cd\u4f5c\uff1a<\/p>\n

>read\u2013\u8fd9\u662f\u5185\u6838\u5c06\u6570\u636e\u4f20\u9012\u56de\u7528\u6237\u7a7a\u95f4\u7684\u65b9\u6cd5.\u6b64\u51fd\u6570\u5728\u8c03\u7528read()\u7cfb\u7edf<\/a>\u8c03\u7528\u7684\u7528\u6237\u7a7a\u95f4\u7ebf\u7a0b\u7684\u4e0a\u4e0b\u6587\u4e2d\u8fd0\u884c,\u5728\u60a8\u7684\u60c5\u51b5\u4e0blinux\u5185\u6838\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f<\/strong>,\u5b83\u5e94\u5f53\u963b\u585e,\u76f4\u81f3\u5185\u6838\u5177\u6709\u987b\u8981\u6653\u5f97\u8f93\u51fa\u7684\u53e6\u4e00\u4e2a\u79cd\u5b50\u503c.<\/p>\n

\u5185\u6838\u7cfb\u7edf\u8c03\u7528_linux\u5185\u6838\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f_\u8c03\u7528\u5185\u6838\u6a21\u5757\u4e2d\u7684\u51fd\u6570<\/p>\n

>write\u2013\u8fd9\u662f\u7528\u6237\u7a7a\u95f4\u5c06\u6570\u636e\u4f20\u9012\u5230\u5185\u6838\u7684\u5f62\u5f0f.\u5728\u60a8\u7684\u60c5\u51b5\u4e0b,\u5185\u6838\u53ea\u4f1a\u5bf9\u539f\u672c\u7684\u8bfb\u53d6\u8fdb\u884c\u54cd\u5e94\u5e76\u5c06\u5176\u4f20\u9012\u7ed9\u786c\u4ef6.<\/p>\n

\u4e4b\u540e\u4f60\u6700\u7ec8\u5728\u7528\u6237\u7a7a\u95f4\u4e2d\u4f7f\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u5faa\u73af\uff1a<\/p>\n

\n

while (1) {\n    read(fd,buf,sizeof buf);\n    calculate_output(buf,output);\n    write(fd,output,sizeof output);\n}\n<\/code><\/pre>\n<\/p>\n

linux\u5185\u6838\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f_\u8c03\u7528\u5185\u6838\u6a21\u5757\u4e2d\u7684\u51fd\u6570_\u5185\u6838\u7cfb\u7edf\u8c03\u7528<\/p>\n

\u5185\u6838\u4e2d\u6839\u672c\u6ca1\u6709\u5faa\u73af\u2013\u4e00\u5207\u90fd\u5728\u9a71\u52a8\u4e8b\u7269\u7684\u7528\u6237\u7a7a\u95f4\u8fdb\u7a0b\u7684\u4e0a\u4e0b\u6587\u4e2d\u8fd0\u884c,\u800c\u5185\u6838\u9a71\u52a8\u7a0b\u5e8f\u53ea\u8d1f\u8d23\u5c06\u6570\u636e\u79fb\u5165\/\u79fb\u51fa\u786c\u4ef6.<\/p>\n

\u6309\u7167\u4f60\u5728\u5185\u6838\u65b9\u9762\u7684\u201c\u505a\u4e00\u4e9b\u968f\u673a\u7684\u4e1c\u897f\u201d,\u4f60\u53ef\u80fd\u4e0d\u53ef\u80fd\u5982\u6b64\u7b80\u5355.\u5047\u5982\u4f60\u771f\u7684\u987b\u8981\u5185\u6838\u5faa\u73af,\u8fd9\u4e48\u4f60\u987b\u8981\u521b\u5efa\u4e00\u4e2a\u5185\u6838\u7ebf\u7a0b\u6765\u8fd0\u884c\u8be5\u5faa\u73af,\u4e4b\u540e\u5728input_datalinux\u7cfb\u7edf\u88c5win7,input_ready,output_data\u548coutput_ready\u7684\u884c\u4e2d\u5305\u542b\u4e00\u4e9b\u53d8\u91cf,\u4ee5\u53ca\u4e00\u4e9b\u7b49\u5f85\u548c\u4f60\u987b\u8981\u7684\u4efb\u4f55\u9501\u5b9a.<\/p>\n

\u5f53\u5185\u6838\u7ebf\u7a0b\u8bfb\u53d6\u6570\u636e\u65f6,\u5c06\u6570\u636e\u88c5\u5165input_ready\u5e76\u8bbe\u7f6einput_ready\u6807\u5fd7\u5e76\u53d1\u51fa\u8f93\u5165waitqueue\u8baf\u53f7linux\u5185\u6838\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f<\/strong>,\u4e4b\u540e\u6267\u884cwait_event().\u8bfb\u53d6\u6587\u4ef6\u64cd\u4f5c\u5c06\u6267\u884cwait_event()\u5e76\u5728\u6570\u636e\u6253\u7b97\u5c31\u7eea\u65f6\u5c06\u6570\u636e\u8fd4\u56de\u7ed9\u7528\u6237\u7a7a\u95f4.\u7c7b\u4f3c\u5730puppy linux,\u5199\u6587\u4ef6\u64cd\u4f5c\u4f1a\u5c06\u4ece\u7528\u6237\u7a7a\u95f4\u83b7\u53d6\u7684\u6570\u636e\u88c5\u5165output_data\u5e76\u8bbe\u7f6eoutput_ready\u5e76\u5411\u8f93\u51fawaitqueue\u53d1\u51fa\u8baf\u53f7.<\/p>\n

\u53e6\u4e00\u79cd(\u66f4\u4e11\u6076,\u66f4\u4e0d\u4fbf\u643a)\u7684\u65b9\u5f0f\u662f\u4f7f\u7528\u50cfioperm,iopl\u6216\/dev\/port\u8fd9\u6837\u7684\u4e1c\u897f\u6765\u5b8c\u6210\u7528\u6237\u7a7a\u95f4\u4e2d\u7684\u6240\u6709\u64cd\u4f5c,\u5305\u62ec\u4f4e\u7ea7\u786c\u4ef6\u8bbf\u95ee.<\/p>\n","protected":false},"excerpt":{"rendered":"

\u8fd9\u662f\u5185\u6838\u5c06\u6570\u636e\u4f20\u9012\u56de\u7528\u6237\u7a7a\u95f4\u7684\u65b9\u5f0f.\u6b64\u51fd\u6570\u5728\u8c03\u7528read()\u7cfb\u7edf\u8c03\u7528\u7684\u7528\u6237\u7a7a\u95f4\u7ebf\u7a0b\u7684\u4e0a\u4e0b\u6587\u4e2d\u8fd0\u884c,\u5728\u60a8\u7684\u60c5\u51b5\u4e0b,\u5b83\u5e94\u8be5\u963b\u585e,\u76f4\u5230\u5185\u6838\u5177\u6709\u9700\u8981\u77e5\u9053\u8f93\u51fa\u7684\u53e6\u4e00\u4e2a\u79cd\u5b50\u503c.<\/p>\n","protected":false},"author":1,"featured_media":288605,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-288604","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\/288604","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=288604"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/288604\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/288605"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=288604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=288604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=288604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}