Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<unistd.h>
- #include<stdio.h>
- #include<sys/stat.h>
- #include<fcntl.h>
- #include <sys/types.h>
- #include <strings.h>
- int main (void)
- {
- int pid1, pid2, nbytes, descriptor, flag;
- int d_pipe[2];
- char buffer[80];
- char readbuffer[80];
- pipe(d_pipe);
- pid1 = fork();
- if(pid1 == -1)
- {
- printf("ERROR 404");
- exit(EXIT_FAILURE);
- }
- if(pid1 == 0)
- {
- close(d_pipe[0]);
- if ((descriptor = open ("algunombre.text", O_CREAT, 0777)) < 0)
- {
- printf("ERROR OPEN");
- exit(EXIT_FAILURE);
- }
- flag = read(descriptor, &buffer, 5);
- write(d_pipe[1], buffer, 6);
- close(d_pipe[1]);
- exit(EXIT_SUCCESS);
- }
- else
- {
- pid2 = fork();
- if(pid2 == -1)
- {
- printf("EEROROOROARFSADF");
- exit(EXIT_FAILURE);
- }
- if(pid2 == 0)
- {
- close(d_pipe[1]);
- nbytes = read(d_pipe[0], readbuffer, sizeof(readbuffer));
- printf("Mira recibiste algo: %s\n", readbuffer);
- exit(EXIT_SUCCESS);
- }
- else
- {
- waitpid(pid1);
- waitpid(pid2);
- exit(EXIT_SUCCESS);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement