fork download
  1. // C program to illustrate
  2. // pipe system call in C
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #define MSGSIZE 16
  6. char* msg1 = "hello, world #1";
  7. char* msg2 = "hello, world #2";
  8. char* msg3 = "hello, world #3";
  9.  
  10. int main()
  11. {
  12. char inbuf[MSGSIZE];
  13. int p[2], i;
  14.  
  15. if (pipe(p) < 0)
  16. exit(1);
  17.  
  18. /* continued */
  19. /* write pipe */
  20.  
  21. write(p[1], msg1, MSGSIZE);
  22. write(p[1], msg2, MSGSIZE);
  23. write(p[1], msg3, MSGSIZE);
  24.  
  25. for (i = 0; i < 3; i++) {
  26. /* read pipe */
  27. read(p[0], inbuf, MSGSIZE);
  28. printf("% s\n", inbuf);
  29. }
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
hello, world #1
hello, world #2
hello, world #3