Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Pierwszy*/
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main()
- {
- int fd;
- char * myfifo = "fifo1_2";
- mkfifo(myfifo, 0666);
- char arr1[80], arr2[80];
- while(1) {
- fd = open(myfifo, O_WRONLY);
- fgets(arr2, 80, stdin);
- write(fd, arr2, strlen(arr2)+1);
- close(fd);
- if(arr2[0] == '@'){
- return 0;
- }
- }
- return 0;
- }
- /*Drugi*/
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main() {
- int fd1;
- int fd2;
- char * myfifo = "fifo1_2";
- char * myfifo2 = "fifo2_3";
- mkfifo(myfifo, 0666);
- mkfifo(myfifo2,0666);
- char str1[80], str2[80];
- while(1) {
- fd1 = open(myfifo,O_RDONLY);
- read(fd1, str1, 80);
- int liczba = strlen(str1);
- liczba--;
- if(str1[0] != '@')
- printf("%s\n", str1);
- close(fd1);
- fd2 = open(myfifo2,O_WRONLY);
- if(str1[0] == '@'){
- liczba=0;
- sprintf(str2, "%d", liczba);
- write(fd2, str2, 80);
- close(fd2);
- return 0;
- }
- else{
- sprintf(str2, "%d", liczba);
- write(fd2, str2, 80);
- close(fd2);
- }
- close(fd2);
- }
- return 0;
- }
- /*Trzeci*/
- #include <stdio.h>
- #include <string.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main() {
- int fd2;
- char * myfifo2 = "fifo2_3";
- char str1[80], str2[80];
- while(1){
- fd2 = open(myfifo2,O_RDONLY);
- read(fd2, str1, 80);
- if(str1[0] != '0')
- printf("%s\n", str1);
- close(fd2);
- if(str1[0] == '0'){
- remove("fifo2_3");
- remove("fifo1_2");
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement