Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Napisz program, który stworzy potok, i wykorzysta go do przesy ł ania danych
- w obr ę bie jednego procesu.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <string.h>
- #define SOME_MESSAGE "Wiadomosc"
- #define BUFFER_SIZE 128
- int main(void)
- {
- int fd[2];
- char buffer[BUFFER_SIZE];
- if(pipe(fd) == -1){
- perror("pipe");
- return EXIT_FAILURE;
- }
- if(write(fd[1], SOME_MESSAGE, strlen(SOME_MESSAGE)) == -1){
- perror("write");
- return EXIT_FAILURE;
- }
- printf("Wiadomosc wyslana: %s\n", SOME_MESSAGE);
- if(close(fd[1]) == -1){
- perror("close");
- return EXIT_FAILURE;
- }
- memset(buffer, '\0', BUFFER_SIZE);
- if(read(fd[0], buffer, BUFFER_SIZE) == -1){
- perror("read");
- return EXIT_FAILURE;
- }
- printf("Odczytana wiadomosc: %s\n", buffer);
- if(close(fd[0]) == -1){
- perror("close");
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment