Want more features on Pastebin? Sign Up, it's FREE!
Guest

read() will read both write()s

By: a guest on Jun 14th, 2011  |  syntax: C  |  size: 0.43 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2.  
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7.  
  8. int main()
  9. {
  10.         char buf[32] = {0};
  11.  
  12.         int fd = open("pipe", O_RDONLY);
  13.  
  14.         printf("fd = %d\n", fd);
  15.  
  16.         // Some sort of CPU processing occurs...
  17.         sleep(10);
  18.  
  19.         read(fd, buf, 6);
  20.         printf("buf: %s\n", buf);
  21. }
  22.  
  23. /* Execute this, then run this Python:
  24.  * p = open('pipe', 'wb'); p.write('Hi'); p.write('There'); p.flush()
  25.  */
clone this paste RAW Paste Data