Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <string.h>
  6. #include <sys/stat.h>
  7. #include <sys/ioctl.h>
  8. int main()
  9. {
  10. int out, in, err;
  11.  
  12. char *cFifo = "/tmp/out";
  13. char *cInFifo = "/tmp/in";
  14.  
  15. mkfifo(cFifo, S_IRUSR|S_IWUSR);
  16. mkfifo(cInFifo, S_IRUSR|S_IWUSR);
  17.  
  18. out = open(cFifo, O_RDWR|O_TRUNC|O_NONBLOCK);
  19. in = open(cInFifo, O_RDWR|O_TRUNC|O_NONBLOCK);
  20.  
  21. dup2(out, STDOUT_FILENO);
  22. dup2(out, STDERR_FILENO);
  23. dup2(in, STDIN_FILENO);
  24.  
  25.  
  26. scanf("%*c");
  27.  
  28. while(1)
  29. {
  30. scanf("%*c");
  31. printf("Hellon");
  32. fflush(stdout);
  33. }
  34.  
  35. return 0;
  36. }
  37.  
  38. #include <stdio.h>
  39. #include <fcntl.h>
  40. #include <unistd.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <sys/types.h>
  44. #include <sys/socket.h>
  45. #include <sys/stat.h>
  46. #include <sys/ioctl.h>
  47. int main()
  48. {
  49.  
  50. int out, in;
  51. size_t i = 0;
  52.  
  53. char bufOut[1024];
  54. char *cFifo = "/tmp/out";
  55. char *cFifoIn = "/tmp/in";
  56.  
  57. out = open(cFifo, O_RDONLY);
  58.  
  59. in = open(cFifoIn, O_WRONLY);
  60.  
  61.  
  62. while(1)
  63. {
  64. i =0;
  65. while(!i)
  66. {
  67. i = read(out, bufOut, 1024);
  68. }
  69.  
  70. if(i)
  71. write(STDOUT_FILENO, bufOut, i);
  72.  
  73. }
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement