Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************************PIPE1*******************************************************/
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main() {
- int output;
- char *fifo1 = "kacper1_2";
- mkfifo(fifo1, 0777);
- char arr[80];
- while(1) {
- output = open(fifo1, O_WRONLY);
- fgets(arr, 80, stdin);
- write(output, arr, strlen(arr)+1);
- close(output);
- if(arr[0] == '@') {
- return 0;
- }
- }
- }
- /***********************************************PIPE2*****************************************************************/
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main() {
- int input;
- int output;
- char *fifo1 = "kacper1_2";
- char *fifo2 = "kacper2_3";
- mkfifo(fifo1, 0777);
- mkfifo(fifo2, 0777);
- char arr1[80], arr2[80];
- while(1) {
- input = open(fifo1,O_RDONLY);
- read(input, arr1, 80);
- int size = strlen(arr1) -1;
- if(arr1[0] != '@')
- printf("%s\n", arr1);
- close(input);
- output = open(fifo2,O_WRONLY);
- if(arr1[0] == '@'){
- size=0;
- sprintf(arr2, "%d", size);
- write(output, arr2, 80);
- close(output);
- break;
- } else {
- sprintf(arr2, "%d", size);
- write(output, arr2, 80);
- close(output);
- }
- }
- return 0;
- }
- /*************************************************PIPE3********************************************************/
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main() {
- int input;
- char *fifo2 = "kacper2_3";
- char arr[80];
- while(1){
- input = open(fifo2,O_RDONLY);
- read(input, arr, 80);
- if(arr[0] != '0')
- printf("%s\n", arr);
- close(input);
- if(arr[0] == '0'){
- remove("kacper2_3");
- remove("kacper1_2");
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement