{"id":2383,"date":"2021-11-17T20:52:29","date_gmt":"2021-11-17T11:52:29","guid":{"rendered":"https:\/\/sirius10.net\/blog\/wordpress\/?p=2383"},"modified":"2021-11-17T21:31:26","modified_gmt":"2021-11-17T12:31:26","slug":"post-2383","status":"publish","type":"post","link":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/2021\/11\/17\/2383\/","title":{"rendered":"\u6a19\u6e96\u51fa\u529b\u3068\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u8aad\u3080"},"content":{"rendered":"\n<p>\u3000\u30d7\u30ed\u30b0\u30e9\u30e0\u5185\u3067\u5916\u90e8\u30b3\u30de\u30f3\u30c9\u3092\u52d5\u304b\u3057\u3001\u305d\u306e\u7d50\u679c\u3092\u53d7\u3051\u53d6\u308d\u3046\u3068\u601d\u3044\u307e\u3057\u305f\u3002\u3053\u306e\u3088\u3046\u306a\u6642\u306f\u3001popen() \u3092\u4f7f\u3063\u3066\u3001\u5916\u90e8\u30b3\u30de\u30f3\u30c9\u306e\u6a19\u6e96\u51fa\u529b\u3092\u8aad\u3080\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u3068\u3053\u308d\u304c\u3001\u4eca\u56de\u52d5\u304b\u305d\u3046\u3068\u3057\u305f\u30b3\u30de\u30f3\u30c9\u306f\u7d50\u679c\u3092\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u306b\u51fa\u3057\u3066\u3044\u3066\u3001popen() \u3067\u306f\u8aad\u3080\u3053\u3068\u304c\u51fa\u6765\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000\u81ea\u524d\u3067\u51e6\u7406\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30d1\u30a4\u30d7\u3092\u4f5c\u6210\u3057\u3066\u3001fork() \u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted file\">    pid_t pid;                \/\/ fork() \u304c\u8fd4\u3059 pid\n    int pipes[2];             \/\/ \u30d1\u30a4\u30d7\n    char *buf[1024];\n    File *fp;\n\n    if( pipe(pipes) == -1 ) return 0; \/\/ \u30d1\u30a4\u30d7\u4f5c\u6210\u5931\u6557\n\n    pid = fork();\n    if( pid == -1 ) return 0; \/\/ fork \u5931\u6557\n\n    if( pid == 0 ) {          \/\/ \u5b50\u30d7\u30ed\u30bb\u30b9\n        close(pipes[0]);      \/\/ \u5b50\u30d7\u30ed\u30bb\u30b9\u306f\u8aad\u3080\u5fc5\u8981\u304c\u306a\u3044\u306e\u3067\u30d1\u30a4\u30d7\u3092\u9589\u3058\u308b\n        close(1);             \/\/ \u5b50\u30d7\u30ed\u30bb\u30b9\u306e\u6a19\u6e96\u51fa\u529b\u3092\u9589\u3058\u3066\u3001\n        dup(pipes[1]);        \/\/ \u30d1\u30a4\u30d7\u3092\u6a19\u6e96\u51fa\u529b\u306b\u8907\u88fd\u3059\u308b\u3002\n        close(2);             \/\/ \u5b50\u30d7\u30ed\u30bb\u30b9\u306e\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u3082\u9589\u3058\u3066\u3001\n        dup(pipes[1]);        \/\/ \u30d1\u30a4\u30d7\u3092\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u306b\u8907\u88fd\u3059\u308b\u3002\n        close(pipes[1]);      \/\/ \u30d1\u30a4\u30d7\u3092\u9589\u3058\u3066\u304a\u304f\u3002\n\n        \/\/ \u30b3\u30de\u30f3\u30c9\u306e\u5b9f\u884c(execl \u7b49)\n    }\n    close(pipes[1]);          \/\/ \u89aa\u30d7\u30ed\u30bb\u30b9\u3067\u306f\u51fa\u529b\u3057\u306a\u3044\u306e\u3067\u9589\u3058\u308b\n    if( (fp = fdopen(pipes[0], \"r\")) != NULL ) { \/\/ \u8aad\u307f\u8fbc\u307f\u30d1\u30a4\u30d7\n        while( fgets(buf, 1023, fp) != NULL ) {\n            \/\/ \u8aad\u307f\u8fbc\u307f\u51e6\u7406\n        }\n        fclose(fp);\n    }<\/pre>\n\n\n\n<p>\u3000dup() \u95a2\u6570\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u3092\u8907\u88fd\u3057\u307e\u3059\u304c\u3001\u7a7a\u3044\u3066\u3044\u308b\u4e00\u756a\u82e5\u3044\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u306b\u8907\u88fd\u3057\u307e\u3059\u3002\u3064\u307e\u308a\u3001close(1) \u3067\u6a19\u6e96\u51fa\u529b\u3092\u9589\u3058\u308b\u306e\u3067\u3001\u305d\u306e\u76f4\u5f8c\u306e dup(pipes[0]) \u306f\u6a19\u6e96\u51fa\u529b\u306b\u8907\u88fd\u3055\u308c\u307e\u3059\u3002\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u3082\u540c\u69d8\u3067\u3059\u3002\u6a19\u6e96\u51fa\u529b\u3082\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u3082\u307e\u3068\u3081\u3066\u8aad\u3080\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u3053\u308c\u3067\u3001\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u306b\u7d50\u679c\u3092\u51fa\u529b\u3059\u308b\u30b3\u30de\u30f3\u30c9\u306e\u7d50\u679c\u3092\u30d7\u30ed\u30b0\u30e9\u30e0\u5185\u3067\u8aad\u3080\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u30d7\u30ed\u30b0\u30e9\u30e0\u5185\u3067\u5916\u90e8\u30b3\u30de\u30f3\u30c9\u3092\u52d5\u304b\u3057\u3001\u305d\u306e\u7d50\u679c\u3092\u53d7\u3051\u53d6\u308d\u3046\u3068\u601d\u3044\u307e\u3057\u305f\u3002\u3053\u306e\u3088\u3046\u306a\u6642\u306f\u3001popen() \u3092\u4f7f\u3063\u3066\u3001\u5916\u90e8\u30b3\u30de\u30f3\u30c9\u306e\u6a19\u6e96\u51fa\u529b\u3092\u8aad\u3080\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002 \u3000\u3068\u3053\u308d\u304c\u3001\u4eca\u56de\u52d5\u304b\u305d\u3046\u3068\u3057\u305f\u30b3\u30de\u30f3\u30c9\u306f\u7d50\u679c\u3092\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-2383","post","type-post","status-publish","format-standard","hentry","category-programing"],"_links":{"self":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=2383"}],"version-history":[{"count":3,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2383\/revisions"}],"predecessor-version":[{"id":2386,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2383\/revisions\/2386"}],"wp:attachment":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=2383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=2383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=2383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}