Guest User

Untitled

a guest
Jun 21st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #define PIPE_ID "aa"
  2. int Pipe_FD = 0;
  3.  
  4. int main (int argc, char **argv)
  5. {
  6. printf("Waiting on openn");
  7. while(Pipe_FD = open(PIPE_ID, O_RDONLY) < 0) {
  8. }
  9.  
  10. printf("waiting on readn");
  11. char ch;
  12. while(read(Pipe_FD, &ch, 1) > 0) {
  13. printf("Read: %ct", ch);
  14. fflush(stdout);
  15. }
  16. close(Pipe_FD);
  17. return 1;
  18. }
  19.  
  20. #define PIPE_ID "aa"
  21. int Pipe_FD = 0;
  22.  
  23. // This function configures named pipe
  24. void configure_pipe() {
  25. if(mkfifo(PIPE_ID, 0666) != 0) {
  26. perror("mkfifo errorn");
  27. }
  28. }
  29.  
  30. void writeInPipe() {
  31. Pipe_FD = open(PIPE_ID, O_WRONLY);
  32. int num;
  33. if((num = write(Pipe_FD, "Hi", sizeof("Hi"))) < 0) {
  34. perror("Error in writingt");
  35. exit(-1);
  36. } else
  37. printf("Wrote bytes: %dn", num);
  38. close(Pipe_FD);
  39. }
  40.  
  41. int main() {
  42. configure_pipe();
  43.  
  44. writeInPipe();
  45. sleep(1);
  46. unlink(PIPE_ID);
  47. }
  48.  
  49. Wrote bytes: 3
  50.  
  51. Waiting on open
  52. waiting on read
  53.  
  54. Read:
  55.  
  56. Read:
  57.  
  58. Read:
  59. a
  60. Read: a Read:
  61. ab
  62. Read: a Read: b Read:
Add Comment
Please, Sign In to add comment