SHARE
TWEET

zad2pipe

LazySenpai Dec 15th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /************************************************PIPE1*******************************************************/
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <fcntl.h>
  5. #include <sys/stat.h>
  6. #include <sys/types.h>
  7. #include <unistd.h>
  8.  
  9. int main() {
  10.     int output;
  11.     char *fifo1 = "kacper1_2";
  12.    
  13.     mkfifo(fifo1, 0777);
  14.  
  15.     char arr[80];
  16.  
  17.     while(1) {
  18.         output = open(fifo1, O_WRONLY);
  19.         fgets(arr, 80, stdin);
  20.         write(output, arr, strlen(arr)+1);
  21.         close(output);
  22.         if(arr[0] == '@') {
  23.             return 0;
  24.         }
  25.     }
  26. }
  27. /***********************************************PIPE2*****************************************************************/
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <fcntl.h>
  31. #include <sys/stat.h>
  32. #include <sys/types.h>
  33. #include <unistd.h>
  34.  
  35. int main() {
  36.     int input;
  37.     int output;
  38.  
  39.     char *fifo1 = "kacper1_2";
  40.     char *fifo2 = "kacper2_3";
  41.     mkfifo(fifo1, 0777);
  42.     mkfifo(fifo2, 0777);
  43.  
  44.     char arr1[80], arr2[80];
  45.     while(1) {
  46.         input = open(fifo1,O_RDONLY);
  47.         read(input, arr1, 80);
  48.         int size = strlen(arr1) -1;
  49.         if(arr1[0] != '@')
  50.             printf("%s\n", arr1);
  51.         close(input);
  52.  
  53.         output = open(fifo2,O_WRONLY);
  54.  
  55.         if(arr1[0] == '@'){
  56.             size=0;
  57.             sprintf(arr2, "%d", size);
  58.             write(output, arr2, 80);
  59.             close(output);
  60.             break;
  61.         } else {
  62.             sprintf(arr2, "%d", size);
  63.             write(output, arr2, 80);
  64.             close(output);
  65.         }
  66.     }
  67.     return 0;
  68. }
  69. /*************************************************PIPE3********************************************************/
  70. #include <stdio.h>
  71. #include <string.h>
  72. #include <fcntl.h>
  73. #include <sys/stat.h>
  74. #include <sys/types.h>
  75. #include <unistd.h>
  76.  
  77. int main() {
  78.     int input;
  79.  
  80.     char *fifo2 = "kacper2_3";
  81.  
  82.     char arr[80];
  83.     while(1){
  84.         input = open(fifo2,O_RDONLY);
  85.         read(input, arr, 80);
  86.  
  87.         if(arr[0] != '0')
  88.             printf("%s\n", arr);
  89.  
  90.         close(input);
  91.         if(arr[0] == '0'){
  92.             remove("kacper2_3");
  93.             remove("kacper1_2");
  94.             break;
  95.         }
  96.     }
  97.     return 0;
  98. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top