20å¹´ãããæ¥ã 使ã£ã¦ããªãããUNIX/Linuxã®ãã¤ãã®æ¯ãèããããåãã£ã¦ã¾ããã§ããããæçµãã«ãæ¥ã«ç¨ãã¦ç¥ãããã¨ããã®ã¯ããã§ããã¡ãã£ã¨ç°¡åãªã³ã¼ãã§å®é¨ãã¦ã¿ã¾ããã
ãªã¹ã1 test1.c
#include <stdio.h> int main(void) { int i; for(i=0;i<5;i++){ sleep(1); printf("test1(%d)\n",i); fflush(stdout); // âãããå¤§äº } return 0; }
ãªã¹ã2 test2.c
#include <stdio.h> int main(void) { char buff[1024]; printf("test2 starts.\n"); while(gets(buff)!=NULL){ printf("test2[%s]\n",buff); } return 0; }
å®è¡çµæ
$ gcc test1.c -o test1 $ gcc test2.c -o test2 $ ./test1 | ./test2 test2 starts.ããâ 0ç§å¾ test2[test1(0)]ãâ 1ç§å¾ test2[test1(1)]ãâ 2ç§å¾ test2[test1(2)]ãâ 3ç§å¾ test2[test1(3)]ãâ 4ç§å¾ test2[test1(4)]ãâ 5ç§å¾ã $ããããããããâ 5ç§ã§çµäº
ã¤ã¾ã
test1ã¨test2ã¯ãã©ã¬ã«ã«åãã¦ã¦ãtest2ã®getsãæ¨æºå ¥å(=test1ã®æ¨æºåºå)ãåæå¾ ã¡ãã¦ããã§ããã