SHARE
TWEET

read() will read both write()s

a guest Jun 14th, 2011 52 Never
  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.  */
RAW Paste Data
Top