Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<unistd.h>
- #include<string.h>
- #include<sys/types.h>
- #include<sys/stat.h>
- #include<sys/fcntl.h>
- //FIFO W JEDNYM - RODZIC I POTOMEK
- void read_from_fifo(int descriptor)
- {
- char message[100]="";
- if(read(descriptor,message,sizeof(message))<0)
- perror("read");
- printf("Odebrana wiadomość: %s\n",message);
- }
- void write_to_fifo(int descriptor)
- {
- char *message = "Systemy Operacyjne";
- if(write(descriptor,message,strlen(message))<0)
- perror("write");
- }
- int main(void)
- {
- if(mkfifo("fifo",0600)<0)
- perror("mkfifo");
- int descriptor = open("fifo",O_RDWR);
- if(descriptor<0)
- perror("open");
- int pid = fork();
- if (pid<0)
- perror("fork");
- if (pid==0)
- write_to_fifo(descriptor);
- else
- read_from_fifo(descriptor);
- if(close(descriptor)<0)
- perror("close");
- if(unlink("fifo")<0)
- perror("unlink");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment